| Overall Statistics |
|
Total Trades 93 Average Win 19.76% Average Loss -16.95% Compounding Annual Return -46.374% Drawdown 80.500% Expectancy 0.166 Net Profit -35.550% Sharpe Ratio 0.202 Probabilistic Sharpe Ratio 19.415% Loss Rate 46% Win Rate 54% Profit-Loss Ratio 1.17 Alpha 0.099 Beta 0.985 Annual Standard Deviation 1.302 Annual Variance 1.696 Information Ratio 0.074 Tracking Error 1.299 Treynor Ratio 0.267 Total Fees $217.78 Estimated Strategy Capacity $810000.00 Lowest Capacity Asset MEDS XC03HZ3KX3L1 |
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021,4,1)
self.SetCash(5000)
self.Data_Symbol = {}
tickers = ["SPY","MEDS","ANY","XIN",]
self.SetWarmUp(30, Resolution.Daily)
for stock in tickers:
symbol = self.AddEquity(stock, Resolution.Minute).Symbol
self.Data_Symbol[symbol] = SymbolData(self, symbol)
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY", 260), self.EveryDayAfterMarketOpen)
def EveryDayAfterMarketOpen(self):
if self.IsWarmingUp: return
for symbol, symbol_data in self.Data_Symbol.items():
if not symbol_data.rsi.IsReady: continue
holdings = self.Portfolio[symbol]
invested = holdings.Invested
nowprice = holdings.Price
aveprice = holdings.AveragePrice
quantity = holdings.Quantity
bpower = self.Portfolio.Cash
rsi = symbol_data.rsi.Current.Value
macd = symbol_data.macd.Current.Value
cci = symbol_data.cci.Current.Value
wilr = symbol_data.wilr.Current.Value
if self.LiveMode and not invested and bpower > nowprice:
self.Log(f'{symbol} :: {rsi:.6},{cci:.6},{wilr:.6},{macd:.6}')
if not invested and bpower > nowprice and rsi > 0 and cci > -100 and wilr > -100 and macd > -10:
self.MarketOrder(symbol, 1)
if self.LiveMode:
self.Log(f'{symbol} bought on {self.Time}')
if invested and nowprice < aveprice * 0.95 and bpower > nowprice: #0.95 is better than 0.90
self.MarketOrder(symbol, quantity + 1)
if invested and nowprice > aveprice * 1.20 or nowprice < aveprice * 0.7: #stop loss at 0.7 best
self.Liquidate(symbol)
class SymbolData:
def __init__ (self,algo,symbol):
self.algorithm = algo
self.symbol = symbol
self.rsi = algo.RSI(symbol, 14, Resolution.Daily)
self.macd = algo.MACD(symbol, 12, 26, 9, Resolution.Daily)
self.cci = algo.CCI(symbol, 14, Resolution.Daily)
self.wilr = algo.WILR(symbol, 14, Resolution.Daily)