Historical stock data very wrong

Bellow is the stock data pulled from the python SDK vs the website trading data for AAPL (apparently i can only ). Past a certain point in time the data becomes unreliable - i have seen this for multiple stocks. Can anyone help me bugcheck this issue

            symbols = ['AAPL']
            timeframe = TimeFrame.Day
            start = datetime(2020, 7, 1)
            end = datetime(2020, 10, 1)

            stock_bars_request = StockBarsRequest(
                symbol_or_symbols=symbols,
                timeframe=timeframe,
                start=start,
                end=end
            )
            
            return self.data_engineering(stock_client.get_stock_bars(stock_bars_request).df)

Running some historical tests locally and also noticed the price data is dramatically off.

The call for AMZN with a 1 minute bar for January 03, 2022:

curl --location 'https://data.alpaca.markets/v2/stocks/AMZN/bars?timeframe=1Min&start=2022-01-03T14%3A30%3A00Z' \
--header 'APCA-API-KEY-ID: #################' \
--header 'APCA-API-SECRET-KEY: #################

Yields an insane price of over $3000 (should be in the ballpark of $160):

{
    "bars": [
        {
            "t": "2022-01-03T14:30:00Z",
            "o": 3352.01,
            "h": 3361.7,
            "l": 3351,
            "c": 3360.7999,
            "v": 97077,
            "n": 7826,
            "vw": 3354.843258
        },
   ...
}

The call for TSLA 1 minute bar for January 03, 2022:

curl --location 'https://data.alpaca.markets/v2/stocks/TSLA/bars?timeframe=1Min&start=2022-01-03T14%3A30%3A00Z' \
--header 'APCA-API-KEY-ID: #################' \
--header 'APCA-API-SECRET-KEY: #################

Also yields an inflated price of over $1000 (should be in the ballpark of $350):

{
    "bars": [
        {
            "t": "2022-01-03T14:30:00Z",
            "o": 1147.75,
            "h": 1149.2911,
            "l": 1140.28,
            "c": 1142.83,
            "v": 790070,
            "n": 37532,
            "vw": 1145.675329
        },
  ...
}

What is going on here?

1 Like

Yeah I am having similar issues where historical price form the API returns 2.66 while it is ~114 on the website and other sources. Have you reached out to support?

1 Like

Yeah i sorted it - the last line here is important and not overly advertised in the docs

            stock_bars_request = StockBarsRequest(
                symbol_or_symbols=stock_data_request.symbols,
                timeframe=stock_data_request.timeframe,
                start=stock_data_request.start,
                end=stock_data_request.end,
                adjustment=Adjustment('all')
            )

link to relevant bit in the docs: Enums - Alpaca-py

I think Apples stock was split in August 2020 - which is the period of time that in my screenshot that shows the drop from around $500 to around $150 - so the screenshots i provided are actually correct and some adjustment has to be done to counter this. i think using adjustment=Adjustment(‘split’) is sufficient to solve for this specific instance.

Thanks. It did the trick! Good find! :+1: