Overall Statistics |
Total Trades 2 Average Win 1.24% Average Loss 0% Compounding Annual Return 89.975% Drawdown 0.800% Expectancy 0 Net Profit 1.238% Sharpe Ratio 11.074 Probabilistic Sharpe Ratio 99.836% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.695 Beta 0.076 Annual Standard Deviation 0.061 Annual Variance 0.004 Information Ratio 4.025 Tracking Error 0.218 Treynor Ratio 8.898 Total Fees $3.05 |
import datetime from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Common") from System import * from QuantConnect import * from QuantConnect.Algorithm import * from time import sleep class ControllClass(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 9, 20) # Set Start Date self.SetEndDate(2020, 9, 26) self.SetCash(100000) # Set Strategy Cash self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Cash) self.Settings.FreePortfolioPercentage = 0.8 self.weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday") self.symbols = [] self.openAt = datetime.time(15,55) self.spy = self.AddEquity("SPY").Symbol self.symbols.append(self.spy) self.gld = self.AddEquity("GLD").Symbol self.symbols.append(self.gld) self.Schedule.On(self.DateRules.Every( DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Friday), self.TimeRules.BeforeMarketClose(self.spy, 21), self.closePositions) self.sma = self.SMA(self.spy, 34, Resolution.Daily) self.SetWarmUp(timedelta(days=34)) self.traded = False def OnData(self, data): if self.IsWarmingUp: return if not self.Time.time() >= self.openAt: return self.Plot("Portfolio", "Cash", self.Portfolio.Cash) self.Plot("Portfolio", "UnsettledCash", self.Portfolio.UnsettledCash) if self.Time.weekday() == 0 and not self.traded: if not self.Portfolio[self.spy].Invested and data[self.spy].Close < self.sma.Current.Value: self.SetHoldings(self.spy, 1, True) self.traded = True def closePositions(self): if self.Portfolio.Invested: self.Liquidate() self.Log(f"Liquidated at {self.Time}") def OnOrderEvent(self, event): if event.Quantity == 0: return self.Debug(str(event))