Overall Statistics
Total Trades
19
Average Win
29.17%
Average Loss
0%
Compounding Annual Return
19.212%
Drawdown
18.700%
Expectancy
0
Net Profit
959.577%
Sharpe Ratio
1.179
Probabilistic Sharpe Ratio
60.360%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.178
Beta
0.238
Annual Standard Deviation
0.176
Annual Variance
0.031
Information Ratio
0.362
Tracking Error
0.229
Treynor Ratio
0.871
Total Fees
$86.11
Estimated Strategy Capacity
$76000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
## SIMON LesFlex June 2021 ##
## Modified by Vladimir

from QuantConnect.Python import PythonQuandl

### 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):
        self.quandlCode = "OECD/KEI_LOLITOAA_OECDE_ST_M"  # LeadInd
        ## 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.MOMP(self.quandlCode, 2)
        self.stock = self.AddEquity('QQQ', Resolution.Hour).Symbol
        self.bond = self.AddEquity('TLT', Resolution.Hour).Symbol
        self.Schedule.On(self.DateRules.WeekStart(self.stock), self.TimeRules.AfterMarketOpen(self.stock, 31), 
            self.Rebalance)
        

    def Rebalance(self):
        if self.IsWarmingUp or not self.mom.IsReady or not self.sma.IsReady: return
        initial_asset = self.stock if self.mom.Current.Value > 0 else self.bond
        if self.init:
            self.SetHoldings(initial_asset, 1)
            self.init = False
        
        if self.mom.Current.Value > 0 and not self.Securities[self.stock].Invested:
            self.Liquidate(self.bond)
            self.SetHoldings(self.stock, 1)
            # self.Debug("Purchased {0} >> {1}".format(self.stock, self.Time))
            
        elif self.mom.Current.Value < 0 and self.sma.Current.Value < 100 and self.Securities[self.stock].Invested:
            self.Liquidate(self.stock)
            self.SetHoldings(self.bond, 1)
            # self.Debug("Liquidated {0} >> {1}".format(self.stock, self.Time))
            
        self.Plot("LeadInd", "SMA(LeadInd)", self.sma.Current.Value)
        self.Plot("LeadInd", "THRESHOLD", 100)
        self.Plot("MOMP", "MOMP(LeadInd)", self.mom.Current.Value)
        self.Plot("MOMP", "THRESHOLD", 0)

        
# Quandl often doesn't use close columns so need to tell LEAN which is the "value" column.
class QuandlCustomColumns(PythonQuandl):
    def __init__(self):
        # Define ValueColumnName: cannot be None, Empty or non-existant column name
        self.ValueColumnName = "Value"