Click here to Login




How to create a trading system, screen and composite using earnings surprise data

Updated on 2012-09-26







Earnings data such as quarterly earnings per share (EPS), earnings surprise and previous earnings numbers can be collected and used in QuantShare to create screens, trading systems and even composites. In this post, I will show you how to download this data (historical) for all stocks (U.S. and International) and use it in the QuantShare language to create screens, trading systems and composites.


Earnings Data

If you search "Earnings Data" in the QuantShare sharing server, you will get many responses. The following download item interest us particularly:
Historical Earnings Surprise, EPS and Consensus Data.

This item retrieves historical earnings data, including the reported EPS (earnings per share), consensus EPS and surprise (Percentage difference between the consensus and actual EPS values). The data is stored in a custom database "earnings_cal".

To run the above downloader:
- Select "Download -> Download Manager"
- Select "Historical Earnings Surprise"
- Click on "Open Selected Downloader"
- Select a start and end dates
- Click on "Start Downloading"

In the rest of the article, I will show you how to access this data and use it in a screen, trading system and composite.


QuantShare Language

The QS language is the main programming language used in QuantShare.
To reference a custom database field, we simply use the "GetData" function.

Syntax:
a = GetData("Database Name", "Field Name");

It is like referencing a price series or an indicator. The data returned by "GetData" function is already synchronized with security data. This means that for each trading bar, you will get the field data that occurred during this bar. If many field entries occurred during one trading bar then you will get the last one. Note that you can create custom functions to handle this particular case where many values are available for the same bar (Tools -> Create Functions -> use "cFunctions.GetCustomDatabaseData").

Back to the earnings data database we have populated previously, we can reference this data by typing:
a = GetData("earnings_cal", "surprise");

Note that this earnings database has three fields: EPS, consensus and surprise.

To display database content:
- Select "Data -> Edit Databases"
- In the "Databases" tab, select "Custom" then "earnings_cal"


Screen

In this screen, you will search for stocks that had a positive earnings surprise during the last 5 trading days. As we saw previously, we can reference earnings data by calling the following function:

a = GetData("earnings_cal", "surprise", Zero);

With "Zero" as last parameter, we instruct QS trading software to set zero on bars where no "surprise" entries were found. Otherwise, the last surprise value will be used in subsequent bars. This is particularly useful in many cases such as when referencing fundamental numbers and ratios.

To create a new screen, select "Analysis -> Screener -> Create a new screen".
Type the following formula:

a = GetData("earnings_cal", "surprise", Zero) > 0;
filter = hhv(a, 5); // Positive surprise in the last 5 trading bars using the "hhv" function (highest value of the N-past bars)



Trading System

The trading system we are going to implement contains the following rules:

Buy:
- Enter a new position when the earnings surprise is higher than 5%
- Enter a new position when the five trading days following the previous earnings surprise (must be positive) were profitable

Sell:
- Exit any position after five trading days

To create a new trading system, select "Analysis -> Simulator -> New".

Here is the trading formula with a brief explanation of each instruction:

// Get today earning surprise
surprise = GetData("earnings_cal", "surprise", Zero);
// Earnings surprise higher than 5%
rule1 = surprise > 5;

// Get the number of surprise entries per bar
ct = GetDataCount("earnings_cal", "surprise");
// Get the number of bars since the previous earnings release. "Ref" function references a previous value of an array
bars1 = BarsSince(ref(ct, 1));
// Get the value of the previous earnings surprise
prev = ref(surprise, bars1+1);
// Get the 5-bar return precedding the previous earnings surprise
ret = ref(perf(close, 5), bars1+1-5);
rule2 = prev > 0 and ret > 0;

buy = rule1 and rule2;


For the sell rule, just add a 5-bar N-Bar Stop

Note 1: The above trading system is already available in the sharing server. You can download it here: Earnings Surprise Strategy
Note 2: If you find it difficult to understand the above formula, I suggest you plot each variable on a chart to see how it works.

For example, create a new chart's pane, right click on it and select "Edit Formula".
Type the following formula then click on "Update Graph":

ct = GetDataCount("earnings_cal", "surprise");
Plot(ct, "Earnings surprise");


After that, add the following lines:
ct = GetDataCount("earnings_cal", "surprise");
plot(ct, "Count", colorGreen);


And so on…


Composite

A composite based on earnings data is something you seldom see. The idea here is to create a market indicator that can measure market strength by calculating the difference between the number of stocks with positive earnings surprise and the number of stocks with negative earnings surprise.

To create a new earnings surprise based composite, select "Tools -> Composite -> Add" then add the following formula:

surprise = GetData("earnings_cal", "surprise", Zero); // Get today earning surprise
composite = iff(surprise > 0, 1, -1);


Settings: Calculate the average of the values added to the composite


Note that the same techniques described above can be used with any other sentimental or fundamental data.

This post for example shows you how to use "GetData" and other functions to reference tweets data in your charts and trading systems. This one shows you how to get and use economic calendar data for several currency pairs (Forex).












no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1449 days ago

Profile Graphs
Posted 1554 days ago

QuantShare
Previous Posts

More Posts

Back







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.