Overall Statistics
import numpy as np
from datetime import timedelta, datetime
import decimal
from QuantConnect.Data.Custom.TradingEconomics import *

class RegressionChannelAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetCash(1000000)
        self.SetStartDate(2015,11,12)
        self.SetEndDate(2019,11,23)
        slowperiod = 1000
        self.SetBenchmark('SPY')
        self.SetWarmUp(timedelta(31))
        
        self.AddForex("EURUSD", Resolution.Daily, Market.Oanda)
        self.AddForex("USDCHF", Resolution.Daily, Market.Oanda)
        self.AddForex("AUDUSD", Resolution.Daily, Market.Oanda)
        self.AddForex("GBPUSD", Resolution.Daily, Market.Oanda)
        self.AddForex("USDJPY", Resolution.Daily, Market.Oanda)
        
        self.usdrate = self.AddData(TradingEconomicsCalendar, TradingEconomics.Calendar.UnitedStates.InterestRate).Symbol
        self.usdinfla = self.AddData(TradingEconomicsCalendar, TradingEconomics.Calendar.UnitedStates.CoreInflationRate).Symbol 
                        
        history = self.History(TradingEconomicsCalendar, self.usdrate, 365, Resolution.Daily)
        
    def OnData(self, data):
        if self.IsWarmingUp: 
            return
        
        if not (data.ContainsKey("EURUSD")) or not (data.ContainsKey("USDCHF")):
            return
        
        # Using the data is the same as other data types: 
        if not (data.ContainsKey(self.usdrate)):
            return
        
        if not (data.ContainsKey(self.usdinfla)):
            self.Log("Checking for keys...")
            return
        
        self.Log("Inflation Data keys...found")
        
        usdrateannouncement = data[self.usdrate]
        #usdinflaEvent = data[self.usdinfla]
        
        #if usdrateannouncement.Event != "Fed Interest Rate Decision":
        #    return
        # In the event of a rate increase, rebalance 50% to Bonds.
        interestRateDecreased = usdrateannouncement.Forecast <= usdrateannouncement.Previous
        interestRateIncreased = usdrateannouncement.Forecast >= usdrateannouncement.Previous
        
        #inflationRateDecreased = usdinflaEvent.Forecast <= usdinflaEvent.Previous
        #inflationRateIncreased = usdinflaEvent.Forecast >= usdinflaEvent.Previous
        self.Log("checking for rate announcements...")
        
        if interestRateDecreased: #inflationRateDecreased: 
            #self.Debug(usdrateannouncement.Event)
            self.Log(usdinflaEvent.Event)
            self.MarketOrder("EURUSD", -100000)
            #self.MarketOrder("USDCHF", 100000)
            #self.MarketOrder("GBPUSD", -100000)
            #self.MarketOrder("AUDUSD", -100000)
            self.MarketOrder("USDJPY", -100000)
        elif interestRateIncreased: # or inflationRateDecreased:
            #self.Debug(usdrateannouncement.Event)
            self.Log(usdinflaEvent.Event) 
            self.MarketOrder("EURUSD", 100000)
            #self.MarketOrder("USDCHF", -100000)
            #self.MarketOrder("GBPUSD", 100000)
            #self.MarketOrder("AUDUSD", -200000)
            self.MarketOrder("USDJPY", 100000)
        elif not self.Portfolio.Invested: 
            self.MarketOrder("EURUSD", -100000)
            #self.MarketOrder("USDCHF", 100000)
            #self.MarketOrder("GBPUSD", -100000)
            #self.MarketOrder("AUDUSD", -100000)
            self.MarketOrder("USDJPY", -100000)