-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_options.py
More file actions
64 lines (49 loc) · 1.93 KB
/
Copy pathdebug_options.py
File metadata and controls
64 lines (49 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""
Debug script to check options chain data
"""
import yfinance as yf
import pandas as pd
def debug_options_chain(symbol="AAPL"):
print(f"=== Debugging Options Chain for {symbol} ===")
try:
stock = yf.Ticker(symbol)
# Get expirations
expirations = stock.options
print(f"Available expirations: {expirations[:3]}") # First 3
if not expirations:
print("❌ No expirations found!")
return
# Get option chain for first expiration
exp = expirations[0]
print(f"Using expiration: {exp}")
option_chain = stock.option_chain(exp)
print(f"\n=== CALLS ===")
calls = option_chain.calls
print(f"Calls shape: {calls.shape}")
print(f"Calls columns: {list(calls.columns)}")
print(f"Sample calls data:")
print(calls[['strike', 'bid', 'ask', 'lastPrice', 'volume']].head())
print(f"\n=== PUTS ===")
puts = option_chain.puts
print(f"Puts shape: {puts.shape}")
print(f"Puts columns: {list(puts.columns)}")
print(f"Sample puts data:")
print(puts[['strike', 'bid', 'ask', 'lastPrice', 'volume']].head())
# Check current stock price
hist = stock.history(period="1d")
current_price = hist['Close'].iloc[-1]
print(f"\nCurrent stock price: ${current_price:.2f}")
# Find ATM options
atm_call = calls.iloc[(calls['strike'] - current_price).abs().argsort()[:1]]
atm_put = puts.iloc[(puts['strike'] - current_price).abs().argsort()[:1]]
print(f"\n=== ATM CALL ===")
print(atm_call[['strike', 'bid', 'ask', 'lastPrice']])
print(f"\n=== ATM PUT ===")
print(atm_put[['strike', 'bid', 'ask', 'lastPrice']])
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
debug_options_chain("AAPL")