-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Backtest multiple instruments at once #20
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@jetychill You just need to setup a for instrument in instruments:
data = run api calls to get data or load csv's
bt_long = Backtest(`data`, `your strategy`, margin=0.002, cash=500)
stats_long = bt_long.optimize(
whatever optimization fields,
maximize='Equity Final [$]'
) Obviously there is likely a bunch of data cleanup but that is something left to the user. Hope this helps! |
Thanks for the help! Thanks |
Multiple positions/instruments aren't yet supported. Welcome a discussion if someone would have a look.
@jetychill By default it doesn't. Can you share a minimal working example? |
Sounds like a good idea for a composable base strategy, |
I would also be interested in being able to have multiple instruments at the same. This could possibly be implemented using a pandas panel. In this way arbitrage strategies would be possible to backtest. |
@nicoloridulfo Can't one backtest arbitrage opportunities by providing the strategy with extra data? |
@kernc Thanks for answering. I believe that is not the case. Correct me if I am wrong. I would be interested in trying to implement such a feature if you'll assign me to it. |
Ah, pairs arbitrage. 😅 I don't know how multiple instruments fit into the existing API. I'd foremost like to keep it simple and straightforward for the 95% use case. If you do care to look into it, however, please certainly base your findings on PR #47 as that's about to get merged soon. |
Not only for arbitrage! I was thinking multi instrument portfolios. |
Would suggest first make the single equity finished(which is 90+% od the use case) then considering enhance to support multiple equities in one strategy. Can imaging things will go complex towards what backtrader looks like. |
You also will need to support TP or SP per group of instruments. |
Is this assigned? |
I also was looking at one of the other issues that has suggested adding support for stock options. I think this would be a prerequisite for that, because option strategies are usually a combination of one, two , or more long or short trades on Put or Call options. |
What is the API implication to implement this? Though I tend to think this is a feature very worth to have. |
It would be really helpful if we could do pair tradings. Thank you so much :D |
Pair trading seems like a popular algorithm yet no one bothers to develop a proper backtest API for its. Fine, I will do it myself |
@truongthanh96 how is the progress? |
Im trying to backtest a pairs trading strategy but i don't know how to add multiple data frames to the backtester in order to add positions to each instruments according to the hedge ratio.
Is there a way to do this?
The text was updated successfully, but these errors were encountered: