Overall Statistics
Total Trades
21
Average Win
29.23%
Average Loss
-6.10%
Compounding Annual Return
18.696%
Drawdown
18.700%
Expectancy
4.211
Net Profit
899.578%
Sharpe Ratio
1.125
Probabilistic Sharpe Ratio
53.541%
Loss Rate
10%
Win Rate
90%
Profit-Loss Ratio
4.79
Alpha
0.167
Beta
0.292
Annual Standard Deviation
0.181
Annual Variance
0.033
Information Ratio
0.354
Tracking Error
0.223
Treynor Ratio
0.697
Total Fees
$87.02
Estimated Strategy Capacity
$76000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
## SIMON LesFlex June 2021 ##

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Data.Custom import *
from QuantConnect.Python import PythonQuandl
from datetime import datetime, timedelta

### Simon LesFlex June 2021 ###
### Key Short—Term Economic Indicators. The Key Economic Indicators (KEI) database contains monthly and quarterly statistics 
### (and associated statistical methodological information) for the 33 OECD member and for a selection of non—member countries 
### on a wide variety of economic indicators, namely: quarterly national accounts, industrial production, composite leading indicators, 
### business tendency and consumer opinion surveys, retail trade, consumer and producer prices, hourly earnings, employment/unemployment,
### interest rates, monetary aggregates, exchange rates, international trade and balance of payments. Indicators have been prepared by national statistical 
### agencies primarily to meet the requirements of users within their own country. In most instances, the indicators are compiled in accordance with 
### international statistical guidelines and recommendations. However, national practices may depart from these guidelines, and these departures may 
### impact on comparability between countries. There is an on—going process of review and revision of the contents of the database in order to maximise 
### the relevance of the database for short—term economic analysis.
### For more information see: http://stats.oecd.org/OECDStat_Metadata/ShowMetadata.ashx?Dataset=KEI&Lang=en
### Reference Data Set: https://www.quandl.com/data/OECD/KEI_LOLITOAA_OECDE_ST_M-Leading-indicator-amplitude-adjusted-OECD-Europe-Level-ratio-or-index-Monthly


class QuandlImporterAlgorithm(QCAlgorithm):

    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        self.quandlCode = "OECD/KEI_LOLITOAA_OECDE_ST_M"
        ## Optional argument - personal token necessary for restricted dataset
        Quandl.SetAuthCode("MLNarxdsMU92vk-ZJDvg")
        
        self.SetStartDate(2008,1,1)                                 #Set Start Date
        self.SetEndDate(datetime.today() - timedelta(1))            #Set End Date
        self.SetCash(25000)                                         #Set Strategy Cash
        self.SetWarmup(100)
        self.init = True
        self.AddData(QuandlCustomColumns, self.quandlCode, Resolution.Daily, TimeZones.NewYork)
        self.sma = self.SMA(self.quandlCode, 1)
        self.mom = self.MOM(self.quandlCode, 2)
        self.SPY = self.AddEquity('SPY', Resolution.Hour).Symbol
        self.QQQ = self.AddEquity('QQQ', Resolution.Hour).Symbol
        self.BOND = self.AddEquity('TLT', Resolution.Hour).Symbol
        self.Schedule.On(self.DateRules.WeekStart("SPY"), self.TimeRules.AfterMarketOpen("SPY", 31), Action(self.Rebalance))
        

    def Rebalance(self):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
        #if not self.Portfolio.HoldStock:
        #if self.sma.Current.Value > 100.0 and not self.Securities[self.SPY].Invested:
        if self.init:
            self.SetHoldings(self.QQQ, 1)
            self.init = False
        
        if self.mom.Current.Value > 0 and not self.Securities[self.QQQ].Invested:
            self.Liquidate(self.BOND)
            self.SetHoldings(self.QQQ, 1)
            self.Debug("Purchased {0} >> {1}".format(self.QQQ, self.Time))
        elif self.mom.Current.Value < 0 and self.sma.Current.Value < 100 and self.Securities[self.QQQ].Invested:
            self.Liquidate(self.QQQ)
            self.SetHoldings(self.BOND, 1)
            self.Debug("Liquidated {0} >> {1}".format(self.QQQ, self.Time))
            
        self.Plot(self.quandlCode, "KEI", self.sma.Current.Value)
        
    def OnData(self, data):
        pass
        
# Quandl often doesn't use close columns so need to tell LEAN which is the "value" column.
class QuandlCustomColumns(PythonQuandl):
    '''Custom quandl data type for setting customized value column name. Value column is used for the primary trading calculations and charting.'''
    def __init__(self):
        # Define ValueColumnName: cannot be None, Empty or non-existant column name
        self.ValueColumnName = "Value"