-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_options_simple.py
More file actions
59 lines (46 loc) · 1.83 KB
/
Copy pathtest_options_simple.py
File metadata and controls
59 lines (46 loc) · 1.83 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
#!/usr/bin/env python3
"""
Simple test of options data access
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
try:
import yfinance as yf
print("Testing options chain access...")
stock = yf.Ticker("AAPL")
# Get current price
hist = stock.history(period="1d")
current_price = float(hist['Close'].iloc[-1])
print(f"Current AAPL price: ${current_price:.2f}")
# Get expirations
expirations = stock.options
print(f"Found {len(expirations)} expirations")
if expirations:
exp = expirations[0]
print(f"Using expiration: {exp}")
# Get options chain
option_chain = stock.option_chain(exp)
calls = option_chain.calls
print(f"Calls dataframe shape: {calls.shape}")
print(f"Calls columns: {list(calls.columns)}")
# Show first few rows with relevant columns
if not calls.empty:
relevant_cols = ['strike', 'bid', 'ask', 'lastPrice', 'volume']
available_cols = [col for col in relevant_cols if col in calls.columns]
print(f"Available relevant columns: {available_cols}")
print("First 3 calls:")
print(calls[available_cols].head(3))
# Test accessing a specific strike
target_strike = calls['strike'].iloc[2] # 3rd option
matching_call = calls[calls['strike'] == target_strike].iloc[0]
print(f"\nTesting strike ${target_strike}:")
print(f"Type: {type(matching_call)}")
print(f"Ask price: {matching_call['ask'] if 'ask' in matching_call else 'N/A'}")
print(f"Bid price: {matching_call['bid'] if 'bid' in matching_call else 'N/A'}")
else:
print("No expirations found!")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()