Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -0.627 Tracking Error 0.324 Treynor Ratio 0 Total Fees $0.00 |
class BasicTemplateFrameworkAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 6, 1) # Set Start Date self.SetEndDate(2020, 6, 2) self.SetCash(100000) # Set Strategy Cash self.AddEquity("SPY", Resolution.Hour, Market.USA) self.AddAlpha(CustomAlpha(self)) class CustomAlpha(AlphaModel): def __init__(self, algorithm): # define our daily macd(12,26) with a 9 day signal self.macd = algorithm.MACD("SPY", 12, 26, 9, MovingAverageType.Exponential, Resolution.Hour) #define our daily RSI with a 14 day period self.rsi = algorithm.RSI("SPY", 14, MovingAverageType.Simple, Resolution.Hour) def Update(self, algorithm, data): insights = [] if "SPY" not in data.Keys: return [] tolerance = 0.0025 signalDeltaPercent = (self.macd.Current.Value - self.macd.Signal.Current.Value)/self.macd.Fast.Current.Value ## Selling conditions if (signalDeltaPercent < -tolerance and self.rsi.Current.Value > 70): insights = [Insight(security, self.insightDuration, InsightType.Price, InsightDirection.Down, self.insightMagnitude, None) \ for security in algorithm.ActiveSecurities.Keys if security != "SPY"] ## Buying conditions if (signalDeltaPercent > tolerance and self.rsi.Current.Value < 30): insights = [Insight(security, self.insightDuration, InsightType.Price, InsightDirection.Up, self.insightMagnitude, None) \ for security in algorithm.ActiveSecurities.Keys if security != "SPY"] return insights def OnSecuritiesChanged(self, algorithm, changes): pass