EOD Historical Data
Economic Events
Introduction
The Economic Events dataset, provided by EODHD, offers daily alerts for major economic events or announcements of global markets within the upcoming 7 days, with estimation and previous record if available. The data starts in January 2019, and is delivered on a daily frequency.
For more information about the Economic Events dataset, including CLI commands and pricing, see the dataset listing.
Getting Started
The following snippet demonstrates how to request data from the Economic Events dataset:
self.add_data(EODHDEconomicEvents, Country.UNITED_STATES) self.add_data(EODHDEconomicEvents, EODHD.Events.UnitedStates.CPI)
AddData<EODHDEconomicEvents>(Country.UnitedStates); AddData<EODHDEconomicEvents>(EODHD.Events.UnitedStates.Cpi);
Requesting Data
To add Economic Events data to your algorithm, call the AddData<EODHDUpcomingIPOs>
add_data
method.
class EconomicEventsDataAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2019, 1, 1) self.set_end_date(2020, 6, 1) self.set_cash(100000) ticker = EODHD.Events.UnitedStates.CPI # ticker = Country.UNITED_STATES self.dataset_symbol = self.add_data(EODHDEconomicEvents, ticker).symbol
public class EconomicEventsDataAlgorithm : QCAlgorithm { private Symbol _datasetSymbol; public override void Initialize() { SetStartDate(2019, 1, 1); SetEndDate(2020, 6, 1); SetCash(100000); var ticker = EODHD.Events.UnitedStates.Cpi; // var ticker = Country.UnitedStates; _datasetSymbol = AddData<EODHDEconomicEvents>(ticker).Symbol; } }
Accessing Data
To get the current Economic Events data, index the current Slice
with the dataset Symbol
. Slice objects deliver unique events to your algorithm as they happen, but the Slice
may not contain data for your dataset at every time step. To avoid issues, check if the Slice
contains the data you want before you index it.
def on_data(self, slice: Slice) -> None: events = slice.get(EODHDEconomicEvents).get(self.dataset_symbol) for event in events: self.log(f"{event.event_type} of {event.country} over {event.event_period} with be held at {event.event_time} with estimated value {event.estimate}")
public override void OnData(Slice slice) { if (slice.Get<EODHDEconomicEvents>().TryGetValue(_datasetSymbol, out var economicEvents)) { foreach (EODHDEconomicEvent economicEvent in economicEvents) { Log($"{economicEvent.EventType} of {economicEvent.Country} over {economicEvent.EventPeriod} with be held at {economicEvent.EventTime} with estimated value {economicEvent.Estimate}"); } } }
To iterate through all of the dataset objects in the current Slice
, call the Get
get
method.
def on_data(self, slice: Slice) -> None: for symbol, events in slice.get(EODHDEconomicEvents).items(): for event in events: self.log(f"{event.event_type} of {event.country} over {event.event_period} with be held at {event.event_time} with estimated value {event.estimate}")
public override void OnData(Slice slice) { foreach (var (symbol, economicEvents) in slice.Get<EODHDEconomicEvents>()) { foreach (EODHDEconomicEvent economicEvent in economicEvents) { Log($"{economicEvent.EventType} of {economicEvent.Country} over {economicEvent.EventPeriod} with be held at {economicEvent.EventTime} with estimated value {economicEvent.Estimate}"); } } }
Historical Data
To get historical Economic Events data, call the History
history
method with the type EODHDEconomicEvents
cast and the underlying Symbol
. If there is no data in the period you request, the history result is empty.
history_bars = self.history[EODHDEconomicEvents](self.dataset_symbol, 100, Resolution.DAILY)
var history = History<EODHDEconomicEvents>(_datasetSymbol, 100, Resolution.Daily);
For more information about historical data, see History Requests.
Example Applications
The Economic Events dataset provides timely notifications about upcoming economic events, allowing traders to trade on that volatility. Examples include the following strategies:
- Long straddle to trade the volatility of the economic events.
- Trade market representative ETFs based on estimated figures for the upcoming events.
- Statistical arbitrage on two or more correlated global markets based on economic events of different locations.
Classic Algorithm Example
The following example algorithm trade Industrial sector ETF based on US PMI estimated change direction. If the estimated PMI of the upcoming announcement is above the previous PMI, buy the Industrial ETF, and sell it otherwise.
class EODHDEconomicEventsAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2019, 1, 1) # Use industrial sector ETF as a vehicle to trade. self.equity_symbol = self.add_equity("XLI").symbol # Request US PMI economic event data to generate trade signals. ticker = EODHD.Events.UnitedStates.MARKIT_MANUFACTURING_PURCHASING_MANAGERS_INDEX self.dataset_symbol = self.add_data(EODHDEconomicEvents, ticker).symbol def on_data(self, slice): # Trade based on the updated economic events. if self.dataset_symbol in slice.get(EODHDEconomicEvents): # Use the Manufacturing Index to generate trade signals on manufacturing industry vehicles. # Make sure previous and estimate are available to estimate the direction of the industry. event = slice[self.dataset_symbol].data[0] if event.previous and event.estimate: # If the estimated PMI is higher than the previous PMI, the manufacturing ETF price is expected to rise. if event.previous > event.estimate: self.set_holdings(self.equity_symbol, 1) # Otherwise, it is expected manufacturing ETF prices will drop. else: self.set_holdings(self.equity_symbol, -1)
public class EODHDEconomicEventsAlgorithm : QCAlgorithm
{
private Symbol _equitySymbol, _datasetSymbol;
public override void Initialize()
{
SetStartDate(2019, 1, 1);
// Use industrial sector ETF as a vehicle to trade.
_equitySymbol = AddEquity("XLI").Symbol;
// Request US PMI economic event data to generate trade signals.
var ticker = EODHD.Events.UnitedStates.MarkitManufacturingPurchasingManagersIndex;
_datasetSymbol = AddData<EODHDEconomicEvents>(ticker).Symbol;
}
public override void OnData(Slice slice)
{
// Trade based on the updated economic events.
if (slice.Get<EODHDEconomicEvents>().TryGetValue(_datasetSymbol, out var economicEvents))
{
var economicEvent = economicEvents.FirstOrDefault() as EODHDEconomicEvent;
// Use the Manufacturing Index to generate trade signals on manufacturing industry vehicles.
// Make sure previous and estimate are available to estimate the direction of the industry.
if (economicEvent.Previous.HasValue && economicEvent.Estimate.HasValue)
{
//If the estimated PMI is higher than the previous PMI, the manufacturing ETF price is expected to rise.
if (economicEvent.Previous.Value > economicEvent.Estimate.Value)
{
SetHoldings(_equitySymbol, 1);
}
// Otherwise, it is expected manufacturing ETF price will drop.
else
{
SetHoldings(_equitySymbol, -1);
}
}
}
}
}
Framework Algorithm Example
The following example algorithm trade Industrial sector ETF based on US PMI estimated change direction using algorithm framework. If the estimated PMI of the upcoming announcement is above the previous PMI, buy the Industrial ETF, sell it otherwise.
class EODHDEconomicEventsAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2019, 1, 1) # Use industrial sector ETF as a vehicle to trade. symbol = Symbol.create("XLI", SecurityType.EQUITY, Market.USA) self.add_universe_selection(ManualUniverseSelectionModel(symbol)) # Custom alpha model to emit insights according to economic events. self.add_alpha(EconomicEventAlphaModel(self)) # Equal weighting position sizing to dissipate capital risk evenly. self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel(Expiry.END_OF_MONTH)) class EconomicEventAlphaModel(AlphaModel): def __init__(self, algorithm: QCAlgorithm) -> None: # Request US PMI economic event data to generate trade signals. ticker = EODHD.Events.UnitedStates.MARKIT_MANUFACTURING_PURCHASING_MANAGERS_INDEX self.dataset_symbol = algorithm.add_data(EODHDEconomicEvents, ticker).symbol self._symbol = None def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]: # Trade based on the updated economic events. if self.dataset_symbol not in slice.get(EODHDEconomicEvents): return [] # Use the US Manufacturing Index to generate trade signals on manufacturing industry vehicles. # Make sure previous and estimate are available to estimate the direction of the industry. event = slice[self.dataset_symbol].data[0] # If the estimated PMI is higher than the previous PMI, the manufacturing ETF price is expected to rise. # Otherwise, it is expected manufacturing ETF prices will drop. direction = InsightDirection.UP if event.previous > event.estimate else InsightDirection.DOWN return [Insight.price(self._symbol, timedelta(5), direction)] def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None: for added in changes.added_securities: self._symbol = added.symbol
public class EODHDEconomicEventsAlgorithm : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2019, 1, 1);
// Use industrial sector ETF as a vehicle to trade.
var symbol = QuantConnect.Symbol.Create("XLI", SecurityType.Equity, Market.USA);
AddUniverseSelection(new ManualUniverseSelectionModel(new[] {symbol}));
// Custom alpha model to emit insights according to economic events.
AddAlpha(new EconomicEventAlphaModel(this));
// Equal weighting position sizing to dissipate capital risk evenly.
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(Expiry.EndOfMonth));
}
}
public class EconomicEventAlphaModel : AlphaModel
{
private Symbol _symbol, _datasetSymbol;
public EconomicEventAlphaModel(QCAlgorithm algorithm)
{
// Request US PMI economic event data to generate trade signals.
var ticker = EODHD.Events.UnitedStates.MarkitManufacturingPurchasingManagersIndex;
_datasetSymbol = algorithm.AddData(ticker).Symbol;
}
public override IEnumerable Update(QCAlgorithm algorithm, Slice slice)
{
// Trade based on the updated economic events.
if (slice.Get().TryGetValue(_datasetSymbol, out var economicEvents))
{
// Use the US Manufacturing Index to generate trade signals on manufacturing industry vehicles.
// Make sure previous and estimate are available to estimate the direction of the industry.
var economicEvent = economicEvents.FirstOrDefault() as EODHDEconomicEvent;
if (economicEvent.Previous.HasValue && economicEvent.Estimate.HasValue)
{
// If the estimated PMI is higher than the previous PMI, the manufacturing ETF price is expected to rise.
// Otherwise, it is expected manufacturing ETF prices will drop.
var direction = economicEvent.Previous.Value > economicEvent.Estimate.Value
? InsightDirection.Up
: InsightDirection.Down;
yield return Insight.Price(_symbol, TimeSpan.FromDays(5), direction);
}
}
}
public override void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
{
foreach (var added in changes.AddedSecurities)
{
_symbol = added.Symbol;
}
}
}
Data Point Attributes
The EODHD Economic Events dataset provides EODHDEconomicEvent
objects, which have the following attributes:
The EODHDEconomicEvents
objects represent a collection of EODHDEconomicEvent
object
Country Enumeration
To filter the countries of the economic events, you can make use of the Country
enumeration. The Country
enumeration has the following members:
Events Enumeration
To filter the event types of the economic events, you can make use of the Events
enumeration. The Events
enumeration has the following members: