Skip to content
pip install yfinance
import yfinance as yf

def fetch_options_chain(symbol):
    # Create a Ticker object
    ticker = yf.Ticker(symbol)

    # Get available expiration dates
    exp_dates = ticker.options

    if not exp_dates:
        print("No options data found.")
        return

    # Use the first expiration date for demonstration
    exp_date = exp_dates[0]
    print(f"Fetching options data for {symbol} expiring on {exp_date}...")

    # Fetch options chain for the given expiration date
    options_chain = ticker.option_chain(exp_date)

    # Display calls and puts
    print("\nCALLS:")
    print(options_chain.calls)

    print("\nPUTS:")
    print(options_chain.puts)

def main():
    symbol = input("Enter the stock symbol (e.g., AAPL): ")
    fetch_options_chain(symbol)

if __name__ == "__main__":
    main()