Overall Statistics
Total Trades
188
Average Win
1.92%
Average Loss
-1.65%
Compounding Annual Return
5.169%
Drawdown
24.100%
Expectancy
0.183
Net Profit
34.432%
Sharpe Ratio
0.488
Probabilistic Sharpe Ratio
8.625%
Loss Rate
45%
Win Rate
55%
Profit-Loss Ratio
1.17
Alpha
0.048
Beta
-0.011
Annual Standard Deviation
0.096
Annual Variance
0.009
Information Ratio
-0.331
Tracking Error
0.194
Treynor Ratio
-4.33
Total Fees
$2666.21
import numpy as np
from QuantConnect.Python import PythonQuandl

class OptimizedResistanceRadiator(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2014, 12, 31)
        self.SetCash(1000000)
        
        self.SetBrokerageModel(BrokerageName.AlphaStreams)
        
        self.ticker = 'SPY'
        self.equity = self.AddEquity(self.ticker, Resolution.Daily)
        self.equity.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.equity_symbol = self.equity.Symbol
        
        self.PMI_data = self.AddData(QuandlPMICompositeIndex, "ISM/MAN_PMI", Resolution.Daily)
        
        self.nextRebalance = self.Time
        self.rebalance_delta = 1
        
        self.Settings.FreePortfolioValuePercentage = 0.01
        
        self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
      
    def OnData(self, data):
       
        if self.Time < self.nextRebalance:# or not self.equity.Exchange.ExchangeOpen:
            return
        
        if data.ContainsKey('ISM/MAN_PMI'):
            self.Plot("Data Chart", "PMI Composite Index", self.Securities['ISM/MAN_PMI'].Price)
            #hist = self.History(['ISM/MAN_PMI'], timedelta(days = 10), Resolution.Daily)
        
            if self.Securities['ISM/MAN_PMI'].Price >= 50.:
                if not self.Securities[self.equity_symbol].Invested:
                    self.EmitInsights(Insight.Price(self.equity_symbol, timedelta(days=15), InsightDirection.Up, 1., 1., "MyAlphaModel", 1.))
            else:
                self.Liquidate()
                self.EmitInsights(Insight.Price(self.equity_symbol, timedelta(days=15), InsightDirection.Flat, 1., 1., "MyAlphaModel", 1.))
                    
        ### Update next rebalance time
        self.nextRebalance = self.Time + timedelta(days=self.rebalance_delta)
            
class QuandlPMICompositeIndex(PythonQuandl):
    def __init__(self):
        self.ValueColumnName = "PMI"