Plot fundamental dates ahead of announcement?
Author: gbullr
Creation Date: 10/21/2011 11:07 AM
profile picture

gbullr

#1
Is there a way to plot fundamental dates on a graph? meaning does the data appear before the announcement?

So in this case
CODE:
Please log in to see this code.


I am interested in knowing when the earnings will be released ahead of time.

Thanks.

profile picture

Cone

#2
QUOTE:
I am interested in knowing when the earnings will be released ahead of time.
You can't plot something on a future bar that does not exist, but you can highlight the current bar or write a message on the chart.

Check out the Earnings Date Helper
profile picture

gbullr

#3
Thanks.

I will look into this. Basically I am trying to see if there is any predictability to trading around earnings dates and for that I need to know what the earnings dates are/were. This
CODE:
Please log in to see this code.


just gives me the next one. Is there a way to get of historical dates marked on a graph. Thanks.


profile picture

Cone

#4
QUOTE:
just gives me the next one.
Well, that's wrong.

QUOTE:
Is there a way to get of historical dates marked on a graph.
Look more closely? Hint: look at all those red highlights, which you shoud see if 1) you don't use a red chart background, and 2) you have the fundamental data required by the script.
profile picture

gbullr

#5
Obviously. I don't know what the heck I am doing but this is what I am trying to do. Buy 10 Days before the earnings announcement and sell the day after the announcement. What I have posted appears to buy every 10 days w/ no reference to the earnings date whatsoever. Is that because the code to bring in the earnings date only brings in the "latest" earnings date rather than bringing them in cronologically?

Thanks.



CODE:
Please log in to see this code.


profile picture

Eugene

#6
Why aren't you using the EarningsDate.InWindow method? Its usage is highlighted in the code example.

Something like this (fragment):
CODE:
Please log in to see this code.
profile picture

gbullr

#7
Principally because I want to buy x dates before the earnings date.

The real question that I have is how to buy x days before prior earnings dates.

lets say that stock xyz has fundamental data from q4 2005 and I want to run the backtest of buying x days before every earnings date.


So buy x days before q1 06 earnings date, x days before q2 06 earnings date .... x days before upcoming earnings date. How would I do that?

Thanks.

profile picture

Cone

#8
CODE:
Please log in to see this code.
We'll keep repeating it: Use the Earnings.InWindow method.

.InWindow gives you the option to indicate the number of days prior and/or after an earnings event. If bar is "in the window" that you specified, the function returns true. That's your trigger to do something.
profile picture

gbullr

#9
I have been looking at this and the code that I have written does not reflect what I want to do and the help provided gets me no closer.


Lets take IBM as an example.

The earnings announcement dates have been:

10/19/12
7/19/12
4/19/12
1/19/12
10/17/11
7/18/11
4/19/11
1/18/11

etc.

As I run the backtest I want the program to buy 10 days before each of these dates. Presumably I have incorporated these dates with the

CODE:
Please log in to see this code.
line.

The inwindow method does not cause the backtest to buy at prior earnings announcement just at the next earnings date where there happens to be an earnings date in the window.

CODE:
Please log in to see this code.



for example at Bar 1 there is an earnings announcement that is upcoming, I want to buy x days before that. After that has passed there is another earnings date and so on until we get to the present.


I want to buy 10 days before every earnings announcement date the Co. has ever had and cover a day after the announcement.

profile picture

Cone

