Click here to Login





                                                   Update existing Historical Earnings Surprise trading object?

  0

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


Hi,

Recently Yahoo made some changes on their earnings calendar / surprise pages (eg, https://biz.yahoo.com/z/20160201.html) 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.

Thanks,
KP



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

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


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




#functions#

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;
t.Start((object)UrlContent);
t.Join();
}


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

wbc.ScriptErrorsSuppressed = true;
wbc.DocumentText = (string)html;
wbc.Document.OpenNew(true);
wbc.Document.Write((string)html);
wbc.Refresh();

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

QuantShare
2016-02-18 10:55:04

  0

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.



Kiran
2016-12-05 15:17:49

  0

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

QuantShare
2016-12-06 04:04:24

  0

It does work here. Try debugging the downloader and see what you get on 2015/2016.
http://www.quantshare.com/how-431-how-to-debug-a-downloader

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



No more messages
0




Reply:

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"










QuantShare

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
Trading Items: Data Download using .Net Scripts
Intermarket Analysis - Correlation and Trading Strategies
Basic trading system implemented using the money management tool









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
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.