The Challenge
Options pricing traditionally requires expensive institutional tools or complex spreadsheets. We wanted to build a unified tool that could:
- Fetch real-time market data from TradingView
- Model volatility using statistical methods
- Price options with Monte Carlo simulations
- Predict price direction using machine learning
- Present everything in an interactive dashboard
Architecture Overview
The tool consists of five integrated components:
- Data Pipeline - WebSocket integration with TradingView
- Storage Layer - SQLite for efficient time-series queries
- Options Pricing Engine - GARCH + Monte Carlo
- ML Forecasting - Temporal Fusion Transformer
- Dashboard - Streamlit with Plotly visualizations
GARCH Volatility Modeling
The heart of options pricing is volatility estimation. Rather than using simple historical volatility (standard deviation of returns), we implemented GARCH(1,1) — Generalized Autoregressive Conditional Heteroskedasticity.
Why GARCH?
Financial markets exhibit volatility clustering: periods of high volatility tend to follow high volatility, and calm periods follow calm periods. Standard deviation treats all historical periods equally, but GARCH captures this time-varying nature.
The GARCH(1,1) model:
Where:
- is the long-term average variance
- captures how much recent shocks affect current volatility
- captures volatility persistence
Implementation Details
We used the arch library for GARCH fitting. One critical lesson: numerical scaling matters. Financial returns are typically very small numbers (0.01 = 1%), which can cause optimization issues. We scale returns by 100x during fitting, then rescale the forecasted variance.
from arch import arch_model
# Scale returns for numerical stability
scaled_returns = returns * 100
# Fit GARCH(1,1)
model = arch_model(scaled_returns, vol='Garch', p=1, q=1)
result = model.fit(disp='off')
# Get annualized volatility
daily_var = result.forecast(horizon=1).variance.values[-1, 0]
daily_vol = np.sqrt(daily_var) / 100 # Rescale
annual_vol = daily_vol * np.sqrt(252)
Monte Carlo Options Pricing
With volatility estimated, we simulate thousands of possible price paths to option expiry using Monte Carlo methods.
The Process
- Generate random returns from a normal distribution scaled by GARCH volatility
- Simulate price paths using geometric Brownian motion
- Calculate option payoffs at expiry for each path
- Average the payoffs to get option price
def simulate_paths_garch(spot, garch_result, days_to_expiry, n_simulations=10000):
"""Simulate price paths with time-varying GARCH volatility."""
omega = garch_result.params['omega']
alpha = garch_result.params['alpha[1]']
beta = garch_result.params['beta[1]']
paths = np.zeros((n_simulations, days_to_expiry + 1))
paths[:, 0] = spot
# Initialize variance from last fitted value
variance = np.full(n_simulations, garch_result.conditional_volatility[-1]**2)
for t in range(1, days_to_expiry + 1):
# Sample shocks
z = np.random.standard_normal(n_simulations)
# Returns driven by current (time-varying) volatility
returns = np.sqrt(variance) * z
paths[:, t] = paths[:, t-1] * np.exp(returns / 100) # Rescale
# Update variance for next step (GARCH dynamics)
variance = omega + alpha * (returns**2) + beta * variance
return paths
The key difference from constant-volatility Monte Carlo: variance evolves at each time step following GARCH dynamics. This captures volatility clustering - if we hit a large shock, subsequent steps will have elevated volatility.
ML-Based Directional Forecasting
Beyond options pricing, we wanted to predict price direction using machine learning. We implemented a Temporal Fusion Transformer (TFT) — a state-of-the-art architecture for time series forecasting.
Feature Engineering
The model uses 17+ technical indicators as features:
- Price-based: Log returns at multiple horizons (1d, 5d, 20d)
- Moving averages: SMA-20, SMA-50, EMA-12, EMA-26
- Momentum: MACD, RSI(14)
- Volatility: Bollinger Bands, rolling standard deviation
- Volume: Volume/SMA ratio
- Temporal: Hour, day of week, month
Horizon Selection
We tested prediction horizons from 1 hour to 50 hours. The results were illuminating:
| Horizon | Directional Accuracy |
|---|---|
| 1h | 57.4% |
| 5h | 54.0% |
| 10h | 64.5% |
| 20h | 55.5% |
| 50h | 41.7% |
The 10-hour horizon hit the sweet spot — long enough for the model to capture meaningful patterns, short enough to maintain signal quality.
Interactive Dashboard
Everything comes together in a Streamlit dashboard that provides:
- Candlestick charts with technical indicator overlays
- Options pricing panel with strike/expiry inputs
- Monte Carlo visualization showing simulated price paths
- ML predictions with entry/exit signals
The dashboard fetches data from SQLite, runs calculations on-demand, and renders interactive Plotly charts.
Key Learnings
- Numerical stability is crucial — GARCH optimization fails silently with unscaled data
- Horizon selection matters for ML — longer isn't better for price prediction
- Feature engineering beats model complexity — good indicators outperform fancy architectures
- Integration is the hard part — connecting data, models, and UI cleanly takes effort
Results
The finished tool provides:
- Real-time data from any TradingView symbol
- GARCH-based volatility estimates
- Monte Carlo options pricing with 10,000 simulations
- 64.5% directional accuracy on 10-hour predictions
- All in an interactive, self-contained dashboard
The full source code is available on GitHub.
Building trading tools or financial applications? Contact us to discuss your project.
