Data Library

Trading Economics

Trading Economics

Updated August 28th, 2019: This data source is only supported in backtesting

Introduction

QuantConnect provides Trading Economics calendar and indicator data for use in your algorithms. Trading Economics is a provider of economic event announcements and economic report data. An example use of the data is using it to factor in interest rate changes or unemployment report announcements to rebalance your portfolio.

QuantConnect hosts Trading Economics data dating back to around 2013 for various countries.

To subscribe to Trading Economics data, use the AddData method with the data source you'd like information about.

Valid values for the type parameter in AddData are:

  • TradingEconomicsCalendar
  • TradingEconomicsIndicator

Here's an example on adding TradingEconomicsCalendar data to your algorithm:

// Adding TradingEconomicsCalendar interest rate data to the algorithm
AddData<TradingEconomicsCalendar>(TradingEconomics.Calendar.UnitedStates.InterestRate);
        
# Adding TradingEconomicsCalendar interest rate data to the algorithm
self.AddData(TradingEconomicsCalendar, TradingEconomics.Calendar.UnitedStates.InterestRate);
        
Note: Due to the nature of this data, you'll have to add the data sources manually in order to use the data.

Handling Data

We recommend that you store the Symbol object that is accessible from the Security type returned from the AddData call. Reasons for doing so are:

  1. You can reference the custom data symbol directly for use in other methods
  2. It makes accessing data from Slice easier
  3. Allows you to remove the custom data subscription later if you're not using it anymore
Note: special care must be taken with adding TradingEconomics data. The AddData method currently assumes that the data timezone (i.e. the timezone the data is stored in) is America/New_York. We need to make sure that we use UTC because the data is stored in UTC.

In order to store your custom data symbol, you can do the following:

// Storing a symbol object to a List<Symbol> defined as a class member variable
public class TradingEconomicsCalendarAlgorithm : QCAlgorithm 
{
    // Can be private or public
    private List<Symbol> _customDataSymbols = new List<Symbol>();

    public void Initialize() 
    {
        var calendars = new List<string> 
        {
            TradingEconomics.Calendar.UnitedStates.InterestRate,
            // ...
        };

        foreach (var calendar in calendars) 
        {
            var tickerSymbol = AddData<TradingEconomicsCalendar>(calendar, Resolution.Daily, TimeZones.Utc).Symbol;
            _customDataSymbols.Add(tickerSymbol);
        }
    }

    public void OnData(Slice slice) 
    {
        // ...
    }
}
        
# Storing a symbol object to a list defined as a class member variable
class TradingEconomicsCalendarAlgorithm(QCAlgorithm):
    def Initialize():
        calendars = [TradingEconomics.Calendar.UnitedStates.InterestRate]

        self.customDataSymbols = [self.AddData(TradingEconomicsCalendar, calendar, Resolution.Daily, TimeZones.Utc).Symbol for calendar in calendars]

    def OnData(slice):
        # ...
        pass
        

After you've stored your symbol object, you can access data from the Slice object using the stored symbol object, similar to how you would load equity data. Please see the Handling Data documentation section for more information on how to access your data using a symbol object.

Data Shape and Properties

Trading Economics data is stored as a flat, single-line JSON file on disk. Data can be accessed using either one of the types using AddData:

You can see the available fields for both Calendar and Indicator data by clicking the type name in the list above.

Trading Economics data is separated into two distinct categories: Calendar, and Indicator. The calendar category contains the announcements and results of economic events, whereas Indicators only contain the most recent value parsable as a decimal. An example of Calendar data is U.S. fed interest rate announcements. Calendar data will contain the announced actual value, the predicted value (by Wall St. and Trading Economics), and the previous value. Indicator data is similar to calendar data, but contains numeric values instead of hard to parse values.

Accessible ticker values for Calendar and Indicator data for AddData can be seen on GitHub

Because calendar data sometimes has unclean values for the fields: "Actual", "Previous", "Forecast", "TEForecast", you'll have to clean the string and then parse as decimal/float. To do this, we recommend doing the following:

var inBillions = calendarData.Forecast.Contains("B");
var inMillions = calendarData.Forecast.Contains("M");

var formattedForecast = calendarData.Forecast.Replace("%", "").Replace("$", "");
var forecast = 0;

if (inBillions) 
{
    forecast = Convert.ToDeicmal(formattedForecast.Replace("B", ""), CultureInfo.InvariantCulture) * 1000000000;
}
else if (inMillions) 
{
    forecast = Convert.ToDecimal(formattedForecast.Replace("M", ""), CultureInfo.InvariantCulture) * 1000000;
}
else 
{
    forecast = Convert.ToDecimal(formattedForecast, CultureInfo.InvariantCulture);
}
        
inBillions = "B" in calendarData.Forecast
inMillions = "M" in calendarData.Forecast

if inBillions:
    forecast = float(calendarData.Forecast.replace("%", "").replace("B", "").replace("$", ""))
    forecast = forecast * 1000000000
elif inMillions
    forecast = float(calendarData.Forecast.replace("%", "").replace("M", "").replace("$", ""))
    forecast = forecast * 1000000
else:
    forecast = float(calendarData.Forecast.replace("%", "").replace("$", ""))
        

About the Provider


Trading Economics provides indicator, calendar, government bonds, equities, and commodity data for 196 countries. Data is sourced from official, non-third party sources. They provide more than 20 million indicators, which are manually checked for any errors and inconsistencies. You can find out more about Trading Economics at https://tradingeconomics.com/about-te.aspx

You can also see our Tutorials and Videos. You can also get in touch with us via Chat.

Did you find this page Helpful ?