Avoiding Earnings Period
Author: wmrgrove
Creation Date: 5/6/2018 10:38 PM
profile picture

wmrgrove

#1
Looking for a little help with my strategy. What I want to accomplish is to NOT TRADE during a period around earnings dates. To define an optimal "window" I want to back-test my pairs history for say 2 years.
A limitation is that I can’t do this for External Symbols in the pairs. That's ok as just testing the "primary" symbol will give me insight into this trading window.

I have found on WIKI , using Community.Components; code that will execute "true" when there is an earning period. What I want to do is NOT Trade in an earnings window and back-test for "NOT X periods before and NOT X periods after the earnings date " ( using Fidelity Fund. Data).

The strategy below uses 2 methods, but both are true when an earnings window is present. Any help to change the code would be much appreciated!

if (EarningsDate.InWindow(this, bar, "earnings per share", 2, 2)) appears to be the best method?

CODE:
Please log in to see this code.

profile picture

Eugene

#2
You're pretty close. An example code can be found in post #3 of this thread: Avoiding earnings release dates? (surprise). That should suffice for backtesting.

Don't forget to adjust the trading loop accordingly (here 3 bars before and 3 after):
CODE:
Please log in to see this code.

Or you get a runtime error.

Also, I don't get the point with delaying the FundamentalItem one bar:
CODE:
Please log in to see this code.
profile picture

wmrgrove

#3
Eugene, thanks for the help.

You said; "An example code can be found in post #3 of this thread: Avoiding earnings release dates? (surprise). That should suffice for backtesting."

I probably missed something simple here as I get this error;

Operator "-" can not be applied to operands of type 'System.DateTime' and 'int' and
Operator "+" can not be applied to operands of type 'System.DateTime' and 'int'

basic test code here;

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

Eugene

#4
William, that's because it's pseudocode. Don't just copy and paste it but study proper .NET syntax for comparison of dates: Compare two DATE and get Days in c#. It's just an example but there are many more in various Strategies and forum discussions (and much more external examples on the internet). I see your posts with coding attempts going back to 2012. This subject is C# 101 so it should not present any trouble to you. Good luck.
profile picture

Cone

#5
Why did you abandon the InWindow() method? This code should get you started on the right foot. I think you want to detect the window edges... so this code creates a synchronized boolean array for InWindow(). Then you can test if it's false on the previous bar and true on the current bar and vice-versa to detect the edges... And, as you can see, you can do that with the secondary symbol too.

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

wmrgrove

#6
Cone, thank you for the detailed reply. This helps a lot as I did not think you could test the External Symbol for Earnings Window!

The common thinking in Pairs Trading is to always stay away from the "Earnings Window". Of course volatility at that time often spikes and the resulting move can be a 50/50 call. My initial testing, on both the in-sample and out-of-sample is the trade entered before the earnings date is better than average and the trade entered shortly after the earnings date is below average. ( not what one would think) Earnings creates lot's of additional pairs trades but they can be suspect, due to announcements on earnings day, creating a new "Trend Direction" for the affected pair symbol.

I have been using the, " InWindow() method" the last few days back-testing my Pairs Strategy! I am just now starting to get enough "Out of sample" data to truly test my strategy. The pairs selection used 2 years of data ending 1-30-18 and the "Pairs Alert Trading strategy uses,
private static Dictionary<string,string> stock2externalIndex = new Dictionary<string,string>(); Thanks to contributor SuperTrader on this forum I am able to run over 200 selected pairs daily ( from a set list) in about 3 seconds ( Symbol Tab visualizer not active ) !

Thanks again for your help.

profile picture

wmrgrove

#7
Cone; a question on the code above, please.

I am trying to get this to function on my Pairs Strategy ( earnings for both primary and external symbol ) using

CODE:
Please log in to see this code.


If you have a moment could you take a peak at the attached code? I am trying to replace a single "External" symbol with the string example above. For example selecting "A" in a pairs list will have it compare to "PRAH" directly. ( a few hundred pairs in the actual strategy code)

CODE:
Please log in to see this code.


Thanks for any help!
profile picture

wmrgrove

#8
Cone, any chance to get a little help on my question above ( Post#7 )?
profile picture

Cone

#9
Apologies. I really didn't see post #7 until now. If you're waiting for me specifically and I haven't answered in 2 days, feel free to ping me like you just did ;)

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

wmrgrove

#10
Cone, thanks so much, this really helps! Waited a week or so as I'm sure your busy! :)
profile picture

Eugene

#11
UPDATE 09/02/2020

"earnings per share" no longer works (Fidelity data). Replacement:

Zacks Adjusted Earnings (EPS) provider
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).