Comments (3)
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.
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.
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)
- Metatrader support HOT 1
- [FEATURE] CCXT Bridge HOT 2
- [FEATURE] clientOrderId HOT 3
- [FEATURE] getSymbolPeriods on the past HOT 3
- [FEATURE] `getSymbolPeriods` without authenticated account
- Time in force undefined is unknown HOT 3
- Mida login on AWS lambda HOT 6
- Adding a custom id to a MidaTradingAccount HOT 4
- Closed Position Detail HOT 3
- H4 timeframe HOT 3
- Missing import { marketComponent, } HOT 2
- Can Mida introduce and use it in react? HOT 1
- ProtoOAGetTickDataReq does not work HOT 1
- `placeOrder` message `Unknown payload type 2142` HOT 16
- cTrader token expiration date
- Package depending on vulnerable versions of dependecies
- Closed Position Detail HOT 1
- The cTrader getOrders function return only 5 entries HOT 1
- Help with Backtester - Question HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mida.