Historical EOD optons price

Hi,

How to reliably get the historical eod price for a given option?

  1. I don’t think you can get historical L1 bars, only ohlcv bars
  2. Even if I settle for ohlcv and go by last trade as closing price, the OptionsBarsRequest (Requests - Alpaca-py) method seems to take start and end times, with just putting in end not being an option it seems. So it’s unclear to me how to in this case just get eod, since you’re forced to provide a start, based on the liquidity of the option you might end up either not getting any data or getting more than a page.

@Linkus To get end of day prices for options use the get_option_bars and set timeframe=TimeFrame.Day (using the alpaca-py python SDK). The close price will be the price of the last contract traded that day.

Below is some sample code to fetch daily bars for two contracts (AAPL251017C00110000, AAPL251017C00175000) for the past 30 days. Using the .df method converts the result to a convenient dataframe.

!pip install -q alpaca-py

import pandas as pd

from alpaca.data.historical import OptionHistoricalDataClient
from alpaca.data.requests import OptionBarsRequest
from alpaca.data.timeframe import TimeFrame

# instantiate the options client
option_data_client = OptionHistoricalDataClient(api_key=DATA_KEY, secret_key=DATA_SECRET)

request = OptionBarsRequest(symbol_or_symbols='AAPL251017C00110000,AAPL251017C00175000',
                  timeframe=TimeFrame.Day,
                  start=pd.Timestamp('now', tz='America/New_York') - pd.Timedelta(days=30),
                  # omit the end parameter to default to the current day
                  )
daily_bars = option_data_client.get_option_bars(request).df

The above results in this dataframe

Notice there can be many days where there isn’t a bar. Many options do not trade much and may not have any trades on a specific day. In that case there will not be a bar. For example, the AAPL251017C00110000 contract had only a single trade in the past 30 days (albeit a large trade of 345 contracts).

Does that help?