GithubHelp home page GithubHelp logo

Comments (3)

Vasile-Peste avatar Vasile-Peste commented on August 18, 2024 1

So to have a brief summary, we have to:
1. Create a way to elapse a backtest using a file stream as data source;
2. Avoid using .filter/forEach and any functional
3. See what we can do to improve the MidaDecimal processing times (starting from the isZero proposal)
4. Process and emit ticks and periods in parallel

A plus but not required for this stage is generating a report of the backtest, can be calculated manually for now
I have created a PR where we will do our best to address the points above #113

from mida.

Vasile-Peste avatar Vasile-Peste commented on August 18, 2024

Hello,
This for me is wrong because in my strategy I want to do things when period is closed and other things when a new tick comes. The solution I propose is to use the property MidaPeriod#ticks to simulate better the market.

You are absolutely right here. The fact is that the engine was built to be initially used either with ticks or periods, everyone agrees that it should work with both simultaneously.

Now, this is going to be a long post about how we can improve the backtesting engine so we are going discuss further improvements here. I will personally come back here with some proposed solutions taking into consideration also your solutions, thank you!

from mida.

fgnm avatar fgnm commented on August 18, 2024

Thank you for all the support, I'll keep update this issue with more improvements for the backtest engine, reporting the one already discussed on discord to keep track of it :)

Performances

There are some performances issues that heavily impact on backtest engine performances. With huge datasets it's not practical to perform a backtest in a reasonable time. Two major bottlenecks I've found are the MidaPlaygroundEngine and in MidaDecimal.

For the first one, the abuse of filter method for the array slows down a lot. Especially for the getOpenPositions function. The proposed fix here is to replace with simple for-loop. i.e.:

    public async getOpenPositions (): Promise<MidaPosition[]> {
        let openPositions: MidaPosition[] = [];

        for (let [id, position] of this.#positions) {
            if (!position.volume.isZero()) openPositions.push(position);
        }

        return openPositions;
    }

The MidaDecimal has a huge impact on backtest performances, in particular the decimal function, widely used in the backtest engine, always allocate new objects (increasing GC time) and the getParts function requires a lot of time to compute. A partial fix is to add a isZero function to help reduce the creation of uselss objects in some scenarios (like getOpenPositions):

    public isZero (): boolean {
        return this.#value === 0n;
    }

The the major issue I wasn't able to fix.

Report generation and equity

In a backtest we usually wants to know which positions where opened, when closed, drawdown, etc. Would be very nice to have a final report for all positions happened during the backtest and some stats.

Also I noticed that the TradingAccount#getEquity isn't very useful, because it just tries to sell the assets but doesn't look at real position opened, its behavior in backtest engine is completely different then cTrader for example.

from mida.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.