Start strategy from 2008 even if some stocks was listed later
-
Hello guys,
I prepared the following strategy based on some fundamental indicators I select 10 stock each month and buy them. Now my current output is a map where the key is a date of entry and as value, I have a map where the key is a stock and the value is the percent of the portfolio to invest.
Something like this:
2018-01-29: {'JPM': 0,5, 'AAPL': 0,5}
I wanted to apply this map to bakctrader to see the strategy analyzer outputs to select the best fundamental indicators.Now I have a problem as for example when my calculation output is done for 2008-2021 range a lot of stocks was not listed in 2008 and backtrader is not able to start from 2008. Is any workaround for this?
-
@strazak
Backtrader prefers full lines.Input your data using a Pandas dataframe. Start by having a full datetime index in memory available for the period you want. I tend to copy a datetime index from another similar stock I know had trading on every day for the whole period. Then simply create a dataframe of your data, then reindex to the new index with
method='ffill'
Then
fillna(0)