Back

Close history

Hi everyone,

I am trying to get the close price of the day, but as you can see I get 266.79 for the close of the 14th December 2017 but it's the close of the 13th December not the 14th.

Any idea ?

2017-12-14 00:00:00 : Time 2017-12-13 16:05:00
2017-12-14 00:00:00 : Close history symbol time SPY 2017-12-09 265.49 2017-12-12 266.34 2017-12-13 266.79 Name: close, dtype: float64
2017-12-14 00:00:00 : Close Today 266.79
import numpy as np
from datetime import datetime

class price_check(QCAlgorithm):
'''Basic template algorithm simply initializes the date range and cash'''

def Initialize(self):

self.SetStartDate(2017,12,11) #Set Start Date
self.SetEndDate(2017,12,14) #Set End Date
self.SetCash(100000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
self.AddEquity("SPY", Resolution.Minute)
self.spy = self.AddEquity("SPY", Resolution.Minute).Symbol

# at market close
self.Schedule.On(self.DateRules.EveryDay(self.spy), \
self.TimeRules.BeforeMarketClose(self.spy, -5), \
Action(self.EveryDayAtMarketClose))


def OnData(self, data):
pass

def EveryDayAtMarketClose(self):

lookback = 3
hist = self.History(self.spy, lookback, Resolution.Daily)
lastPrice = self.Securities[self.spy].Price

close = hist["close"]
self.Log('Time {}'.format(str(self.Time)))
self.Log('Close history {}'.format(close))
self.Log('Close Today {}'.format(close[-1]))

Thank you.

Update Backtest








Close prices are always at the end of the time-step (begining of the next time-step). 
2017-12-14 00:00:00 IS the close time for the 13th with a daily bar.

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.


Thank you Jared.

If I understand it correctly, the close of the 14th will be available only after midnight ?

0

Yes, the close price is the last value we record before the day 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.


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