Hi Team,
I noticed that when the algo automatic restarts on sunday, the variables that I stored in the code (e.g. filled price) gets reset. Is there a way to avoid that or we need to build the code assuming that it will be reset on a weekly basis?
QUANTCONNECT COMMUNITY
Hi Team,
I noticed that when the algo automatic restarts on sunday, the variables that I stored in the code (e.g. filled price) gets reset. Is there a way to avoid that or we need to build the code assuming that it will be reset on a weekly basis?
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.
Mia Alissi
Yes, there is a way to preserve the state of your algorithm across restarts. QuantConnect provides a feature called the Object Store which allows you to save data that can be accessed in the next algorithm restart.
Here is an example of how you can use the Object Store to save and retrieve a variable:
Please note that the Object Store is intended for small pieces of data, such as algorithm state or configuration settings. It is not designed to store large amounts of data like price history or other dataset.
Also, remember that the live trading algorithm portfolio is loaded from the brokerage holdings, including open orders. So, your algorithm should not assume it starts from an empty portfolio as you may have holdings from previous deployments.
Lastly, if the algorithm is terminated unexpectedly, you should review the live algorithm portfolio at the brokerage to confirm it will behave as expected.
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.
Francesco
Hi Mia,
thank you for your reply, I would like to store a variable that contains a number, but it gives error. By reading the guide I see that I can store only strings and bytes? is that the issue? how can I store a numeric value?
Mia Alissi
Yes, you're correct. The Object Store in QuantConnect can only directly store
string
andbytes
objects. If you want to store a numeric value, you would need to convert it to a string before saving it, and then convert it back to a number after retrieving it.Here's how you can do it in Python:
In this example,
str()
is used to convert the numeric value to a string before saving it, andfloat()
is used to convert the string back to a number after retrieving it.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.
Francesco
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!