Back

How to get a stock's price change for the first day without calling history()?

For example, I have AddEquity("SPY", Resolution.Minute") to get SPY on-minute data. However, for the first day, how do I get SPY's price change for that day?

SPY price change today = SPY current price - SPY yesterday's close price.

I need to know the Close price of yesterday to calculate it. I know I can call history() and request for just one bar of daily history to get the Close price of yesterday, but I am wondering if there is actually some easier way to do it without calling history()?

Update Backtest







0

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.


Hey JL Lord,

You can use a scheduled event that fires at market close to store each day's close. Then you can use that stored close to calculate the next day's price change.

0

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.


Thanks, Rahul

but I still cannot get the Closing price when the alogrithm runs "the first day". I need to wait one day to get previous day's closing price when an algo starts. I hope to get the closing price without waiting. Right now, the only way I know is to call history(). 

However, history() will make the algo crash (10-minutes loop error) in Live trading when the number of symbols is around 1000. The crash doesn't happen in Back Testing mode, but just in Live Mode. I've tried several times and found it happening, which is another issue.

0

Hey JL,

If you are using universe selection, the only way to warmup your daily close values is with a history call. I wrote an example for you.

For issues with live trading, please submit a live trading support ticket by accessing Algorithm Lab -> Support -> Add Project -> Attach Live Deployment. This is the best way to get support for live trading issues.

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed