Click here to Login

Charting, Backtesting and Trading using Fundamental Data

Updated on 2013-09-12

Want to chart and trade based on fundamental ratios and measures?

Sure you can do that with QuantShare. As you may know QuantShare is a powerful analysis tool where you can do anything from displaying, analyzing, ranking, comparing… any kind of data. But you may also know that QuantShare doesn’t provide data. Hopefully, we have several downloaders that you can use in our sharing server. One of these downloaders lets you retrieve historical data of several fundamental measures from Morningstar.

Getting Historical Fundamental Data

I will show you how to get yearly fundamental data by using the following item: Morningstar Historical Fundamentals.
This item gets 10 years of yearly data for 80 fundamental items/ratios.

- Open the follow URL: Morningstar Historical Fundamentals
- Click on "Download" then follow instructions to get the downloader
- In QuantShare, select "Download -> Download Manager"
- Select "Morningstar Historical Fundamentals"
- Click on "Open Selected Downloader"
- You can choose for which stocks you would like to download fundamental data by adding conditions in the "Symbols" tab
- Click on "Start Downloading"

In this process, QuantShare will get fundamental data from different URLs generated by the downloader. It will parse the data and insert it in a custom database.

Checking Fundamental Data

Let us look at the fundamental data we have just downloaded.

- Select "Data" then "Edit Databases"
- Next to "Choose Database", select "Custom"
- Next to "Choose a custom database", select "morningstar_fundamentals"
- Select a symbol in "Symbols" panel to see fundamental data in the right panel

Note that " morningstar_fundamentals" is the database created by our downloader.

Charting fundamental data

What if we want to display changes of revenues on a chart?

Here is how to do that:
- Open a new chart
- Right click on it then select "Create new pane"

There are two ways to add the revenues on this pane. You can either use the wizard or type the formula directly for that pane.

Solution 1:
- Click on the first icon located in the top/left corner of the pane
- Select "Databases/Fields"
- Select "morningstar_fundamentals" database then "revenue_usd_mil" field
- Click on "OK"

Solution 2:
- Right click on the pane then select "Edit Formula"
- Type the following formula then click on "Update Graph"

a = GetData('morningstar_fundamentals', 'revenue_usd_mil', LastData);
Plot(a, "Revenues", colorBlack, chartLine, StyleSymbolNone);

The "GetData" function allows you to retrieve data from a custom database. "LastData" option instructs QuantShare to use the last available value if no value is available for the current bar/date.
"Plot" instructs QuantShare to plot a variable on the chart.

Example of a chart plotting ROA (Return on asset):

Backtesting a Fundamental-based Trading System

Let us create a trading system now.

- Select "Analysis -> Simulator"
- Click on "New" to create a trading system

Since you already know how to get fundamental data using QuantShare programming language, let us use the formula editor.

- Select "Create trading system using the formula editor"
- Type the following formula:

a = GetData('morningstar_fundamentals', 'gross_margin_pct');
buy = a > 50;
sell = a < 50;

// This simple trading system enters long when a stock’s gross margin (percentage) is higher than 50. It exits the position when the gross margin of the stock becomes lower than 50%.

To backtest your trading system, select it in the Simulator Manager then click on "Simulate / Backtest" button.

Note: You can automatically get the available databases and fields in your account by using the CONTROL+SPACE shortcut.


After you type a = GetData(", use CONTROL+SPACE to get available databases.
After you type a = GetData('morningstar_fundamentals', use CONTROL+SPACE to get available fields in your fundamentals database.

Here are some more articles that may interest you:

How to Download and Use Fundamental Data
How to Quickly Create Fundamental Scans
Fundamental Stock Analysis: Rank stocks based on a valuation ratio
Fundamental Screen based on Stock price, ROI and Market capitalization
3 Market Indicators based on Fundamental Data

no comments (Log in)

QuantShare Blog
Search Posts

Recent Posts

Create Graphs using the Grid Tool
Posted 1272 days ago

Profile Graphs
Posted 1377 days ago

Previous Posts

More Posts


Create an account
Affiliate Program
Contact Us
Trading Forum
How-to Lessons
About Us
Terms of Use

Copyright © 2024
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
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.