Back

How do you find open and close prices?

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
------------------------------------
Update Backtest








Hmmm, I wonder if the reported open/close are actual trades or if they can just be quotes? I don't think QuantConnect has the quote data yet which could explain the discrepancy. I've modified your algorithm slightly to also look at tick data.
0

I've been having trouble attaching projects lately. Here's the modified Main.cs.

EDIT: Wonderful, now it posts! Hmm... maybe it's user error. I've been trying to attach a project without a backtest, maybe this has been my fatal flaw!


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;
}
}
}
0


I ran yours but got no log, were you still not getting correct open/close?

I just tested the starter algo "50d-10d Exponential Moving Average Cross" and noticed its open prices also did not match reality...

So I don't know anymore..
0

I just ran it and got a log, see it here: http://data.quantconnect.com/backtests/7498/30304/9633499bacbc06f65f2d433be95fe044-log.txt

But like you're experiencing, they still don't perfectly match reported open/close prices. As I was saying earlier, I wonder if the reported open/close prices are based on quote data, which I don't believe QuantConnect has yet.
0

Hey guys - we discussed briefly on an earlier thread - and I manually downloaded the data to verify the raw closing price was identical.

If you go back far enough the price will also be different because of splits and dividend adjustments. We use backwards adjusted data - so the dividends and corporate splits have been accounted for in the data you're receiving. In the cases of more than a few days ago it will most certainly be backwards adjusted, to be the same as the Yahoo adjusted price.

Potentially with open sourcing we can make this configurable (so the dividends are deposited as cash into your account instead of being factored into the stock price).

The third potential difference - the price you see on yahoo and google finance aren't created by actual trades! :) It was set by a human who makes the representative price for the open and closing. Because the stock trades on multiple exchanges and volumes there is no one open or close price. There was another private email-discussion thread on this recently as well - its fascinating because I never realized the markets were like this!
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.


Wow! Thanks for the insight Jared. I never really stopped to think about it, but that all makes sense.
0

End of Day events are fired once per symbol at 3.50pm. This was made to give people time to sell off stocks at the end of the day. I've attached another version very close to Yahoo which logs the last bar of previous day (3.59pm).
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 Jared, It seems your code matches the prices as the previous methods, so it isn't a coding problem, but a timing problem.

The open/close price seems to be pretty consistent across the internet sources, I've never seen multiple that are different. But I also haven't found exactly how or when they come up with these numbers...

I'd like to be able to get to the code to match, because there are many strategies this affects. (Every daily indicator, opening gaps, whether the stock is up/down for the day, etc)

Instead of trying to calculate it, is there a way to just extract the data from an online provider?
0

A few comments.

...the price you see on yahoo and google finance aren't created by actual trades! :) It was set by a human who makes the representative price for the open and closing.

As far as I know they are always actual trades. Most data vendors, platforms, and sites display the official closing print of the listing market for the particular security as the closing price (or previous close). The official closing price is in most cases determined in an automated (except NYSE that the closing of each symbol is still a very manual affair) closing cross; you know MOC, LOC. Should there be no cross for a security the norm is to call the last trade at or before the market close time (4PM usually) the closing price.

Since the crosses are automated in all markets that hold them (except NYSE as mentioned above) the actual closing print comes just after 4:00:00 PM (as in ?s's after or less). In NYSE's case this can be seconds to minutes after 4PM (even >10 minutes).
0

Fascinating @Eliezer - it didn't make sense to me it would be manually set. With 11,000 symbols it would take days. Can you think of some way we could reproduce that official closing price with the trades data?

@Kevin - IMHO it doesn't seem important to reproduce official - if you use the actual trades before 4pm then its what you can realistically trade.
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.


@Jared, That is precisely what the "SaleCondition" flag is used for. From the QuantQuote TickView Historical Trades spec you can see several flags that indicate the closing print according to how QuantQuote categorizes the symbols.

For instance:
‘6’ – Market Center Closing Prints
‘M’ = Market Center Close Price
‘6’ – Closing Prints

Without being able to look at the tick data (including the SaleCondition) it is hard to say which flag applies to which market center (their specification is a bit outdated).
0

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.

0

@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.

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