Visualization API
Price chart visualizations using Plotly.
Provides interactive price charts including: - Candlestick charts - OHLCV charts with volume - Multi-ticker comparison - Price with moving averages
- quantlab.visualization.price_charts.create_candlestick_chart(df, ticker, show_volume=True, show_range_selector=True, height=600, intraday=False)[source]
Create interactive OHLC candlestick chart with optional volume.
- Parameters:
- Return type:
Figure- Returns:
Plotly figure object
Example
>>> import pandas as pd >>> df = pd.DataFrame({ ... 'date': pd.date_range('2024-01-01', periods=30), ... 'open': np.random.randn(30).cumsum() + 100, ... 'high': np.random.randn(30).cumsum() + 102, ... 'low': np.random.randn(30).cumsum() + 98, ... 'close': np.random.randn(30).cumsum() + 100, ... 'volume': np.random.randint(1000000, 5000000, 30) ... }) >>> fig = create_candlestick_chart(df, ticker="AAPL") >>> fig.show()
- quantlab.visualization.price_charts.create_price_line_chart(df, ticker, price_column='close', show_volume=False, moving_averages=None, height=600, intraday=False)[source]
Create line chart for price with optional moving averages.
- Parameters:
df (
DataFrame) – DataFrame with columns: date, price_column, (optional) volumeticker (
str) – Stock ticker symbolprice_column (
str) – Column to use for price (default: ‘close’)show_volume (
bool) – Include volume subplotmoving_averages (
Optional[List[int]]) – List of MA periods (e.g., [20, 50, 200])height (
int) – Chart height in pixels
- Return type:
Figure- Returns:
Plotly figure object
Example
>>> fig = create_price_line_chart( ... df, ... ticker="AAPL", ... moving_averages=[20, 50, 200] ... ) >>> fig.show()
- quantlab.visualization.price_charts.create_multi_ticker_comparison(data_dict, price_column='close', normalize=True, height=600)[source]
Create comparison chart for multiple tickers.
- Parameters:
- Return type:
Figure- Returns:
Plotly figure object
Example
>>> data = { ... 'AAPL': df_aapl, ... 'GOOGL': df_googl, ... 'MSFT': df_msft ... } >>> fig = create_multi_ticker_comparison(data, normalize=True) >>> fig.show()
Options strategy visualization charts using Plotly.
Provides interactive visualizations for options including: - Payoff diagrams - Greeks surface plots (2D and 3D) - Options chain heatmaps - Greeks timeline projections
- quantlab.visualization.options_charts.create_payoff_diagram(prices, pnls, strategy_name, current_price, breakeven_points=None, max_profit=None, max_loss=None, height=600)[source]
Create interactive options strategy payoff diagram.
- Parameters:
- Return type:
Figure- Returns:
Plotly figure object
Example
>>> prices = np.linspace(90, 110, 100) >>> pnls = np.maximum(prices - 100, 0) - 5 # Long call at 100, premium 5 >>> fig = create_payoff_diagram( ... prices, pnls, ... strategy_name="Long Call", ... current_price=100, ... breakeven_points=[105], ... max_profit=None, # Unlimited ... max_loss=-500 ... ) >>> fig.show()
- quantlab.visualization.options_charts.create_greeks_heatmap(greeks_data, greek_name='delta', height=600)[source]
Create heatmap showing Greek values across strikes and expirations.
- Parameters:
- Return type:
Figure- Returns:
Plotly figure object
Example
>>> df = pd.DataFrame({ ... 'strike': [95, 100, 105] * 3, ... 'expiration': ['2024-01-01'] * 3 + ['2024-02-01'] * 3 + ['2024-03-01'] * 3, ... 'delta': [0.8, 0.5, 0.2, 0.7, 0.5, 0.3, 0.6, 0.5, 0.4] ... }) >>> fig = create_greeks_heatmap(df, greek_name='delta') >>> fig.show()
- quantlab.visualization.options_charts.create_greeks_timeline(timeline_data, strategy_name, greeks_to_show=None, height=700)[source]
Create timeline showing Greeks evolution over time.
- Parameters:
- Return type:
Figure- Returns:
Plotly figure object with subplots
Example
>>> df = pd.DataFrame({ ... 'days_forward': range(0, 30), ... 'delta': np.random.randn(30).cumsum() + 50, ... 'gamma': np.random.randn(30).cumsum() + 5, ... 'theta': np.random.randn(30).cumsum() - 10, ... 'vega': np.random.randn(30).cumsum() + 20 ... }) >>> fig = create_greeks_timeline(df, strategy_name="Long Call") >>> fig.show()
- quantlab.visualization.options_charts.create_greeks_3d_surface(price_range, time_range, greek_values, greek_name, strategy_name, current_price, height=700)[source]
Create 3D surface plot showing Greek sensitivity to price and time.
- Parameters:
price_range (
ndarray) – Array of underlying pricestime_range (
ndarray) – Array of days forwardgreek_values (
ndarray) – 2D array of Greek values (time × price)greek_name (
str) – Name of Greek (delta, gamma, theta, vega)strategy_name (
str) – Name of options strategycurrent_price (
float) – Current underlying priceheight (
int) – Chart height in pixels
- Return type:
Figure- Returns:
Plotly figure object
Example
>>> prices = np.linspace(90, 110, 50) >>> days = np.linspace(0, 30, 30) >>> P, D = np.meshgrid(prices, days) >>> delta_values = 0.5 * np.exp(-(P - 100)**2 / 100) * (1 - D / 30) >>> fig = create_greeks_3d_surface( ... prices, days, delta_values, ... greek_name='delta', ... strategy_name='Long Call', ... current_price=100 ... ) >>> fig.show()
- quantlab.visualization.options_charts.create_strategy_comparison(comparison_data, current_price, height=600)[source]
Create comparison chart for multiple options strategies.
- Parameters:
- Return type:
Figure- Returns:
Plotly figure object
Example
>>> prices = np.linspace(90, 110, 100) >>> data = { ... 'Long Call': (prices, np.maximum(prices - 100, 0) - 5), ... 'Long Put': (prices, np.maximum(100 - prices, 0) - 5), ... 'Straddle': (prices, np.abs(prices - 100) - 10) ... } >>> fig = create_strategy_comparison(data, current_price=100) >>> fig.show()