Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -7.629 Tracking Error 0.056 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
# region imports from AlgorithmImports import * import pandas as pd import numpy as np from datetime import time, datetime, timedelta # endregion class CombinedAlgorithm(QCAlgorithm): def Initialize(self): # INITIALIZE self.SetStartDate(2021, 8, 1) # Set Start Date self.SetEndDate(2021, 8, 15) self.SetCash(10000) # Set Strategy Cash self.symbol = self.AddEquity('AAPL', Resolution.Minute) # Change back to minute self.symbol.SetDataNormalizationMode(DataNormalizationMode.Raw) # VARIABLES self.current_true_range = 0 self.true_range = [] # WARM UP self.SetWarmUp(timedelta(days = 50)) # CONSOLIDATED DATA # ATR atrConsolidator = TradeBarConsolidator(timedelta(days=1)) self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, atrConsolidator) atrConsolidator.DataConsolidated += self.ATRDayBar self.atrBarWindow = RollingWindow[TradeBar](14) def Rebalance(self): if self.IsWarmingUp: return def OnData(self, data): return # CONSILDATED FUNCTIONS def ATRDayBar(self, sender, bar): self.atrBarWindow.Add(bar) if self.IsWarmingUp: return array = [] # Grabbing the initial 3 numbers ########################################################################## array.append([self.atrBarWindow[0].High - self.atrBarWindow[0].Low, 0, 0]) array.append([self.atrBarWindow[1].High - self.atrBarWindow[1].Low, \ np.abs(self.atrBarWindow[1].High - self.atrBarWindow[0].Close), \ np.abs(self.atrBarWindow[1].Low - self.atrBarWindow[0].Close)]) array.append([self.atrBarWindow[2].High - self.atrBarWindow[2].Low, \ np.abs(self.atrBarWindow[2].High - self.atrBarWindow[1].Close), \ np.abs(self.atrBarWindow[2].Low - self.atrBarWindow[1].Close)]) array.append([self.atrBarWindow[3].High - self.atrBarWindow[3].Low, \ np.abs(self.atrBarWindow[3].High - self.atrBarWindow[2].Close), \ np.abs(self.atrBarWindow[3].Low - self.atrBarWindow[2].Close)]) array.append([self.atrBarWindow[4].High - self.atrBarWindow[4].Low, \ np.abs(self.atrBarWindow[4].High - self.atrBarWindow[3].Close), \ np.abs(self.atrBarWindow[4].Low - self.atrBarWindow[3].Close)]) array.append([self.atrBarWindow[5].High - self.atrBarWindow[5].Low, \ np.abs(self.atrBarWindow[5].High - self.atrBarWindow[4].Close), \ np.abs(self.atrBarWindow[5].Low - self.atrBarWindow[4].Close)]) array.append([self.atrBarWindow[6].High - self.atrBarWindow[6].Low, \ np.abs(self.atrBarWindow[6].High - self.atrBarWindow[5].Close), \ np.abs(self.atrBarWindow[6].Low - self.atrBarWindow[5].Close)]) array.append([self.atrBarWindow[7].High - self.atrBarWindow[7].Low, \ np.abs(self.atrBarWindow[7].High - self.atrBarWindow[6].Close), \ np.abs(self.atrBarWindow[7].Low - self.atrBarWindow[6].Close)]) array.append([self.atrBarWindow[8].High - self.atrBarWindow[8].Low, \ np.abs(self.atrBarWindow[8].High - self.atrBarWindow[7].Close), \ np.abs(self.atrBarWindow[8].Low - self.atrBarWindow[7].Close)]) array.append([self.atrBarWindow[9].High - self.atrBarWindow[9].Low, \ np.abs(self.atrBarWindow[9].High - self.atrBarWindow[8].Close), \ np.abs(self.atrBarWindow[9].Low - self.atrBarWindow[8].Close)]) array.append([self.atrBarWindow[10].High - self.atrBarWindow[10].Low, \ np.abs(self.atrBarWindow[10].High - self.atrBarWindow[9].Close), \ np.abs(self.atrBarWindow[10].Low - self.atrBarWindow[9].Close)]) array.append([self.atrBarWindow[11].High - self.atrBarWindow[11].Low, \ np.abs(self.atrBarWindow[11].High - self.atrBarWindow[10].Close), \ np.abs(self.atrBarWindow[11].Low - self.atrBarWindow[10].Close)]) array.append([self.atrBarWindow[12].High - self.atrBarWindow[12].Low, \ np.abs(self.atrBarWindow[12].High - self.atrBarWindow[11].Close), \ np.abs(self.atrBarWindow[12].Low - self.atrBarWindow[11].Close)]) array.append([self.atrBarWindow[13].High - self.atrBarWindow[13].Low, \ np.abs(self.atrBarWindow[13].High - self.atrBarWindow[12].Close), \ np.abs(self.atrBarWindow[13].Low - self.atrBarWindow[12].Close)]) ########################################################################## # Grabbing 14 True Ranges def max(i): max_value = i[0] for number in i: if number > max_value: max_value = number return max_value for i in array: self.true_range.append(max(i)) self.current_true_range = self.true_range[0] # The Average True Range avg_true_range = [] def AvgTrueRange (l): avg = sum(l)/len(l) return avg avg_true_range.append(AvgTrueRange(self.true_range)) ''' SMOOTHING FACTOR FORMULA ------------------------ EXPONENTIAL -> ((2/(n + 1)) * TR[0]) + (1-(2/(n+1))) * ATR[1] WILDERS -> (1/n) * TR[0]) + (1-(1/n)) * ATR[1] '''