I have a csv file / pandas dataframe which looks like this. It contains various portfolio compositions for different strategies. Mostly based on different optimisation methods, max sharpe, min VaR etc..

date        asset   percentage strategy
4-Jan-21    AAPL    12.00%  strategy1
4-Jan-21    TSM 1.00%   strategy1
4-Jan-21    IBM 31.00%  strategy1
4-Jan-21    KO  15.00%  strategy1
4-Jan-21    AMD 41.00%  strategy1
4-Jan-21    DELL    23.00%  strategy2
4-Jan-21    TSM 12.20%  strategy2
4-Jan-21    IBM 15.24%  strategy2
4-Jan-21    KO  1.50%   strategy2
4-Jan-21    NKE 7.50%   strategy2
4-Jan-21    TSLA    9.50%   strategy2
4-Jan-21    CSCO    3.30%   strategy2
4-Jan-21    JPM 27.76%  strategy2
4-Jan-21    AMD 45% strategy3
4-Jan-21    BA  0.50%   strategy3
4-Jan-21    ORCL    54.50%  strategy3
5-Jan-21    …   …   strategy1

I want to test a bunch of strategies with a 30 asset portfolio.

So lets say on 4Jan2021, strategy1's composition would be 12% in apple, 1% in TSM.. etc. I want to be able to check the prices and know howmany I should be holding. I can easily create a function for that.

I have been looking at backtrader as a backtesting platform, however, the code I have seen in the repo mostly shows how to do stuff with indicators, like SMA cross over, RSI...

My question is, is it possible to create and test portfolios based on these compositions I have so I can test which strategy is the most profitable one? So if I'm testing strategy1, it would check this frame, and know howmany stocks in apple to buy or sell on that particular day.

Is there example of code anywhere that would let me test my strategy based on the frame I have?

I am new to backtesting and backtrader, any help would be greatly appreciated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.