GetNextEarningsDate
Author: tedclimo
Creation Date: 9/5/2010 11:45 AM
profile picture

tedclimo

#1
I cannot get it to work.
I researched Other Scripts using "public static" as well those using "DateTime", Wiki, Wealthscript Programming Guide & even my Deitel C# book.
But cannot figure out the proper syntax.

The goal of this approach is simply to tell script to:
1) Not produce any Alerts for 2 days before, nor 2 days after a forthcoming "published" EPS release date.
2) Not take any trades for 2 days before, nor 2 days after a forthcoming "published" EPS release date.
3) Separate code for requiring both web-sources to confirm "published" upcoming EPS date AS WELL AS code only requiring one or the other of the two web-sources to have a "published" upcoming EPS date.

Here is error msg I get(I don't know what it is asking me to do):
QUOTE:
WealthLab.Strategies.Strategy2.GetNextEarningsDate(string) must declare a body because it is not marked abstract or extern


I placed "GetNextEarningsDate" code in this simple script to make it easier for someone to help. Once solution is present, will than transplant solution to other scripts that will benefit:
CODE:
Please log in to see this code.


Here is Dataset of 100 symbols that all had trades (in the last 1 year), that occurred either two days before or two days after a formal EPS release: Thought it would help in validating revised code.
CODE:
Please log in to see this code.


Thanks in advance,
Ted
profile picture

Eugene

#2
Double check your Deitel book, Ted.

I'm sure that it should state somewhere that static variables are accessed without creating an instance of the class. You're doing just the opposite -- trying to define as static what is already static and can be accessed "out of the box".

1. Remove those 2 declarations,
2. Recollect that GetNextEarningsDate is a member of the Utility class,
3. Fix the call to GetNextEarningsDate -- you forgot to pass the current Bars.Symbol to the function.

I'm updating its online help page in the Wiki with a mockup example: GetNextEarningsDate, GetNextEarningsDate2
profile picture

tedclimo

#3
Thank you for the Wiki example,... it spoke volumes!

Regarding Deitel book, it's like trying to read a foreign language.

My last 10 years of coding have been in WLP 3.x/4.x, so C# is a very slow technique to learn.

Are all Community.Components part of "Utility class"? This is first time I've encountered that term since I started coding in 5.x about 5 months ago. All self taught from coaching you & Robert provide the WL community (I have no formal training).

Good news is, WL(& you guys) have made it possible for me to have 10 consequtive winning years. You Rock!!!

Thank you Obi-Wan Kenobi.

Your humble padawon,

Ted

P.S. Do you ever take a day off??? Seems like I see your postings 24/7 :-(
profile picture

Eugene

#4
Not all Community Components methods and functions are actually a part of the Utility class.

If one digs into the project's source code or the Wiki online help pages, he would see that methods that deal with DataSeries are grouped into the SeriesHelper class, PositionHelper is the place to find Position helper functions, various calculations share the Calculate class, and other (hard to classify) auxiliary methods fall into the biggest class, Utility.
profile picture

tedclimo

#5
Eugene,
Can you to take another peak at Wiki Example script.
I did several historical tests & it does not appear to prevent any trades day before, nor day after EPS release.
You can see it in the following 5 recent "EPS Release Date" trades(using Wiki Example script):
QUOTE:
BWS on 8/25/10
AMAG on 8/27/10
IRF on 8/27/10
MNTA on 8/30/10
LLEN on 8/31/10

I tried enabling both nextDate & nextDate2, then tried various combinations of Bar/Bar-1/Bar+1 on both nextDate/nextDate2. All results came back the same... none of these 5 trades were prevented. Nor the 00's before them(on other symbols) in the previous year.

Is it possible that the Web-Sources we are using change the "status" of the forthcoming release date (after it actually occurs) so that it is only detectable before it happens,... but not after the fact(thus thwarting Backtesting)?

Also, you should know (not sure if it's pertinent) that same script w/o GetNextEarningsDate code takes 2 secs to backtest & produce alerts. With the GetNextEarningsDate code enabled, same script takes ~2mins45secs on same Dataset of 100 symbols(w 1 year Data Range). Assume this is b/c of reaching out to two Web-Sources during the process. If this is normal, perhaps you'll want to mention on Wiki page & save yourself future inquiries. My DSL download speed averages 6.3-6.5Mbps on any given day, so don't think internet speed is a factor.

Just tossing out ideas here.

Thanx 4 all U do,
Ted
profile picture

Eugene

#6
I fixed the Wiki mockup strategy a bit, check if this helps.

Re: previous year. Look, GetNextEarningsDate returns the single date in the future (as you requested). Period. It becomes available on a quarterly basis (and may be adjusted by the web sites - something to keep in mind), so which previous year do you mean in September?

Let's stress it: GetNextEarningsDate always returns a date in the future and is useless for backtesting.

Re: speed.

The first rule is not to put a call to Utility.GetNextEarningsDate in a loop e.g. trading loop. It's not intended to be called on each bar, this is a static variable. Even if your strategy is OK in this sense, requesting data from the server 100 times (using a single thread) takes time and will slow it down.

Be sure you have just a single call to either GetNextEarningsDate or GetNextEarningsDate2 at a time in your strategy.
profile picture

Cone

#7
Here's the full solution* that I think tedclimo is after, based on this thread's discussion.

* The only problem is detecting days after a 10-Q that has just passed. GetNextEarningsDate doesn't help us because the date is in the past, and, it's unlikely that Fundamental providers have updated their databases quickly.
CODE:
Please log in to see this code.
profile picture

tedclimo

#8
This is a massive step forward for all Dip Traders(not the underlying Dip model above, but rather your masterful filter to identify(& prevent) trading EPS release dates ). I've tried it on several dip models & it improves Stats on all of them!!!

Eugene, while Cone's "Full Solution" is the icing on the cake, your invention of "GetNextEarningsDate" is the cake. Thank you both :-)

Several observations for you both (after extensive testing) AND then one quick question.

1) I ran Robert's latest code today(Sept 6 & Mkt holiday & Mkt closed) on US stocks that YAHOO earnings calendar says will report in next two days;
a) For Sep 7(tommorrow), 63% of Alerts(EPS release dates only) were removed vs. script w/o this filter. I assume not 100%, b/c WebSource that GetNextEarningsDate uses... disagrees with YAHOO earnings calendar.... Do you concur?
b) For Sep 8(day after tommorrow), 100% of Alerts(EPS release dates only) were removed vs. script w/o this filter. Incredible!!!
c) Wiki example does not remove any Alerts(EPS release dates only) yet (for Sept 7, tommorow). Perhaps it can be tweaked to help others going forward.

