Wrong historical data for past 4 years

My code is below. It tres to get bars data of last 4 years:

current_date = datetime.now()
days_ago = current_date - timedelta(days=4*365)
start_time = pd.to_datetime(days_ago).tz_localize('America/New_York')
request_params = StockBarsRequest(
    symbol_or_symbols="TQQQ",
    timeframe=TimeFrame.Day,
    start=start_time
)
bars_df = data_client.get_stock_bars(request_params).df.tz_convert('America/New_York', level=1)

Data from above code of Alpaca:

symbol.               timestamp           open      high     low   close                                             
TQQQ         2020-08-13 00:00:00-04:00  128.0800  131.1800  126.53  127.90   
             2020-08-14 00:00:00-04:00  128.6600  129.1900  125.41  127.53   
             2020-08-17 00:00:00-04:00  129.8700  132.3600  129.66  131.74   
             2020-08-18 00:00:00-04:00  133.4300  136.4001  131.29  135.61  

From Yahoo-Finance. the data is

All values are different.

Any ideas how to get the right data ?
BTW, I tried both paper and live account. Data from both are wrong.

@goon1983 By default the Alpaca prices are the ‘raw’ prices. Those are the actual traded prices on those days. The Yahoo data is ‘split adjusted’. Their prices account for stock splits so one can more easily compare current to past prices (without large price jumps if/when there is a stock split). You can fetch split adjusted data from Alpaca too. Simply add the parameter adjustment='split'. It’s also a good practice to explicitly specify the data feed (typically one wants SIP data). Something like this

request_params = StockBarsRequest(
    symbol_or_symbols="TQQQ",
    timeframe=TimeFrame.Day,
    start=start_time,
    adjustment='split',
    feed='sip'
)

You will then get data which matches the Yahoo data.

Additionally, it doesn’t matter whether you access data from a paper or live account. The data is the same. The data subscription is tied to the owner_id. The only thing the account number is used for is to lookup the owner_id.

Thanks @Dan_Whitnable_Alpaca for clarification.

BTW,

  1. how long we can go back for historical data now? 5 years for regular user?

@goon1983 Alpaca has historical equity data beginning 2016-01-04 (8+ years). This same data is available for both the free Basic and the paid data subscriptions.

1 Like

Thanks @Dan_Whitnable_Alpaca . Another question about extra sticker in get_stock_bars.

I used the blow code to get bars data of a list of symbols but it returns extra ones. Below is the example. The BIOS is not in my required list but get_stock_bars returns its data.
Any idea to explain this?

required symbols:  {'ATXS', 'BOTT', 'SLAB', 'BYFC', 'NRIX', 'UDMY', 'BLBD', 'GHIXU', 'ATHA', 'ADUS', 'MTEKW', 'LUNG', 'DXR', 'JTEK', 'MGNX', 'BOCNU', 'RVSN', 'FYC', 'INDB', 'CNXN', 'TVGN', 'IROHR', 'GSMGW', 'CARV', 'RICK', 'BNOX', 'SPRO', 'BYNOU', 'CAFG', 'IVDAW', 'ICLN', 'PITA', 'DHAIW', 'NVDU', 'BRNS', 'INDY', 'WRAP', 'UAL', 'DTST', 'IPXX', 'AIMDW', 'AGNCN', 'SDA', 'TETE', 'METU', 'KYTX', 'LLYVA', 'CYCCP', 'CRGOW', 'WRND', 'VACHU', 'AFRM', 'HPAI', 'FLEX', 'OCGN', 'PXLW', 'LNTH', 'INNV', 'CDTX', 'BNIX', 'VC', 'COLM', 'INO', 'IAC', 'PLUS', 'TTGT', 'OPCH', 'FTNT', 'ATMC', 'MSEX', 'RPRX', 'UTRE', 'INTC', 'AACIW', 'HQGO', 'ARTW', 'AIQ', 'BABX', 'VFLO', 'CROX', 'LFMDP', 'STRS', 'CCLDO', 'FSTR', 'SEEL', 'RGF', 'DPRO', 'FPXE', 'WTMA', 'WISA', 'FCEF', 'IMOM', 'PWOD', 'BULD', 'GOGO', 'SMMT', 'PTEC', 'MCSE', 'MGX', 'WGMI'}
returned symbols {'ATXS', 'BOTT', 'SLAB', 'BYFC', 'NRIX', 'UDMY', 'BLBD', 'GHIXU', 'ATHA', 'ADUS', 'MTEKW', 'BIOS', 'DXR', 'LUNG', 'JTEK', 'MGNX', 'BOCNU', 'RVSN', 'FYC', 'INDB', 'CNXN', 'TVGN', 'IROHR', 'GSMGW', 'CARV', 'RICK', 'BNOX', 'SPRO', 'BYNOU', 'CAFG', 'IVDAW', 'ICLN', 'PITA', 'DHAIW', 'NVDU', 'BRNS', 'INDY', 'WRAP', 'UAL', 'DTST', 'AIMDW', 'AGNCN', 'SDA', 'TETE', 'METU', 'KYTX', 'LLYVA', 'CYCCP', 'CRGOW', 'WRND', 'VACHU', 'AFRM', 'HPAI', 'FLEX', 'OCGN', 'PXLW', 'LNTH', 'INNV', 'CDTX', 'BNIX', 'VC', 'COLM', 'INO', 'IAC', 'PLUS', 'OPCH', 'TTGT', 'FTNT', 'ATMC', 'MSEX', 'RPRX', 'UTRE', 'INTC', 'AACIW', 'HQGO', 'WGMI', 'ARTW', 'AIQ', 'BABX', 'VFLO', 'CROX', 'LFMDP', 'STRS', 'CCLDO', 'FSTR', 'RGF', 'SEEL', 'DPRO', 'FPXE', 'WTMA', 'WISA', 'FCEF', 'IMOM', 'PWOD', 'BULD', 'GOGO', 'SMMT', 'PTEC', 'MCSE', 'MGX', 'IPXX'}
Warning: Extra symbols found in data: {'BIOS'}

Below is the code

request_params = StockBarsRequest(
            symbol_or_symbols=tickers_batch,
            timeframe=TimeFrame.Day,
            start=start_time,
            adjustment='all',
            feed='sip'
        )
        # Fetch data and convert time zone
        bars_df = data_client.get_stock_bars(request_params).df
        
        if not bars_df.empty:
            requested_symbols = set(tickers_batch)
            returned_symbols = set(bars_df.index.get_level_values('symbol'))
            extra_symbols = returned_symbols - requested_symbols
            if extra_symbols:
                print("required symbols: ", set(tickers_batch))
                print("returned symbols", set(bars_df.index.get_level_values('symbol')))
                print(f"Warning: Extra symbols found in data: {extra_symbols}")

@goon1983 Option Care Health, Inc. (OPCH) changed its symbol from BIOS to OPCH on 2020-02-03. For some reason, there is exactly one bar for BIOS on 2020-02-03 probably related to that symbol change. All the data for OPCH (ie the new symbol is correct and carries backwards to the old symbol (ie 2020-02-03 is not missing). I’ve notified the Data Team to look into this. Thanks for bringing it up.

1 Like