Back

Problem with History function

Hi,

I have a minute bar strategy, that retrieve previous daily trade bar with help of History function and then open a deal at Market open time with help of MarketOnOpenOrder function. In my LEAN project everything works fine, but in web-platform it doesn't. I noticed, that daily bar open price doesn't match the open market price (at 9:30). To prove it I created simple strategy, that find the minute trade bar, open price of witch matches open price of daily bar (I retrieve daily bar with help of History function).  And It doesn't find any appropriate minute trade bar at market open (at 9:30).  

Why open price of daily bar doesn't match open price of the first minute trade bar at market open time?

I attached the code of that test strategy.

Thanks in advance.

namespace QuantConnect
{
class TestHistoryStrategy : QCAlgorithm
{
string m_Ticker = "SPY";
List<TradeBar> m_TradeBarList = new List<TradeBar>();

public override void Initialize()
{
SetCash(30000);
//Set start date and end date
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11);
AddEquity(m_Ticker, Resolution.Minute, null, true, 0, true);
}
public override void OnData(Slice slice)
{
TradeBars a_TradeBars = slice.Bars;
Symbol a_Symbol= QuantConnect.Symbol.Create(m_Ticker, SecurityType.Equity, Market.USA);
if (a_TradeBars.ContainsKey(a_Symbol))
{
m_TradeBarList.Add(a_TradeBars[a_Symbol]);
}
if (Time.Hour == 9 && Time.Minute == 30)
{
IEnumerable<Data.Market.TradeBar> bars = History(a_Symbol, 1, Resolution.Daily);
List<TradeBar> a_HistoryBarList = bars.ToList();
if (a_HistoryBarList.Count == 1)
{
TradeBar a_HistoryDailyBar = a_HistoryBarList[0];
foreach (TradeBar a_BarFromList in m_TradeBarList)
{
if (a_BarFromList.Time.Day == a_HistoryDailyBar.Time.Day && a_BarFromList.Open == a_HistoryDailyBar.Open)
{
Log("Canndle with the daily open price for the date "+a_HistoryDailyBar.Time.ToShortDateString()+":");
Log("Open=" + a_BarFromList.Open.ToString() + " Close=" + a_BarFromList.Close.ToString() + " StartTime=" + a_BarFromList.Time.ToString() + " EndTime=" + a_BarFromList.EndTime.ToString());
}
}
}
}
}
}
}

 

Update Backtest








The earliest QCAlgorithm.Time possible when we have subscribed to securities with minute resolution is 09:31 (closing time of a minute bar that opens at 09:30). We recommend the Schedule Events feature for this sort of operation:

// Schedule an event to fire every trading day for a security
// The time rule here tells it to fire 10 minutes after SPY's market open
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.AfterMarketOpen("SPY", 10), () =>
{
Log("EveryDay.SPY 10 min after open: Fired at: " + Time);
});

Please do not log prices. It is against terms of service.

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, Alexandre,

I understood about price logging. But your answer can't help me, because according to the log of my attached strategy open price of daily trade bar doesn't match neither open price of minute trade bar at 9:30 nor at 9:31.

0

hmm he is looking back one day and wants the daily candle for that specific previous date but is using minute resolution. Changing to extendedmarkethours false does not the change the wrong candlevalue of 156 which should be on that date around 168 (spy).

0

Sorry, I misunderstood your first post.
We are looking into this issue. Thank you for reporting.

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, Alexandre,

Can you tell me, when you fix the problem?

0

We cannot give an ETA at this time but we are actively working on it and wil post back here shortly.

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.


Sorry forgot to report back :) It was fixed on Monday. 

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