| Overall Statistics |
|
Total Trades 53 Average Win 2.80% Average Loss -3.08% Compounding Annual Return 7.473% Drawdown 12.200% Expectancy 0.162 Net Profit 8.883% Sharpe Ratio 0.643 Loss Rate 39% Win Rate 61% Profit-Loss Ratio 0.91 Alpha 0.266 Beta -9.288 Annual Standard Deviation 0.124 Annual Variance 0.015 Information Ratio 0.481 Tracking Error 0.124 Treynor Ratio -0.009 Total Fees $87.94 |
from clr import AddReference
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Algorithm.Framework")
from QuantConnect.Algorithm import QCAlgorithm
from QuantConnect.Data.UniverseSelection import *
from QuantConnect.Indicators import *
from datetime import timedelta, datetime
class lowStdAlphaAlgorithm(QCAlgorithmFramework):
def Initialize(self):
self.SetStartDate(2018, 1, 1)
self.SetCash(100000)
# Add SPY to Universe
self.AddSecurity(SecurityType.Equity,"SPY", Resolution.Daily)
# Use Manual Universe Selection Model
self.SetUniverseSelection(ManualUniverseSelectionModel())
# Select the Alpha Model
self.SetAlpha(lowStdExampleAlphaModel())
# Equally weigh securities
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
class lowStdExampleAlphaModel(AlphaModel):
def __init__(self):
# Set length of the insight period
self.period = timedelta(days=1)
# Set lookback period for STD and SMA
self.lookback = 10
# Set data resolution
self.resolution = Resolution.Daily
def Update(self, algorithm, data):
insights = []
if not data.ContainsKey(self.symbol): return insights
# Set magnitude prediction as the average percentage change of price
magnitude = self.meanOfPriceChange.Current.Value
# Emit an "Up" insight if STD(Price) < SMA(STD(Price))
if self.std.Current.Value < self.stdAvg.Current.Value:
insights.append(Insight.Price(self.symbol, self.period, InsightDirection.Up,magnitude))
return insights
# Ignites when securities are added/removed from universe
def OnSecuritiesChanged(self, algorithm, changes):
for added in changes.AddedSecurities:
self.symbol = added.Symbol
# Mean value of returns for magnitude prediction
self.meanOfPriceChange = IndicatorExtensions.SMA(RateOfChangePercent(1),self.lookback)
# Construct standard deviation of price using STD Indicator for added securities
self.std = algorithm.STD(added.Symbol, self.lookback,self.resolution)
# Construct simple moving average (SMA) of the standard deviation of price
self.stdAvg = IndicatorExtensions.SMA(self.std, self.lookback)