Click here to Login





                                                   Lookup Earnings Announcement date and trade on post-earnings day

  0

0
Kiran
2015-05-04 13:03:34


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";

post_earning = <earning_date == <yesterday's date> && stringequal(earning_time,after_close)) || <earning_date == <today's date> && stringequal(earning_time,before_open));
buy = post_earning;

//Read more: http://www.quantshare.com/title-984-how-can-i-incorporate-earnings-release-data-into-my-backtests-scripts&kbaseid=forum-984-5741-2829#ixzz3ZBiwaP6q



QuantShare
2015-05-05 02:38:24

  0

When you request data from a custom database then the custom database data is automatically aligned with quotes data.

Example:

a = GetDataCount("earnings_cal", "etime");

// Variable "a" will be different than 0 on earning date.



Kiran
2015-05-05 14:19:00

  0

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?


// simple Earnings day script
earnings_var = GetDataString('earnings_cal', 'etime', '');
after_close = "After Market Close";
before_open = "Before Market Open";

earning_day = stringequal(earnings_var,after_close) || stringequal(earnings_var,before_open);
buyToday = iff(stringequal(earnings_var,before_open),-1,0);
SetSimTiming(_Buy, _Open, buyToday);
buy = earning_day;



QuantShare
2015-05-06 03:36:17

  0

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:

earning_day = stringequal(earnings_var,after_close);
earning_day1 = stringequal(earnings_var,before_open);
buy = earning_day or earning_day1[-1];




Kiran
2015-05-06 23:04:39

  0

Thanks,

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?

//System that buys upon Earning announcement ..
earnings_var = GetDataString('earnings_cal', 'etime', '');
after_close = "After Market Close";
before_open = "Before Market Open";

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

buy = earning_day && cross(close, FirstMinutesHL(10));



QuantShare
2015-05-07 04:50:48

  0

You could use the "lswitch" function.

Example:
a = lswitch(earning_day, day() != ref(day(), 1));

Plot that on a chart to see how it works.



Kiran
2015-05-07 19:40:18

  0

Thanks,

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");



QuantShare
2015-05-08 05:23:22

  0

You can specify your filter (regex) in the third parameter of the "GetDataString" function.


Kiran
2016-09-15 17:18:45

  0

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.

e_time = GetDataString('earnings_cal', 'etime', '');
consensus = GetDataString('earning_cal', 'consensus','');
e_date = GetDataString('earnings_cal', 'Date', '');
eDate = stringequal(consensus,"");
eDate = stringequal(e_time,'.+');
eDate = stringequal(consensus,"/(\d\w\.)+");
Plot(eDate, "Earnings date");


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?






QuantShare
2016-09-16 09:52:57

  0

1/ Custom database is adjusted to security price series, so to get the date, just use date()

2/ "avgif" does have a lookback period
To calculate average over the last 2 years:

a = getdata("database", "field", Zero);
dr = close/ref(close,1)-1;
eaRtn = avgif(a != 0, dr, 252*2);





Kiran
2016-09-16 16:41:35

  0

The answers didn't help

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?


eaRtn = avgif(eDate!=0, dr, 252*2);



Kiran
2016-09-16 17:30:38

  0

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




QuantShare
2016-09-18 19:26:03

  0

1/ Try this:

a = getdata("database", "field", Zero) > 0;



Seeker
2023-10-26 22:22:34

  0

Can we use AvgIf with multiple conditions?


QuantShare
2023-12-19 01:35:39

  0

Yes, you can.

Example:
a = avgif(a != 0 and b != 0 and c!= 0, 1, 0);



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
Earnings after and before market opens
Day of week and Week number function
Historical Earnings Calendar Data for U.S. Stocks - Date/Time and...
S&P 500 Earnings and Price Earnings Ratio Estimations
iShares ETFs - Class, Total Net Assets, Inception Date and Number...

How-to Lessons
How to download and use U.S. stocks earnings data
How to create and trade a Neural Network model
How to download earnings calendar data for various stocks
How to plot support and resistance lines automatically
How to plot the number of stock tweets per day

Related Forum Threads
Previous day high and low in in intraday chart
Sales Surprise and Earnings surprise data?
Visible Date of first and last bar on chart
Day Trade Option Strategy (buy/sell calls only)
How to read date and get quote of next day.

Blog Posts
Day Trading: A trading system that combines intraday and EOD data
How to predict and trade the stock market using pivot points
3 Items To Get and Trade the News In QuantShare Platform
How to create a trading system, screen and composite using earnin...
How To Create and Backtest an S&P 500 Trend Following System









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.