Command-Line Interface (CLI)¶
This CLI package contains the main entry point and command structure for
the optpricing command-line interface.
backtest ¶
backtest(ticker: Annotated[str, Option('--ticker', '-t', help='The stock ticker to backtest.')], model: Annotated[list[str] | None, Option('--model', '-m', help="Model to backtest ('all' for every calibratable model). Can be used multiple times.")] = None, auto: Annotated[bool, Option('--auto', help='Use the settings tuned for this ticker (`optpricing tune`).')] = False, allow_mc: Annotated[bool, Option('--allow-mc', help='Also backtest simulation-only models (slow).')] = False, n_starts: Annotated[int, Option('--n-starts', help='Starting points per calibration.')] = 2, verbose: Annotated[bool, Option('--verbose', '-v', help='Enable detailed logging.')] = False)
Runs a walk-forward backtest (calibrate on day t, evaluate on day t+1).
Results are saved per model to artifacts/backtest_logs/ (per-period CSV,
bucket CSV and a JSON summary) and summarised in a table.
Source code in src/optpricing/cli/commands/backtest.py
print_backtest_summary ¶
Rich table of per-model backtest summaries (best out-of-sample first).
Source code in src/optpricing/cli/commands/backtest.py
calibrate ¶
calibrate(ticker: Annotated[str, Option('--ticker', '-t', help='The stock ticker to calibrate against.')], model: Annotated[list[str] | None, Option('--model', '-m', help="Model to calibrate ('all' for every calibratable model). Can be used multiple times.")] = None, date: Annotated[str | None, Option('--date', '-d', help='Snapshot date (YYYY-MM-DD). Defaults to latest available.')] = None, fix_param: Annotated[list[str] | None, Option('--fix', help="Fix a parameter (e.g., 'sigma=0.25'). Can be used multiple times.")] = None, auto: Annotated[bool, Option('--auto', help='Use the settings tuned for this ticker (`optpricing tune`).')] = False, allow_mc: Annotated[bool, Option('--allow-mc', help='Also calibrate simulation-only models (slow).')] = False, objective: Annotated[str, Option('--objective', help="Residual space: 'iv' or 'price'.")] = 'iv', n_starts: Annotated[int, Option('--n-starts', help='Starting points per model.')] = 4, verbose: Annotated[bool, Option('--verbose', '-v', help='Enable detailed logging.')] = False)
Calibrates one or more models to a market snapshot and ranks them.
With --model all every model that can be priced on a chain is fitted and a
leaderboard (sorted by evaluation IV RMSE) is printed and saved to
artifacts/calibration_logs/; parameters go to artifacts/calibrated_params/.
Source code in src/optpricing/cli/commands/calibrate.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
parse_fixed_params ¶
Parses key=value strings into a dict, exiting with a message on error.
Source code in src/optpricing/cli/commands/calibrate.py
print_leaderboard ¶
Rich table of per-model calibration results.
Source code in src/optpricing/cli/commands/calibrate.py
select_models ¶
Expands all and aliases; exits on unknown names.
Source code in src/optpricing/cli/commands/calibrate.py
dashboard ¶
Launches the Streamlit dashboard application.
Source code in src/optpricing/cli/commands/dashboard.py
download_data ¶
download_data(tickers: Annotated[list[str] | None, Option('--ticker', '-t', help='Stock ticker to download. Can be used multiple times.')] = None, all_default: Annotated[bool, Option('--all', help='Download all default tickers specified in config.yaml.')] = False, period: Annotated[str, Option('--period', '-p', help="Time period for historical data (e.g., '10y', '5y').")] = '10y', rates: Annotated[bool, Option('--rates', help='Also download the ^IRX (13-week T-bill) history used as the risk-free rate of older snapshots.')] = False)
Downloads historical prices, dividends and log returns (and optionally the risk-free rate history) for specified tickers or all defaults.
Source code in src/optpricing/cli/commands/data.py
get_dividends ¶
get_dividends(tickers: Annotated[list[str] | None, Option('--ticker', '-t', help='Stock ticker to fetch. Can be used multiple times.')] = None, all_default: Annotated[bool, Option('--all', help='Fetch for all default tickers specified in config.yaml.')] = False)
Fetches and displays the live forward dividend yield for specified tickers.
Source code in src/optpricing/cli/commands/data.py
save_snapshot ¶
save_snapshot(tickers: Annotated[list[str] | None, Option('--ticker', '-t', help='Stock ticker to snapshot. Can be used multiple times.')] = None, all_default: Annotated[bool, Option('--all', help='Snapshot all default tickers specified in config.yaml.')] = False, compact: Annotated[bool, Option('--compact', help='Keep only liquid options and compress (what the scheduled GitHub Action commits; ~10x smaller files).')] = False, only_fresh: Annotated[bool, Option('--only-fresh', help='Skip tickers whose chain shows no trade today (holidays).')] = False)
Fetches and saves a live market data snapshot (schema v2: spot, rate and dividend yield included) for specified tickers.
Source code in src/optpricing/cli/commands/data.py
stream_quotes ¶
stream_quotes(tickers: Annotated[list[str] | None, Option('--ticker', '-t', help='Underlying to stream (repeatable).')] = None, symbols: Annotated[list[str] | None, Option('--symbol', '-s', help="Any extra Yahoo symbol, e.g. an option contract 'SPY250919C00600000' or an index '^SPX' (repeatable).")] = None, duration: Annotated[float, Option('--duration', '-d', help='Recording length in seconds.')] = 60.0, contracts: Annotated[int, Option('--contracts', '-c', help='Also stream the N most active option contracts of each ticker.')] = 0, output: Annotated[Path | None, Option('--output', '-o', help='Parquet file (default: data/live_quotes/).')] = None)
Records live quotes from Yahoo Finance's free streamer into a parquet file.
Press Ctrl-C to stop early; whatever was received is saved.
Source code in src/optpricing/cli/commands/data.py
demo_american ¶
demo_european ¶
demo_european(model: Annotated[str | None, Option('--model', '-m', help="Run for a specific model (e.g., 'BSM').", case_sensitive=False)] = None, technique: Annotated[str | None, Option('--technique', '-t', help="Run for a specific technique (e.g., 'MC').", case_sensitive=False)] = None)
Runs the European options pricing and performance benchmark.
Source code in src/optpricing/cli/commands/demo.py
price ¶
price(ticker: Annotated[str, Option('--ticker', '-t', help='Stock ticker.')], strike: Annotated[float, Option('--strike', '-k', help='Strike price.')], maturity: Annotated[str, Option('--maturity', '-T', help='Maturity YYYY-MM-DD.')], option_type: Annotated[str, Option('--type', help='call|put', case_sensitive=False)] = 'call', style: Annotated[str, Option('--style', help='european|american', case_sensitive=False)] = 'european', model: Annotated[str, Option('--model', '-m', help='Model key.')] = 'BSM', technique: Annotated[str | None, Option('--technique', '-x', help='Force technique key (e.g., mc, crr).', case_sensitive=False)] = None, param: Annotated[list[str] | None, Option('--param', help='Repeat: key=value (e.g. sigma=0.2)', show_default=False)] = None)
Prices a single option using live market data and specified parameters.
Source code in src/optpricing/cli/commands/price.py
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
get_implied_rate ¶
get_implied_rate(ticker: Annotated[str, Option('--ticker', '-t', help='Stock ticker for the option pair.')], strike: Annotated[float, Option('--strike', '-k', help='Strike price of the option pair.')], maturity: Annotated[str, Option('--maturity', '-T', help='Maturity date in YYYY-MM-DD format.')])
Calculates the implied risk-free rate from a live call-put pair.
Source code in src/optpricing/cli/commands/tools.py
print_tuning_leaderboard ¶
Rich table of the tuning leaderboard (best model first).
Source code in src/optpricing/cli/commands/tune.py
tune ¶
tune(ticker: Annotated[str, Option('--ticker', '-t', help='The stock ticker to tune for.')], model: Annotated[list[str] | None, Option('--model', '-m', help="Model to include ('all' by default). Can be used multiple times.")] = None, candidates: Annotated[str, Option('--candidates', help="'quick' (3 settings), 'full' (all) or a comma-separated list of: " + join(CANDIDATE_SETTINGS))] = 'quick', max_pairs: Annotated[int | None, Option('--max-pairs', help='Use only the most recent N day pairs.')] = None, allow_mc: Annotated[bool, Option('--allow-mc', help='Include simulation-only models (slow).')] = False, verbose: Annotated[bool, Option('--verbose', '-v', help='Enable detailed logging.')] = False)
Tunes calibration settings per model by walk-forward cross-validation and ranks the models for a ticker.
The result is cached in artifacts/tuning/{TICKER}.json and used by
optpricing calibrate --auto and optpricing backtest --auto.