Back

How to pass data to scheduled function (python)?

Sorry, beginner here. I can't figure out how to get a security price while in scheduled function. Tried different things, getting errors...

Update Backtest








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))

 

1

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.


Can we do the same thing with options data?

0

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.

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