| Overall Statistics |
|
Total Trades 400 Average Win 3.22% Average Loss -1.04% Compounding Annual Return 236.071% Drawdown 19.200% Expectancy 0.651 Net Profit 286.373% Sharpe Ratio 5.737 Probabilistic Sharpe Ratio 97.121% Loss Rate 60% Win Rate 40% Profit-Loss Ratio 3.11 Alpha 2.539 Beta 0.838 Annual Standard Deviation 0.482 Annual Variance 0.233 Information Ratio 6.176 Tracking Error 0.404 Treynor Ratio 3.302 Total Fees $465.00 |
from datetime import datetime, timedelta
import decimal
import pandas as pd
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020,1,1)
#self.SetEndDate(2020,1,1)
self.SetEndDate(datetime.now())
self.SetCash(10000)
self.SetBenchmark("SPY") # Set SPY as benchmark
self.SetTimeZone(TimeZones.NewYork)
self.SetWarmUp(30)
self.sma = {}
self.symbols = ["TQQQ", "TNA"]
for symbol in self.symbols:
self.AddEquity(symbol, Resolution.Hour)
self.Securities[symbol].SetLeverage(1.0)
self.sma[symbol] = self.SMA(symbol, 20, Resolution.Hour)
def OnData(self,data):
if self.IsWarmingUp: return # Make sure all the data we need is in place
for symbol in self.symbols:
if self.Securities[symbol].Price > self.sma[symbol].Current.Value:
if self.Portfolio[symbol].Invested == False and self.Securities[symbol].Price > self.sma[symbol].Current.Value:
self.SetHoldings(symbol, 0.45)
#self.Debug(self.sma[symbol]) #print SMA price
for symbol in self.symbols:
#Close position if price is below SMA
if self.Securities[symbol].Price < self.sma[symbol].Current.Value and self.Portfolio[symbol].IsLong:
self.Liquidate(symbol)