Back

HELP: Getting current price in scheduled function.

I know it was discussed already (see below). However I found that in my Algo Security.Price returns 0 for whatever reason. 

I created notebook to confirm (attached). Something is obviously missing - any suggestions?

 

 

 

https://www.quantconnect.com/forum/discussion/2324/how-to-pass-data-to-scheduled-function-python

 

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.


Hi Artem, the backtest below is my attempt to recreate the issue however the prices do get printed. The QuantConnect research environment is helpful when importing historical price data. I suggest trying to debug in the QuantConnect Lab.

0


Hi,

it's fine to get prices from OnData. My question is how to get prices from other scheduled functions? However the code I posted didn't work in research env as well. And I can't understand why.

for i in qb.Securities.Values:
print(i.Symbol.Value + ":" +str(i.Price))

 

 

 

0

Hi Artem.

You can retrieve prices with qb.History() in the research environment:

symbols = [x.Value for x in qb.Securities.Keys]
hist = qb.History(symbols,1,Resolution.Daily)

To retrieve prices at a certain time during the day, use the Schedule.On() method. In the attached backtest, I've demonstrated how you can print SPY close price using Schedule.On() to the attached log file. For further information, check out this documentation section on Scheduled Events.

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 Haldor, It's helpful. So qb.Securities.Price - doesn't actually work but returns no error, Ok. I updated my test case and 2 more questions.

1. Why Price of any freshly added to universe security returns 0 1st day?

2. Why during history requests symbol names mangled to smth like 

AAPL R735QTJ8XC9X AMZN R735QTJ8XC9X FB V6OIPNZEM8V9Will it affect anything? Logs are here: https://www.quantconnect.com/backtest/66117/2367060/9a074dd1efed3f0986b5eacd69ce9d44-log.txtBacktest attached
 
0


Hi Artem.

Use the method History() to retrieve prices in the research environment.

1. You can resolve the issue by setting the universe data resolution from daily to minute — the data resolution input used in the method Schedule.On() is then in sync with the universe data resolution: 

self.UniverseSettings.Resolution = Resolution.Minute

2. This is the identification of each security in the security universe. The method History() returns a pandas DataFrame() object. When you print out the DataFrame, you see the security identification as a column name, which by itself does not affect anything.

I've attached a backtest where I set the data resolution for the security universe to a minute data resolution which resolves the issue of retrieving zero prices for added securities to the security universe.

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