Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Innaccurate Historical Data #248

Open
WhileE opened this issue Oct 5, 2023 · 2 comments
Open

Innaccurate Historical Data #248

WhileE opened this issue Oct 5, 2023 · 2 comments

Comments

@WhileE
Copy link

WhileE commented Oct 5, 2023

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-3y_1d

TQQQ Actual

ACTUAL_TQQQ-3y_1d

AAPL in Blankly

AAPL-3y_1d

AAPL Actual

ACTUAL_AAPL-3y_1d

@EmersonDove
Copy link
Member

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.

@WhileE
Copy link
Author

WhileE commented Oct 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants