SPB Git

Repository Public

quant-job-options.json 3.4 KB 1 lines json

1{"job":{"id":"b291ea56-d9b6-481f-abb4-ab1313c1e570","tool":"options","params":{"symbol":"AAPL","strike_price":250,"time_to_maturity":0.5,"risk_free_rate":0.05,"option_type":"call"},"status":"done","startedAt":1795041106557,"finishedAt":1795041111423,"error":null,"code":"import math\nfrom scipy import stats\nfrom fmpClient import get_historical_prices, get_stock_quote, calculate_historical_volatility\n\n# Fetch market data for AAPL\nsymbol = 'AAPL'\nprint(f\"Fetching market data for {symbol}...\")\n\n# Get current stock price\nquote = get_stock_quote(symbol)\nS = quote['price']\nprint(f\"Current stock price: $\\{S:.2f}\")\n\n# Get historical prices\nhist_data = get_historical_prices(symbol)\nclosing_prices = [h['close'] for h in reversed(hist_data['historical'])]\n\n# Calculate or use provided volatility\n# Calculate 30-day historical volatility\nrecent_prices = closing_prices[-30:] if len(closing_prices) >= 30 else closing_prices\nsigma = calculate_historical_volatility(recent_prices, annualize=True)\nprint(f\"Calculated 30-day historical volatility: {sigma*100:.2f}%\")\n\n# Black-Scholes Option Pricing Parameters\nK = 250  # Strike price\nT = 0.5  # Time to maturity (years)\nr = 0.05  # Risk-free rate\n\n# Calculate d1 and d2\nd1 = (math.log(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * math.sqrt(T))\nd2 = d1 - sigma * math.sqrt(T)\n\n# Calculate Call Option Price\ncall_price = S * stats.norm.cdf(d1) - K * math.exp(-r * T) * stats.norm.cdf(d2)\n\n# Calculate Put Option Price\nput_price = K * math.exp(-r * T) * stats.norm.cdf(-d2) - S * stats.norm.cdf(-d1)\n\n# Calculate Greeks\n# Delta\ncall_delta = stats.norm.cdf(d1)\nput_delta = call_delta - 1\n\n# Gamma (same for call and put)\ngamma = stats.norm.pdf(d1) / (S * sigma * math.sqrt(T))\n\n# Vega (same for call and put)\nvega = S * stats.norm.pdf(d1) * math.sqrt(T) / 100\n\n# Theta\ncall_theta = (-(S * stats.norm.pdf(d1) * sigma) / (2 * math.sqrt(T))\n              - r * K * math.exp(-r * T) * stats.norm.cdf(d2)) / 365\n\nput_theta = (-(S * stats.norm.pdf(d1) * sigma) / (2 * math.sqrt(T))\n             + r * K * math.exp(-r * T) * stats.norm.cdf(-d2)) / 365\n\n# Rho\ncall_rho = K * T * math.exp(-r * T) * stats.norm.cdf(d2) / 100\nput_rho = -K * T * math.exp(-r * T) * stats.norm.cdf(-d2) / 100\n\nprint(f\"Call Option Price: $\\{call_price:.4f}\")\nprint(f\"Put Option Price: $\\{put_price:.4f}\")\nprint(f\"\\nCall Greeks:\")\nprint(f\"  Delta: \\{call_delta:.4f}\")\nprint(f\"  Gamma: \\{gamma:.4f}\")\nprint(f\"  Theta: \\{call_theta:.4f}\")\nprint(f\"  Vega: \\{vega:.4f}\")\nprint(f\"  Rho: \\{call_rho:.4f}\")\nprint(f\"\\nPut Greeks:\")\nprint(f\"  Delta: \\{put_delta:.4f}\")\nprint(f\"  Gamma: \\{gamma:.4f}\")\nprint(f\"  Theta: \\{put_theta:.4f}\")\nprint(f\"  Vega: \\{vega:.4f}\")\nprint(f\"  Rho: \\{put_rho:.4f}\")","result":{"success":true,"parameters":{"stock_price":352.45,"strike_price":250,"time_to_maturity":0.5,"risk_free_rate":0.05,"volatility":0.2345,"option_type":"call"},"call_option":{"price":108.8449,"intrinsic_value":102.45,"time_value":6.3949,"greeks":{"delta":0.9894,"gamma":0.0005,"theta":-0.0373,"vega":0.0698,"rho":1.1994},"moneyness":"ITM"},"put_option":{"price":0.2224,"intrinsic_value":0,"time_value":0.2224,"greeks":{"delta":-0.0106,"gamma":0.0005,"theta":-0.0039,"vega":0.0698,"rho":-0.0198},"moneyness":"OTM"},"parity_check":{"call_minus_put":108.6225,"stock_minus_pv_strike":108.6225,"parity_holds":true}}}}
Files main
Menu

Theme