Overall Statistics |
Total Trades 131 Average Win 0.04% Average Loss -0.16% Compounding Annual Return 3.528% Drawdown 7.200% Expectancy -0.305 Net Profit 0.171% Sharpe Ratio 0.253 Probabilistic Sharpe Ratio 43.128% Loss Rate 45% Win Rate 55% Profit-Loss Ratio 0.25 Alpha 0.242 Beta -0.934 Annual Standard Deviation 0.32 Annual Variance 0.103 Information Ratio -0.254 Tracking Error 0.359 Treynor Ratio -0.087 Total Fees $131.00 |
from datetime import timedelta class helloWorldModel(AlphaModel): def __init__(self): self.mom = [] def OnSecuritiesChanged(self, algorithm, changes): for security in changes.AddedSecurities: symbol = security.Symbol price_val = security.Price kama_val=algorithm.KAMA(symbol, 10,2,30, Resolution.Hour) mom_val=algorithm.MOM(symbol, 14, Resolution.Hour) self.mom.append({"symbol":symbol, "mom":mom_val, "kama":kama_val,"price":str(price_val)}) def Update(self, algorithm, data): grp=[] x = 0 while x < len(self.mom): symbol=str(self.mom[x]['symbol']) mom=str(self.mom[x]['mom'].Current.Value) kama=str(self.mom[x]['kama'].Current.Value) price=str(self.mom[x]['price']) mom_dir=int(float(mom)) vinsightDirection = InsightDirection.Flat signal="hold" if mom_dir >0 and price>kama: vinsightDirection = InsightDirection.Up signal="buy" if mom_dir < 0 or price<kama: vinsightDirection = InsightDirection.Down signal="sell" algorithm.Log(symbol+" "+str(mom_dir)+" MOM "+mom+" KAMA "+kama+" LastPrice "+price+" algo action:"+signal) grp.append(Insight(symbol, timedelta(1), InsightType.Price, vinsightDirection, 0.0025,None, "helloWorldModel",None)) x += 1 return Insight.Group(grp) class FrameworkAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 12, 1) self.SetCash(100000) tickers=["MSFT","MRNA","MELI"] symbols = [Symbol.Create(x, SecurityType.Equity, Market.USA) for x in tickers] frequency = Resolution.Hour # Set Benchmark self.AddEquity("SPY", frequency) self.SetBenchmark("SPY") self.UniverseSettings.Resolution = frequency self.SetWarmUp(timedelta(28)) # Warm up 28 days of data. self.SetUniverseSelection(ManualUniverseSelectionModel(symbols)) self.SetAlpha(helloWorldModel()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.02))