Overall Statistics |
Total Trades 14 Average Win 3.58% Average Loss 0% Compounding Annual Return 2.108% Drawdown 4.900% Expectancy 0 Net Profit 27.786% Sharpe Ratio 0.588 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha -0.01 Beta 1.587 Annual Standard Deviation 0.037 Annual Variance 0.001 Information Ratio 0.042 Tracking Error 0.037 Treynor Ratio 0.014 Total Fees $350.00 |
import numpy as np class BasicTemplateAlgorithm(QCAlgorithm): '''Basic template algorithm simply initializes the date range and cash''' def Initialize(self): self.SetStartDate(2007,1, 1) #Set Start Date self.SetEndDate(2018,9,30) #Set End Date self.SetCash(10000) #Set Strategy Cash self.spy = self.AddEquity("SPY", Resolution.Daily) self.AddEquity("UPRO", Resolution.Daily) self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage) self.rsi = self.RSI("SPY", 2) self.sma200 = self.SMA("SPY", 200) self.sma20 = self.SMA("SPY", 20) ## will use this later on def OnData(self, data): if not self.sma200.IsReady: return if data.ContainsKey("SPY") == False: return #var buy1 = RSI<24 && adx>20; #var buy2 = RSI<10 && adx>30; #if _spyhigh>Avg200 then buy1 else buy2; if data[self.spy.Symbol].High > self.sma200.Current.Value and self.rsi.Current.Value <24 and not self.Portfolio["UPRO"].Invested: self.Debug("UPRO buy") self.MarketOrder("UPRO", 5000) self.Debug("Market order was placed") #var sell1 = _spy>_Avg20 && RSI>85; #var sell2 = _spy>Avg20 && RSI>80; #if _spyhigh<SMA200 then sell1 else sell2; if data[self.spy.Symbol].High > self.sma200.Current.Value and (self.rsi.Current.Value > 85 or self.rsi.Current.Value < 80): self.Debug("UPRO sell") self.Liquidate()