Best way to implement multiple individual contracts for the same instrument?
I would like to test some carry strategies on commodities, which requires calculation of implied yield on multiple individual contracts of the same instrument, e.g. soybean oil from the front month to 2 years out. So continuously linked contracts based on rollover doesn't seem to be convenient for this purpose. I am wondering what is the best way to implement this? I am sure someone else probably figured this out before. Some thoughts I have:
- Naively I can add all the datefeeds to cerebro, and have my indicator go through them one by one. Is there a more elegant way, say expand the csvdata class so that the one datafeed object would contain all the contracts of the same instrument, and deliver either front month or back month intelligently? or handle it at the strategy level, instead of datafeed level?
- Or is it better to pre-process the data, adding the implied yield as a new column to the csv. This way cerebro doesn't need to load multiple individual contracts. The value/momentum strategies only need the front month to operate, only carry needs the extra data along the curve. Maybe this way is more efficient?
Appreciate any insights the community could provide. Thank you.