Sorry, beginner here. I can't figure out how to get a security price while in scheduled function. Tried different things, getting errors...
QUANTCONNECT COMMUNITY
Sorry, beginner here. I can't figure out how to get a security price while in scheduled function. Tried different things, getting errors...
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.
Alexandre Catarino
QCAlgorithm has a member called Securities. It is a dictionary with information from all the subscribed securities that can be accessed every time we need. Here is an example on how to get the security price in a scheduled event:
class MyAlgo(QCAlgorithm): def Initialize(self): AddEquity("SPY") self.Schedule.On(self.DateRules.EveryDay("SPY"), \ self.TimeRules.AfterMarketOpen(self.spy, 60), \ Action(self.print_first_hour)) def print_first_hour(self): spy = self.Securities["SPY"] price = spy.Price self.Log("EveryDay.SPY 60 min after open: Fired at: {0}. Price: {1}".format(self.Time, price))
Jon Soll
Can we do the same thing with options data?
Gurumeher Sawhney
Yes, It is possible to get options data in a scheduled event. Note that the sliced data needs to be saved previously and then called upon in during the scheduled event.
Iouri Verchok
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!