robcarver17 / pysystemtrade

Systematic Trading in python
GNU General Public License v3.0
2.67k stars 839 forks source link

Duplicate markets included in asset class trend calcs #1148

Closed tgibson11 closed 1 year ago

tgibson11 commented 1 year ago

Running a backtest...I see AUD_micro is correctly identified as a duplicate market:

2023-04-19 14:32:53 {'type': 'run_systems', 'strategy_name': 'futures_system'}  Following instruments are 'duplicate_markets' ['AEX_mini', 'AUD_micro', 'Another_thing', 'CAD_micro', 'CHF_micro', 'CNH-onshore', 'COPPER-micro', 'COPPER-mini', 'CORN_mini', 'CRUDE_W', 'CRUDE_W_mini', 'DOW_mini', 'ETHER-micro', 'EU-DJ-OIL', 'EU-DJ-TECH', 'EU-DJ-UTIL', 'EUR', 'EUR_mini', 'GASOILINE_micro', 'GAS_US', 'GBP_micro', 'GOLD', 'GOLD-mini', 'JGB-mini', 'JPY_mini', 'KOSPI', 'KRWUSD', 'LUMBER-new', 'NASDAQ', 'bad_thing'] 

Then a bit later, I see AUD_micro being used in an asset class trend calculation:

2023-04-19 14:32:54 {'type': 'base_system', 'stage': 'forecastScaleCap', 'instrument_code': 'AUD'}  Calculating capped forecast for AUD assettrend16
2023-04-19 14:32:54 {'type': 'base_system', 'stage': 'rules', 'instrument_code': 'AUD'}  Calculating raw forecast AUD for assettrend16
2023-04-19 14:32:54 {'type': 'base_system', 'stage': 'rawdata', 'instrument_code': 'AUD'}  Calculating normalised return for AUD
2023-04-19 14:32:54 {'type': 'base_system', 'stage': 'rawdata', 'instrument_code': 'AUD_micro'}  Calculating normalised return for AUD_micro
2023-04-19 14:32:54 {'type': 'base_system', 'stage': 'rawdata', 'instrument_code': 'AUD_micro'}  Calculating daily volatility for AUD_micro
2023-04-19 14:32:54 {'type': 'base_system', 'stage': 'rawdata', 'instrument_code': 'AUD_micro'}  Calculating daily prices for AUD_micro

Have not checked if this is an issue for the asset class carry rules too.

robcarver17 commented 1 year ago

Yes the logic originally was to include ALL assets in a given bucket for the cross asset rules, which obviously makes sense if a market has been exclued because it's too expensive, but for duplicate markets will result in double counting, so this is indeed a problem.

robcarver17 commented 1 year ago

Fixed now only instruments that appear in system.get_instrument_list() will be considered part of an asset class. That will usually exclude duplicate and ignored instruments; unless you have made a custom call to that function already.