This is a constant problem that I have not yet worked out.
I have attached a simple code that attempts to find the Open/Close in two different methods. One is by using Timestamps, and the other using the TimeSpanConsolidator class making a one day bar. Both seem to be ineffective, here is the log:
ACTUAL VALUES:
12/01/14: Open: 206.40, Close: 205.76
12/02/14: Open: 205.81, Close: 207.09
====================================
EVALUATED VALUES:
TIME: Open: 206.43 Close: 205.77
CONSOL: Open: 206.43 Close: 205.77
------------------------------------
TIME: Open: 205.81 Close: 207.04
CONSOL: Open: 205.8 Close: 207.04
------------------------------------
Michael H
Michael H
using System; using System.Linq; using System.Collections.Generic; using QuantConnect.Securities; using QuantConnect.Models; namespace QuantConnect { // Name your algorithm class anything, as long as it inherits QCAlgorithm public class BasicTemplateAlgorithm : QCAlgorithm { decimal open = 0m; decimal close = 0m; private Consolidator oneDayConsol; //Initialize the data and resolution you require for your strategy: public override void Initialize() { SetStartDate(2014, 12, 01); SetEndDate(2014, 12, 03); SetCash(1000); AddSecurity(SecurityType.Equity, "SPY", Resolution.Tick); oneDayConsol = new Consolidator(TimeSpan.FromDays(1)); Log("ACTUAL VALUES:"); Log("12/01/14: Open: 206.40, Close: 205.76"); Log("12/02/14: Open: 205.81, Close: 207.09"); //Log("12/03/14: Open: 207.30, Close: 207.89"); Log("===================================="); Log("EVALUATED VALUES:"); } Tick last; Tick first; public void OnData(Ticks ticks) { List tick;
if (ticks.TryGetValue("SPY", out tick))
{
// im not sure how the ticks are ordered in the list,
// sadly DateTime doesn't provide decent precision so we don't know
// who was actually the first
if (first == null)
{
first = tick.First();
}
last = tick.Last();
}
}
public override void OnEndOfDay()
{
Log("TICK: Open: " + first.Value.ToString(".00") + " Close: " + last.Value.ToString(".00"));
first = null;
}
}
}
Kevin Roe
Michael H
Jared Broad
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.
Michael H
Jared Broad
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.
Kevin Roe
Eliezer Paiewonsky
Jared Broad
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.
Eliezer Paiewonsky
Fred Saff
Hello,
I know it's been 2 years since the last comment in this thread, but I was wondering whether or not there was now a solution to get the "official" daily closing price, instead of the close of the last bar of the day which often still differs from the official close.
Jared Broad
@Fred - "solution to get the "official" daily closing price"; yes what we have in place is a good solution which statistically matches the vast majority of symbols with minimum error. The majority of the time matching precisely.
If you're using intraday data you'll get the last intraday bar. For daily data we use the ticks marked as the closing ticks from the exchanges. We get a bunch of ticks all marked as closing so we pick the best one we can which match Yahoo etc closest as possible. All other public sources also differ so there's no one price. I think it depends on which exchange the physical MarketOnClose order is sitting.
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.
Kevin Roe
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!