Innaccurate Historical Data
WhileE opened this issue · comments
Description
Inaccurate historical data for some equities. I just threw together a simple test to look at data visualization options, and immediately noticed some oddities with TQQQ/SQQQ, same code works perfectly fine with AAPL?
Is there something I'm missing because they're ETF's, or is there an underlying bug that I'm not aware of? I searched a bit in the issues, but didn't see anything related.
Code
def init(symbol, state: StrategyState):
interface: Interface = state.interface
resolution: float = state.resolution
variables = state.variables
variables["history"] = interface.history(symbol, 800, resolution, return_as='deque')["close"]
def bar_event(bar, symbol, state):
pass
if __name__ == "__main__":
alpaca = Alpaca()
s = Strategy(alpaca)
s.add_bar_event(bar_event, "AAPL", resolution="1d", init=init)
result = s.backtest(initial_values={"USD": 1000}, to="3y", GUI_output=False)
history = result.history['AAPL']
fig = make_subplots(rows=1, cols=1, shared_xaxes=True, vertical_spacing=None)
fig.add_trace(
go.Candlestick(
x=pd.to_datetime(history.time,unit='s'),
open=history.open,
high=history.high,
low=history.low,
close=history.close),
col=1,row=1
)
fig.show()
TQQQ in Blankly
TQQQ Actual
AAPL in Blankly
AAPL Actual
Interesting, so under the hood the code is the same, we're just quering alpaca using the same symbols. It would most likely be some difference that alpaca is giving the data back to us or us dropping sets of data. Back when I wrote this in 2021 alpaca had a few weird history bugs like this on their end but maybe they're resolved now. I'll try to replicate on my end.
I figured it was in Alpaca, but didn't have the time to dig in today. It's odd, it looks like the first "chunk" of data on TQQQ is almost acting like it is using '100' as a baseline/offset, then the next chunk looks like it is using '50' as a baseline/offset, and then it normalizes.