Hi everyone,
I’m finding it particularly challenging to manage two different time scales within the same algorithm. Specifically, my trading logic operates at a lower frequency, while the risk management model requires a higher frequency.
Currently, I haven’t been able to effectively monitor positions at a minute resolution for risk management purposes when my alpha model is based on hourly bars. Using consolidators has caused the algorithm to stop trading altogether. I also attempted to use the Schedule.On method to maintain the initial hourly resolution for the alpha model while overriding the risk management logic, but it didn’t have any impact on the crash test drawdown.
If the QC team or the community has a good example of a risk management model operating at a minute (or consolidated minute) resolution alongside an alpha model using hourly resolution, I’d be very interested in studying it.
Thank you in advance!
Best regards
Sebastien M. Laignel
Mia Alissi
To help Sebastien manage different time scales within the same algorithm, here's a structured approach using QuantConnect's capabilities:
Step-by-Step Implementation
Set Up Data Subscriptions:
self.add_equity
to add securities with the desired resolution.Use TradeBarConsolidators:
TradeBarConsolidators
to aggregate minute data into hourly bars for your alpha model. This ensures the consolidator time period matches the desired resolution.Implement Risk Management:
CompositeRiskManagementModel
to combine multiple risk management strategies, such asMaximumDrawdownPercentPortfolio
andMaximumUnrealizedProfitPercentPerSecurity
, which can operate on minute data.Schedule Risk Management Checks:
Schedule.on
method to run risk management checks at a minute resolution, ensuring these checks are independent of the alpha model's hourly resolution.Handle Data in OnData:
OnData
method, process both the consolidated hourly data for your alpha model and the minute data for risk management, ensuring each component operates on its respective data. ```python def on_data(self, data):Handle minute data for risk management if data.bars.contains_key("SPY"):def on_hourly_data(self, consolidated_bar):
```
Test and Validate:
Optimize and Adjust:
By following these steps, Sebastien can effectively manage different time scales within the same algorithm, ensuring that both the alpha model and risk management operate efficiently.
Sources: Time Period Consolidators - QuantConnect.com, Data Consolidation Algorithm, Getting Started - QuantConnect.com, A Risk Parity Approach to Leveraged ETFs, Intraday Application of Hidden Markov Models
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Sebastien M. Laignel
I have a universe of 200 stocks, not a manual universe of few tickers. What should be the resolution in the main loop ?
Sebastien M. Laignel
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!