2) The "Full Solution"(as Cone calls it,... appears flawless. I've done historical testing going back many months and WOW!... It also removes both "EPS Release Dates" in backtesting as well as removing Alerts currently. Conversely, one can quicly change the code to
CODE:
Please log in to see this code.

and see what happened if they did trade in the EPS TimeSpan window. Perfect.

3) Regarding speed: No action requested, just FYI,... When running script on 2000 symbols:
a) on script w/o this (EPS release Date) filter, it takes about 30secs.
b) on script with this filter, it takes about 10mins (using 32bit PC, don't have 64bit yet).
c) I assume difference... b/c script is accessing external web-source... just wanted you (& others) to be forewarned.

My only question:
1) When the Print Debug window opens showing TimeSpan as... "ts: 21, ts: 22, etc)... what is it telling me exactly?... That last EPS date was ts: x days ago??? Have not figured that one out quite yet.

Thanks again to you two Jedi,
Ted

profile picture

Eugene

#9
Let me disagree: Robert's strategy is both the cake and the icing, but thanks anyway.

Re: 3c) - That's right. Behind the scenes, Wealth-Lab is downloading the 2000 web pages for all those symbols. Processing the web requests, along with parsing the text, consumes a lot of time.
profile picture

Cone

#10
Great, I knew you'd like that ;) And I also think Eugene's method is the "cake".

Re: 63% of Alerts
It sounds like something's off by one day in the code. If you can give me a precise example or two, it would help me determine the problem.

Re: ts: 21, etc.
It's the number of calendar days until the next 10-Q. Just comment out PrintDebug("ts: " + ts.Days); It's a leftover from development.
profile picture

tedclimo

#11
Master Yoda,

Here are two sets of precise examples... both using Yahoo's earnings calendar...

BUT... Warning 1st! Model changed alerts overnight (even thought Mkts were closed for US stocks on Monday & I am still using EOD close data from last Friday - I have not updated dataset yet for today, Tuesday).

QUOTE:
//Sept 7, Yahoo Earnings Calendar Symbols (x8) are
ALOY CASY EXXI FIZZ LLEN NCS PIKE PVH
//On Monday(holiday), 5 of these 8 symbols were excluded from alerts(63%).
//This morning(Tuesday), only 1 of these symbols is excluded - yet still using last Fridays EOD data.
PIKE is only one excluded today - I did not record the 3 that were excluded yesterday


