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 0.099 Tracking Error 0.181 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
from AlgorithmImports import * from collections import deque import time class HistoryIndicatorTest(QCAlgorithm): def Initialize(self) -> None: self.SetStartDate(2021, 10, 1) #Set Start Date self.symbol = self.AddEquity("AAPL", Resolution.Daily).Symbol start = time.time() self.FetchWithHistoryCall() duration = time.time() - start self.Log(f"Fetch with History : {round(duration,6)} seconds ") start = time.time() self.FetchWitHistoryIndicator() duration = time.time() - start self.Log(f"Fetch w/ Indicator : {round(duration,6)} seconds ") # -------------------------------------------- # This is the old way to fetch history, slow. # -------------------------------------------- def FetchWithHistoryCall(self) -> None: history = self.History(self.symbol, 4000000, Resolution.Minute) # for bar in history.loc["AAPL"].itertuples(): # self.Log(bar.close) # ------------------------------------------------------- # This is the new way to fetch history, faster, maybe? # ------------------------------------------------------- def FetchWitHistoryIndicator(self) -> None: history = IdentityHistoryIndicator(4000000) self.WarmUpIndicator(self.symbol, history, Resolution.Minute) # for bar in history.History: # self.Log(bar.Close) class IdentityHistoryIndicator(PythonIndicator): def __init__(self, period, name="Identity History"): self.WarmUpPeriod = period self.Name = name self.Value = 0 self.queue = deque(maxlen=period) @property def History(self): return reversed(list(self.queue)) def Update(self, input: BaseData) -> bool: # self.queue.appendleft(input.Value) self.queue.appendleft(input) count = len(self.queue) self.Time = input.Time self.Value = count return count == self.queue.maxlen