Handling assets with different history lengths

Posted By: MegaTanker

Handling assets with different history lengths - 08/28/21 17:37

Working on a script that filters through a large list of assets, some of which are much younger than the backtest length. The history can be as short as a year but since I'm working with daily bars, I can't cut the backtest length short to just one year.
I have plotted one such histories and have noticed that it propagates the earliest value in the history all the way to the earliest day of the backtest. This means I probably can't check if price() returns something valid, because it does no matter what.

I have found AssetFrame in the manual which states: "Asset specific time frame, automatically set by AssetZone or AssetMarket. 0 when the current asset had no price quotes in the current bar or when its market is closed".
I haven't tested if that works for my intended purposes, it seems to be designed for some other purpose. Is there a recommended way to check if an asset already has a history at the current bar? I also need to consider that each asset will need some lookback period to calculate indicators and such. I could run an int array that counts up each encountered bar of an asset, and then only start considering assets once the counter is greater than the lookback. But maybe there's some built-in solution to this problem?
Posted By: danatrader

Re: Handling assets with different history lengths - 08/29/21 13:17

Sorry, but totally unclear for any reader what your question is.
Posted By: MegaTanker

Re: Handling assets with different history lengths - 08/29/21 14:51

Ok, I'll try differently: I want the backtest to be 5 years long but the asset list includes assets that haven't existed 5 years ago because they're new companies, so the historical data for those doesn't go back 5 years. I need to find out at each bar if an asset already has valid price data at this current bar or not.
Posted By: jcl

Re: Handling assets with different history lengths - 08/30/21 08:25

Compare the current price with the first price. If both are identical, the history has not yet begun.

Normally it doesn't matter because trades are usually not triggered anyway when the price curve is flat.
© 2024 lite-C Forums