Click here to Login

                                                   Update existing Historical Earnings Surprise trading object?


Kyra Packens
2016-02-18 01:39:52


Recently Yahoo made some changes on their earnings calendar / surprise pages (eg, that caused the Historical Earnings Surprise, EPS and Consensus Data downloader to stop working properly. That data is pretty important for a number of my strategies, so I went ahead and coded up a fix.

Now, my question is, what is the best way to share the fix? It would be nice to be able to update the existing trading object with the update, but I don't think I can do that(?) I know that I could submit a new trading object, but that seems like it would be confusing since its purpose would be identical to the existing object. Suggestions?

Anyhow, I'll go ahead and paste the updated Pre-Script code below -- it should be the only change needed to fix the downloader.


>>>>>>>>>>>>>>>>>>>> Pre-Script >>>>>>>>>>>>>>>>>>>

using System.Windows.Forms;
using System.Threading;

new ParseHtml(Global, Content).Parse();


public class ParseHtml

QuantShare.Scripting.Global Global;
PreScript Content;

string UrlDate;
string UrlContent;

public ParseHtml(QuantShare.Scripting.Global g, PreScript c)
this.Global = g;
this.Content = c;

// Get date from URL
string date = Content.GetURLORFileName().Replace(".html", "");
date = date.Substring(date.LastIndexOf('/') + 1);
this.UrlDate = date;

// Yahoo uses "N/A" for unknown / invalid data; QS needs NAN for these
this.UrlContent = Content.GetContent().Replace("N/A", "NAN");

// Ignore all unprocessed data
for(int i=0; i < Content.Rows.Length; i++) {
Content.Rows[i].IsIgnoreLine = true;

public void Parse()
Thread t = new Thread(DoParse);
t.ApartmentState = ApartmentState.STA;

private void DoParse(object html)
WebBrowser wbc = new WebBrowser();

wbc.ScriptErrorsSuppressed = true;
wbc.DocumentText = (string)html;

System.Windows.Forms.HtmlDocument doc = wbc.Document;

// Grab all rows in the document
HtmlElementCollection rows = doc.GetElementsByTagName("TR");

// Inspect each row looking for those containing 7 TD elements; these rows hold
// the data that we're after. Quick and dirty, but awfully fragile...
foreach (System.Windows.Forms.HtmlElement row in rows) {

HtmlElementCollection cels = row.GetElementsByTagName("TD");

if (cels.Count == 7) {
string symbol = cels[1].InnerText;
string surprise = cels[2].InnerText;
string eps = cels[3].InnerText;
string consensus = cels[4].InnerText;

Content.AddRow(UrlDate, symbol, surprise, eps, consensus);


Historical Earnings Surprise, EPS and Consensus Data (by Patrick Fonce, uploaded several months ago)
No notes

Rate an item Rate an item Rate an item Rate an item Rate an item Number of downloads Notes Report an item

2016-02-18 10:55:04


Best Answer
Thank you Kyra. I have updated the pre-script and uploaded the new item.
Only the owner or admin can do that. Thank you again for the new code.

2016-12-05 15:17:49


I downloaded the script and data - but it gives NaN for all releases after Jan 2015, for the Surprise, EPS and Consensus fields.
How do i fix this, so it gives valid data for all the recent releases in 2015 and 2016?

The data is fine for 2010->end of 2014.

Historical Earnings Surprise, EPS and Consensus Data (by Patrick Fonce, uploaded several months ago)
No notes

Rate an item Rate an item Rate an item Rate an item Rate an item Number of downloads Notes Report an item

2016-12-06 04:04:24


It does work here. Try debugging the downloader and see what you get on 2015/2016.

Also please send us the last few recent trace files by email to support.

No more messages


No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"


Trading Items
Historical Earnings Surprise, EPS and Consensus Data
Historical trading volatility-based system to adjust trade sizes
Earnings Surprise Strategy
Historical Earnings Calendar Data for U.S. Stocks - Date/Time and...
Historical Earnings Calendar for Major Stock Exchanges

How-to Lessons
How to create a trading system
How to download and use U.S. stocks earnings data
How to add a trading indicator to a chart
How to import trading data from CSV files
How to download earnings calendar data for various stocks

Related Forum Threads
historical earnings surprise
Sales Surprise and Earnings surprise data?
Historical Earnings Calendar doesn't download after Nov 2016
Download symbols, update symbols, then download historical data
Problems Downloading Historical Earnings Data

Blog Posts
How to create a trading system, screen and composite using earnin...
Update Chart Layout based on Active Ticker Symbol
The Ultimate Guide to Create Trading Systems in QuantShare
Trading Items: Data Download using .Net Scripts
Basic trading system implemented using the money management tool

Create an account
Affiliate Program
Contact Us
Trading Forum
How-to Lessons
About Us
Terms of Use

Copyright 2021
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Follow us on Google+
RSS Trading Items

Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.