Hi all,
i have recently spent some time on an algo which trades 0DTE options (sells them). Some conditions related to min implied volatility and a stop loss/liquidate before end of day features are implemented.
I used some code i found here in another topic, so thanks to the OP of that discussion.
I am trying to run it live but QC rejects it as it uses more ram than my node has (500mb). I know it has to store some option chains, but is there any way to reduce the ram usage?
For example, i may force it to get less strikes in the option chain, but when i try to do so it results in an error due to missing data. Is that because i subscribe to an option contract but then when spot price moves the algo “unsubscribes” from the same option contract?
Moreover any coding tip or improvement is welcome here. Please note that this strategy by design doesn't trade in 2023 (too low vol to justify the risk).
Mia Alissi
Hi Gianluca,
Reducing memory usage in your algorithm can be achieved in several ways. Here are some suggestions based on the information extracts:
Minimize your universe and historical requests: As suggested by Nico Xenox in the forum discussion, reducing the frequency of rebalancing or the number of historical requests can help manage memory usage.
Optimize your algorithm: Before considering a higher live trading host with more memory capacity, it's essential to optimize your algorithm first to ensure efficient usage of resources.
Filter your universe more aggressively: As mentioned by Mia Alissi in the same forum discussion, you can try filtering your universe more aggressively in the
CoarseSelectionFunction
. For example, you can increase the minimum price or dollar volume thresholds.Manage your data subscriptions: As discussed in the forum discussion by Garrison Whipple, managing your data subscriptions effectively can also help reduce memory usage. Make sure to remove data subscriptions that are no longer needed.
Here's an example of how you can manage your data subscriptions:
Remember, each asset in the universe consumes approximately 5MB of RAM, so reducing the number of assets can help with memory usage.
If you still face memory issues after optimizing your algorithm, you may need to consider using a higher live trading host with more memory capacity. However, it's essential to optimize your algorithm first to ensure efficient usage of resources.
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.
Yuri Lopukhov
yes, it looks like this might happen, in this line:
in OnData handler you are trying to get price data for a symbol from the data slice, but it may not be there, not only because option contract is no longer matching your filter, but simply because there were no trades for this contract in this time slice. So you should always check if data slice actually contains data for your symbol, like this:
Gianluca Giuliano
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!