Overall Statistics |
Total Trades 5 Average Win 0% Average Loss 0% Compounding Annual Return 48.930% Drawdown 0.900% Expectancy 0 Net Profit 3.516% Sharpe Ratio 5.336 Probabilistic Sharpe Ratio 90.939% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.141 Beta 0.355 Annual Standard Deviation 0.061 Annual Variance 0.004 Information Ratio -2.428 Tracking Error 0.081 Treynor Ratio 0.921 Total Fees $5.00 Estimated Strategy Capacity $73000000.00 Lowest Capacity Asset AAPL R735QTJ8XC9X |
# region imports from AlgorithmImports import * import pandas as pd import numpy as np from datetime import time, datetime, timedelta # endregion class MyAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 3, 15) # Set Start Date self.SetEndDate(2021, 4, 15) self.SetCash(100000) # Set Strategy Cash self.symbol = self.AddEquity('AAPL', Resolution.Minute) self.symbol.SetDataNormalizationMode(DataNormalizationMode.Raw) self.invest = False self.sell = True self.liquidate = True self.potential_buy = False self.indicator_week = False self.indicator_day = 0 self.indicatorHigh = 0 self.indicatorWeekHigh = 0 dailyConsolidator = TradeBarConsolidator(timedelta(days=1)) self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, dailyConsolidator) dailyConsolidator.DataConsolidated += self.OnTwoDayBar self.barWindow = RollingWindow[TradeBar](2) weeklyConsolidator = TradeBarConsolidator(Calendar.Weekly) self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, weeklyConsolidator) weeklyConsolidator.DataConsolidated += self.OnTwoWeekBar self.weekBarWindow = RollingWindow[TradeBar](2) def OnData(self, data): self.Plot('Custom Chart', 'symbol Price', self.Securities[self.symbol.Symbol].Close) profit = self.Portfolio[self.symbol.Symbol].UnrealizedProfitPercent symbol_price = self.Securities[self.symbol.Symbol].Price if (self.indicator_day == self.Time.day) and (symbol_price > self.indicatorHigh) and self.potential_buy: shares_to_buy = int(self.Portfolio.Cash / data[self.symbol.Symbol].Open) self.MarketOrder(self.symbol.Symbol, (shares_to_buy*0.1)) self.potential_buy = False if (symbol_price > self.indicatorWeekHigh) and self.indicator_week: shares_to_buy = int(self.Portfolio.Cash / data[self.symbol.Symbol].Open) self.MarketOrder(self.symbol.Symbol, (shares_to_buy*0.1)) self.potential_buy = False def OnTwoDayBar(self, sender, bar): self.barWindow.Add(bar) if not self.barWindow.IsReady: return indicatorBar = self.barWindow[0] previousBar = self.barWindow[1] self.indicatorHigh = indicatorBar.High indicatorLow = indicatorBar.Low previousHigh = previousBar.High previousLow = previousBar.Low # Inside Bar if (self.indicatorHigh < previousHigh) and (indicatorLow > previousLow): self.indicator_day = self.Time.day self.potential_buy = True # 2Down if (self.indicatorHigh < previousHigh) and (indicatorLow < previousLow): self.indicator_day = self.Time.day self.potential_buy = True def OnTwoWeekBar(self, sender, bar): self.barWindow.Add(bar) if not self.barWindow.IsReady: return indicatorBar = self.barWindow[0] previousBar = self.barWindow[1] self.indicatorWeekHigh = indicatorBar.High indicatorLow = indicatorBar.Low previousHigh = previousBar.High previousLow = previousBar.Low # Inside Bar if (self.indicatorWeekHigh < previousHigh) and (indicatorLow > previousLow): self.indicator_week = True # 2Down if (self.indicatorHigh < previousHigh) and (indicatorLow < previousLow): self.indicator_week = True