#10
When I run your code, it buys 9 days before the announcement (because you detect the 10th day, but then you're buying on bar + 1). However, you're using a terribly erroneous rule to sell at bar + 11. This is a perfect example of why you should NEVER do that. Use bar + 1, always. Your bar + 11 rule causes the LastPosition to be exited logically, which in turn puts you back in the "window" for the entry logic, which buys again.. this process repeats 5 times.

Replace the loop section of your code with this. It buys 10 days before earnings and sells 1 day later. You'll get an Alert to buy MSFT today for its scheduled earnings on the 19th.

CODE:
Please log in to see this code.
profile picture

gbullr

#11
I don't know how to explain this to you. I want to buy EVERY single time there HAS been an earnings announcement not just the next earnings announcement.


Imagine someone asked you what would have happened if you had bought MSFT 10 days before EVERY earnings announcement it has had.

Thanks.

profile picture

Cone

#12
It does buy every single time there has been an earnings announcement... keep in mind that Fidelity Fundamental data are available for only the last 24 quarters.

Here's your script with my edit. Tell me what you see that's wrong here - and note that the script bought on Jan 4, just like I said it would before the market opened that day.

profile picture

gbullr

#13
Maybe I am retarded .

CODE:
Please log in to see this code.


I don't know how to post a chart on here but my chart has no trades triggered. It is a normal MSFT chart that in addition says Next Earnings: 4/19/2012


The fundamental data I am download is: Fidelity Estimated Earnings Data for Securities.
Is there something else I need to be downloading?



profile picture

Cone

#14
QUOTE:
Is there something else I need to be downloading?
Yes. You need Fidelity Fundamental Data for Securities

Estimated Earnings are all dated with the last day of calendar quarters, and, they can be/are updated many times before that date. imho, Estimated Earnings has almost no place for backtesting, unless you ignore them until the end of the past quarter.. and if you're going to do that you might as well just use the more-timely actual earnings data and not an estimate!
profile picture

gbullr

#15
Thank you once again.

profile picture

gbullr

#16
I have changed the code and I have instances where the trade occurs after the earnings date. Is there a problem w/ my data?

CODE:
Please log in to see this code.


This should trade two days before the announcement no?

How do I post a screenshot like you did above?

profile picture

Eugene

#17
To post an image, upload it first to any free image hoster (tinypic.com, imageshack.us, imagebam.com - to name a few). Then:

* either retrieve the direct link to the full-size image and paste the link right between a pair of IMG tags (you should see a pane with "...LINK, QUOTE, CODE, IMG" buttons when adding a new post),
* or use a code snippet "for posting on the forums" (usually, every image hoster provides it).
profile picture

gbullr

#18


If you look the trade occurs after the E date. Am I doing something wrong?

CODE:
Please log in to see this code.
profile picture

gbullr

#19
Also.

Any reason why this code would give me Runtime error Object reference not set to instance of an object at WealthLab.Srategies.EarningsGap.Execute()

Code is from strat downloads. Since I don't understand inwindows too well I am trying to go basic.

CODE:
Please log in to see this code.


Thanks

profile picture

Cone

#20
Regarding the first 3/29 post, if (EarningsDate.InWindow(this, bar, "earnings per share", 2, 0) returns true on bar and you ShortAtMarket on bar+1. If the other conditions had been true 2 days earlier (like EarningsDate.InWindow was), then you would have shorted earlier.

The object error occurs when fi is null.. if you're looking back too far before earnings are available, for example.
profile picture

gbullr

#21
So I inserted this line && fi.Date.AddDays(-2) == Date[bar] to try to make sure it only tests for the other conditions before the earnings announcement but it does not work. I am sure you know why but I don't; probably because fi.Date.AddDays(-2) does not work... but what can I put in there that does.

Thanks.



CODE:
Please log in to see this code.



profile picture

Cone

#22
You cannot use an object's methods if it is null.
CODE:
Please log in to see this code.
profile picture

gbullr

#23
tried this

CODE:
Please log in to see this code.


and this

CODE:
Please log in to see this code.


and neither worked. Compiles but generates no trades while if I // this line && fi.Date.AddDays(-2) == Date[bar] it generates trades w/ the aforementioned problem of generating trades AFTER the earnings release.

profile picture

Cone

#24
CODE:
Please log in to see this code.
This condition will never be true. It's a logic error. The fundamental item always refers to the an event that occurred on the current bar or in the past. If you subtract 2 days from something in the past and compare it to the current date, it's always false.

What is the condition, precisely, that you are trying to code?
profile picture

gbullr

#25


I think I figured it out! OMG could it be? You set Days Before to = negative Days After!!!

so if( EarningsDate.InWindow(this, bar, "earnings per share", 2, 0) becomes if( EarningsDate.InWindow(this, bar, "earnings per share", 2, -2) to test for other conditions prior to earnings.

it does what I wanted it to do! Wow was that painful. Thank you for your help.

wawawiwaa!!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).