| Overall Statistics |
|
Total Orders 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Start Equity 100000.00 End Equity 100000 Net Profit 0% Sharpe Ratio 0 Sortino 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 3.672 Tracking Error 0.05 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset Portfolio Turnover 0% |
# region imports
from AlgorithmImports import *
# endregion
# Your New Python File
class TrailingDataSamplesHistoryAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2021, 4, 30)
self.set_end_date(2021, 5, 4)
self.SetWarmUp(300)
# Get the Symbol of an asset.
self.ticker = 'EURHUF'
self.symbol = self.add_forex(self.ticker, Resolution.DAILY).symbol
self.sma200 = self.sma(self.symbol, 200, Resolution.DAILY)
self.bar_period = timedelta(days=1)
self.data = {}
self.data[self.ticker] = SymbolData(self)
def on_data(self, data):
if self.is_warming_up: return
if self.sma200.is_ready:
# The current value of self.sma200 is represented by self.sma200.current.value
self.plot("SimpleMovingAverage", "sma from automatic indicator", self.sma200.current.value)
self.plot("SimpleMovingAverage", "sma from SymbolData (consolidated)", self.data[self.ticker].sma200.current.value)
self.plot("SimpleMovingAverage", "sma from SymbolData registered with algorithm", self.data[self.ticker].sma200_algoregistered.current.value)
if self.Time.date() == datetime(2021, 5, 2).date():
history = self.history(self.symbol, 200, Resolution.DAILY)
last = history['close'].rolling(200).mean().iloc[-1]
self.log(f"sma from automatic indicator {self.sma200.current.value} , rolling sma from history call {last} , equal? {self.sma200.current.value == last}")
self.log(f"sma from SymbolData (consolidated) {self.data[self.ticker].sma200} -> different from above? why?")
self.log(f"sma from SymbolData registered with algorithm {self.data[self.ticker].sma200_algoregistered}")
class SymbolData:
def __init__(self, algorithm):
self.algorithm = algorithm
self.bar_period = self.algorithm.bar_period
self.bars = RollingWindow[QuoteBar](2)
self.consolidator = QuoteBarConsolidator(self.bar_period)
self.consolidator.data_consolidated += self.consolidation_handler
self.algorithm.subscription_manager.add_consolidator(self.algorithm.symbol, self.consolidator)
self.sma200 = SimpleMovingAverage(200)
self.sma200_algoregistered = SimpleMovingAverage(200)
self.algorithm.register_indicator(self.algorithm.ticker, self.sma200_algoregistered, Resolution.DAILY)
def consolidation_handler(self, sender, bar: QuoteBar):
self.bars.add(bar)
self.sma200.update(bar.end_time, bar.close)