You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Thanks for the help!
Another question, does the back tester has some sort of default maximum holding time where it closes the position after n amount of time has passed I'm comparing results to my back tester and they seem identical, but when there is a long holding period the the results vary significantly, could also be a bug on my side but just asking if the back tester by default closes positions earlier.
I believe that is not the case. Correct me if I am wrong.
I have studied the code and from what i see: one backtest = one instrument. It is not possible to look at multiple instruments in the same backtest and e.g. go long one instrument and short an other. If the order placing would be instrument specific and with some minor changes to the broker and strategy classes, I believe that it could be possible. The rest of the code is written in such a way that it seems like it was made to support this kind of feature.
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.
One of the most important parts of trading is risk management. Portfolio optimization through asset diversification is one way. I'll look into it 👍
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.
Ther are still gaps for single equity case to fill or to verify, suppoorting of Future/Stocks with options of:
Margin/NonMargin
Shortable/NonShortable
T+0 or T+N
If putting everything in one backtest too complicated, possible split another parallel backtestbroker to deal with subset of cases ?
Activity
chhudson commentedon Sep 17, 2019
@jetychill
Definitely!
You just need to setup a
for
statement to pull from a list ofinstruments
IE. `instruments = ['USD_JPY', 'EUR_USD']
Obviously there is likely a bunch of data cleanup but that is something left to the user.
Hope this helps!
ghost commentedon Sep 17, 2019
Thanks for the help!
Another question, does the back tester has some sort of default maximum holding time where it closes the position after n amount of time has passed I'm comparing results to my back tester and they seem identical, but when there is a long holding period the the results vary significantly, could also be a bug on my side but just asking if the back tester by default closes positions earlier.
Thanks
kernc commentedon Sep 17, 2019
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?
kernc commentedon Sep 24, 2019
Sounds like a good idea for a composable base strategy,
HoldNBarsStrategy
. 💡ridulfo commentedon Mar 22, 2020
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.
kernc commentedon Mar 22, 2020
@nicoloridulfo Can't one backtest arbitrage opportunities by providing the strategy with extra data?
ridulfo commentedon Mar 22, 2020
@kernc Thanks for answering.
I believe that is not the case. Correct me if I am wrong.
I have studied the code and from what i see: one backtest = one instrument. It is not possible to look at multiple instruments in the same backtest and e.g. go long one instrument and short an other. If the order placing would be instrument specific and with some minor changes to the broker and strategy classes, I believe that it could be possible. The rest of the code is written in such a way that it seems like it was made to support this kind of feature.
I would be interested in trying to implement such a feature if you'll assign me to it.
kernc commentedon Mar 22, 2020
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.
ridulfo commentedon Mar 22, 2020
Not only for arbitrage! I was thinking multi instrument portfolios.
One of the most important parts of trading is risk management. Portfolio optimization through asset diversification is one way. I'll look into it 👍
sdmovie commentedon May 27, 2020
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.
Ther are still gaps for single equity case to fill or to verify, suppoorting of Future/Stocks with options of:
Margin/NonMargin
Shortable/NonShortable
T+0 or T+N
If putting everything in one backtest too complicated, possible split another parallel backtestbroker to deal with subset of cases ?
diegolovison commentedon Aug 17, 2020
You also will need to support TP or SP per group of instruments.
Example:
buy: A, B, and C
TP 5% [A,B,C]
SL 10% [A,B,C]
15 remaining items