Overall Statistics
Total Trades
25
Average Win
28.51%
Average Loss
-3.01%
Compounding Annual Return
23.259%
Drawdown
23.000%
Expectancy
8.602
Net Profit
1560.028%
Sharpe Ratio
1.37
Probabilistic Sharpe Ratio
79.437%
Loss Rate
8%
Win Rate
92%
Profit-Loss Ratio
9.48
Alpha
0.221
Beta
0.225
Annual Standard Deviation
0.182
Annual Variance
0.033
Information Ratio
0.525
Tracking Error
0.236
Treynor Ratio
1.106
Total Fees
$129.79
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_JPN_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, 1)
        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)

        
class QuandlCustomColumns(PythonQuandl):
    def __init__(self):
        self.ValueColumnName = "Value"