| Overall Statistics |
|
Total Trades 611 Average Win 0.96% Average Loss -0.59% Compounding Annual Return 6.654% Drawdown 17.600% Expectancy 0.205 Net Profit 48.780% Sharpe Ratio 0.681 Probabilistic Sharpe Ratio 21.290% Loss Rate 54% Win Rate 46% Profit-Loss Ratio 1.62 Alpha 0.049 Beta 0.159 Annual Standard Deviation 0.102 Annual Variance 0.01 Information Ratio -0.402 Tracking Error 0.148 Treynor Ratio 0.437 Total Fees $16202.74 |
from datetime import timedelta
class MOMAlphaModel(AlphaModel):
def __init__(self):
self.mom = []
def OnSecuritiesChanged(self, algorithm, changes):
#Initialize a 14-day momentum indicator for each symbol
for security in changes.AddedSecurities:
symbol = security.Symbol
self.mom.append({"symbol":symbol, "indicator":algorithm.MOM(symbol, 14, Resolution.Daily)}) #14
def Update(self, algorithm, data):
#Sort the list of dictionaries by indicator in descending order
ordered = sorted(self.mom, key=lambda kv: kv["indicator"].Current.Value, reverse=True)
#Return a group of insights, emitting InsightDirection.Up for the first item of ordered, and InsightDirection.Flat for the second
return Insight.Group(
[
Insight.Price(ordered[0]["symbol"], timedelta(1), InsightDirection.Up),
#Insight.Price(ordered[1]["symbol"], timedelta(1), InsightDirection.Down),
Insight.Price(ordered[1]["symbol"], timedelta(1), InsightDirection.Flat),
#Insight.Price(ordered[3]["symbol"], timedelta(1), InsightDirection.Down),
])
class FrameworkAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2013, 10, 1)
#self.SetEndDate(2013, 12, 1)
self.SetCash(1000000)
self.reference = "SPY"
self.SetBenchmark("SPY")
symbols = [
Symbol.Create("GLD", SecurityType.Equity, Market.USA),
Symbol.Create("SPY", SecurityType.Equity, Market.USA),
]
self.UniverseSettings.Resolution = Resolution.Daily
self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
# Call the MOMAlphaModel Class
self.SetAlpha(MOMAlphaModel())
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
#self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel())
self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.002))
self.SetExecution(ImmediateExecutionModel())
self.SetBrokerageModel(BrokerageName.AlphaStreams)