I have an intra-day system that needs to trade the morning after earning release.
How do i lookup the earning date in the earning_cal custom database (string format) and compare to the date of current bar?
Below is my attempted code, but please advise code, especially the post_earning line ..
// system that trades on post-earning morning..
earning_time = GetDataString('earnings_cal', 'etime', '');
earning_date = GetDataString('earnings_cal','Date', '');
after_close = "After Market Close";
before_open = "Before Market Open";
Thanks for that .. I'm trying to distinguish between Before Market and After Market Announcements (i.e. Buy at Open Today for BMO, Buy at Open Tomorrow for AMC in this simple system below) and running into 2 issues..
1) For Daily systems, the AMC scenario works ok, but the Before Market trades are not opened Today - they're opened the next day just like AMC. Is there something wrong in my SetSimTiming statement?
2) For Intraday systems (e.g. 5minute, no outside market-hours), all Buy orders execute at the next intraday bar (i.e. at 9:35am). How do i modify this script, so it executes trades the same day for BMO and the next day for AMC?
The "SetSimTiming" accepts only fixed numbers. Also, buying at the open the signal bar doesn't make sense. There is a big look-ahead bias here.
Instead of updating "SetSimTiming", you should update your "buy" rule.
It it is for testing purposes and you don't mind the look-ahead bias then you can do something like:
I used the following code for an intraday system. However, the "earning_day" evaluates to True only on the first bar of the Earnings day (ie. 9:30am NY time). This breaks my Buy logic because I need to add other Buy conditions that happen later in the day so the Buy order executes later in the day (e.g. at 3rd bar).
- How do i make "earning_day" evaluate to True for all intraday bars on Earnings day?
earning_dayA = stringequal(earnings_var,after_close);
earning_dayB = stringequal(earnings_var,before_open);
earning_day = earning_dayA[79] or earning_dayB; // buy at next 5-minute bar after earning
One other quick one - Noticed that several etime fields are "8:30am" or some other character string.
How do i specify non-NULL, non-"After Market Close" wildcard in the strategy script? - Something like ...
earnings_var = GetDataString('earnings_cal', 'etime', '');
earning_dayB = stringequal(earnings_var,"regex-like pattern that is not NULL and not "After Market Close");
I'm trying to find the average 1-day price return (i.e. close/ref(close,1)-1) on Earnings Announcements day for the last 8 announcements (2 years) by using the earnings_cal database, and having 2 challenges
1) I'm trying to get an eDate series (with 1 on Earnings dates, 0 on other dates) - however, several eTime fields are blank on earnings dates in the database (see AAPL for example) and i can't use it, so i tried using consensus and Date fields but the logic below doesn't pick these up - i tried regex in the stringequal but that doesn't work either.
2) Once i get eDate, i calculate average daily return in last 8 announcements as ..
dr = close/ref(close,1)-1;
eaRtn = avgif(eDate, dr);
However, avgif has no lookback period and calculates over entire eDate history.
How do i set historic eDate (before 2 years) to 0, so avgif will only calculate over a lookback of 2 years?
1) date() doesn't help, as it just returns the date of current bar. I need a series (eDate) that returns 1 on Earning date (in the earning_cal database) and 0 on other dates. How do i construct this series? I've tried various approaches in the thread above but they dont work.
2) avgif() gives a syntax error if we pass the third argument of lookback. It has only 2 parameters and none for lookback.
- One workaround is to mask eDate to 0 for all bars before 252*2 and then use it below as shown. However, not sure how to mask a series before a lookback.
- If this isn't possible, is there some other way of getting avgif over a lookback of 500 bars?
Sorry, I got (2) working .. the only issue is (1) -
1) date() doesn't help, as it just returns the date of current bar. I need a series (eDate) that returns 1 on Earning date (in the earning_cal database) and 0 on other dates. How do i construct this series? I've tried various approaches in the thread above but they dont work. As you can see the database sample below, some e_time entries are blank and the others (consensus, eps, surprise) are double/float (so can't use GetDataString), so couldn't figure out the code to capture all EA dates.
Date surprise eps consensus e_time
7/26/2016 0:00 NaN NaN NaN After Market Close
4/26/2016 0:00 NaN NaN NaN After Market Close
1/26/2016 0:00 NaN NaN NaN After Market Close
10/27/2015 0:00 NaN NaN NaN After Market Close
7/21/2015 0:00 NaN NaN NaN After Market Close
4/27/2015 0:00 NaN NaN NaN After Market Close
1/27/2015 0:00 NaN NaN NaN After Market Close
10/20/2014 0:00 NaN NaN NaN After Market Close
7/22/2014 0:00 NaN NaN NaN After Market Close
4/23/2014 0:00 NaN NaN NaN 4:30 pm ET
1/27/2014 0:00 NaN NaN NaN After Market Close
10/28/2013 0:00 3.77 8.26 7.96
7/23/2013 0:00 NaN NaN NaN After Market Close
4/23/2013 0:00 NaN NaN NaN After Market Close
1/23/2013 0:00 NaN NaN NaN After Market Close
10/25/2012 0:00 NaN NaN NaN After Market Close
7/24/2012 0:00 -10.13 9.32 10.37
4/24/2012 0:00 22.51 12.3 10.04
1/24/2012 0:00 NaN NaN NaN After Market Close
10/18/2011 0:00 -4.6 7.05 7.39
7/19/2011 0:00 NaN NaN NaN After Market Close
4/20/2011 0:00 NaN NaN NaN After Market Close
1/18/2011 0:00 NaN NaN NaN Time Not Supplied
10/18/2010 0:00 NaN NaN NaN After Market Close
7/20/2010 0:00 NaN NaN NaN After Market Close
4/20/2010 0:00 35.92 3.33 2.45
1/25/2010 0:00 NaN NaN NaN After Market Close
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.