QUOTE:
//Sept 8(tomorrow, Wednesday), Yahoo Earnings Calendar Symbols(x13) are
AVAV CIEN HITK MW NAV PBY RURL SEH SFD SHFL TITN TLB UNFI
//On Monday(holiday), 13 of these 13 symbols were excluded from alerts(100%).
//This morning(Tuesday), only 12 of these 13 symbols are excluded (92%) - still using last Fridays EOD data.
PBY was excluded yesterday, but not today


Hope this helps!!!

In case you want to walk forward some more:
QUOTE:
//Sept 9(Thursday), Yahoo Earnings Calendar Symbols(x6) are
IRET KFY MVC NSM PNY SNDA
//This morning(Tuesday), SNDA is excluded (other 5 still get to trade) - still using last Fridays EOD data.

And for Friday(of this week
QUOTE:
//Sept 10(Friday), Yahoo Earnings Calendar Symbols(x2) are
BRC LULU
//This morning(Tuesday), neither are excluded (as it should be) - still using last Fridays EOD data.


I only gave you symbols that also meet liquidity filters of the script (>$5 & >50K 90day ADV) so liquidity filters would not be a factor in solving the puzzle.

All the best,
Ted
profile picture

Cone

#12
QUOTE:
PIKE is only one excluded today - I did not record the 3 that were excluded yesterday
Note that the next earnings date returned by Eugene's code is displayed in the upper left corner of the chart. It says 9/8/2010, not 9/7/2010 like Y!.

On 9/3/2010, there are 5 calendar days to the 9/8/2010 earnings date, but only 2 trading days - Friday and today. So, 9/3 is 2 bars before and 9/7 is 1 bar before, and 9/8 is the earnings date. All of these are part of the "2, 1" earnings window.

PBY GetNextEarningsDate is 1/1/0001 - so it's "undefined" today.

SNDA GetNextEarningsDate is 9/8/2010, it falls in the "2,1" earnings window for the 9/3 and 9/7 bars.

Since BRC LULU report on Friday 9/10, they fall into the "2,1" window starting on the close of the 9/8.

Conclusion:
Based on the data returned by GetNextEarningsDate, the results are correct.
profile picture

tedclimo

#13
Bro,

I never noticed Eugene's 'forthcoming date in upper left corner before'. It is a perfect troubleshooting tool ;)
Thank you for pointing it out.

Am moving this discussion to Order Ticket as it pertains to a business opportunity for MS123, but no value-added to our WL community.

All the best,
Ted
profile picture

Eugene

#14
grtrader asked:

Does the GetNextEarningsDate work for upcoming dates, or is it only for backtesting? It would be advantageous to have the next earnings date show on the charts.
profile picture

Eugene

#15
As unequivocally stated in the documentation, the method returns the next earnings date of a stock.
profile picture

richard1000

#16
I find that GetNextEarningsDate (or EarningsDate.GetNext) sometimes misses the dates. I was following a symbol PLCE as having earnings date of 03/28/2017. But instead, it reported on 03/08/2017.

I find the Fidelity website as having the best accurate earnings date. For example,

https://eresearch.fidelity.com/eresearch/evaluate/fundamentals/earnings.jhtml?symbols=AAPL

Can we scrape Fidelity's data and replace either earningswhispers.com or money.cnn.com?

Here's another idea for Fidelity customers. Fidelity ActiveTraderPro watchlist shows next Earnings Dates and Equity Summary Scores. Since Equity Summary Scores is already fundamental data provider in WL, why not also add next earnings date from Fidelity.
profile picture

Eugene

#17
QUOTE:
I find the Fidelity website as having the best accurate earnings date. For example,

Appreciate your feedback. Unfortunately, this web page does not qualify as a source. It is quite complicated from the technical standpoint. Before the page is rendered, Javascript is used to load the earnings data, and this request is a tough nut to crack: protection by tokens, usage of symbol ID instead of ticker (e.g. 037833100 vs. AAPL) etc. Not worth the trouble.

QUOTE:
Since Equity Summary Scores is already fundamental data provider in WL, why not also add next earnings date from Fidelity.

If this is an enhancement request for the Fidelity data, please submit it to your Fidelity rep. Thanks.
profile picture

richard1000

#18
I am using Earnings Date Helper and one thing I noticed from description of GetNextUseCache:

QUOTE:
It also uses the list to estimate and cache future earnings dates about 6 weeks in advance. When within 10 days of the cached date, the estimate is updated by the GetNext/GetNext2 methods. The resulting update is cached and not requested again until following the earnings release.


Clearly, in the above case, the cached date (03/28/2017) is outside the 10 day window of actual earnings date (03/08/2017). I am assuming initial cache date is a rough estimate and the actual earnings date could change. So can we increase the window of update from 10 days to a month (25 to 30 days) before cache date, or let the user have the option of choosing the window of update?