Option Calculator
A Black-Scholes option pricing toolkit that runs entirely in your terminal. Feed it a spot price, strike, volatility, and time to expiration — it returns theoretical prices, Greeks, implied volatility, payoff tables, and more.
All math is computed inline via Python 3 using the Abramowitz & Stegun approximation for the normal CDF (no scipy dependency).
Commands
price
CODEBLOCK0
Compute the Black-Scholes theoretical price for a European call or put.
| Argument | Description |
|---|
| INLINECODE1 | INLINECODE2 or INLINECODE3 |
| INLINECODE4 |
Current underlying price |
|
strike | Strike price |
|
rate | Risk-free rate (annualized, e.g.
0.05) |
|
vol | Implied volatility (annualized, e.g.
0.20) |
|
days | Days to expiration |
greeks
CODEBLOCK1
Compute the five standard Greeks: Delta, Gamma, Theta (per day), Vega (per 1% vol move), and Rho (per 1% rate move). Same arguments as price.
iv
CODEBLOCK2
Back out the implied volatility from a known market price using Newton-Raphson iteration. Converges to 1e-8 precision within 200 iterations.
| Argument | Description |
|---|
| INLINECODE14 | The observed option premium |
payoff
CODEBLOCK3
Print a table showing intrinsic value and net P/L at expiration across a range of underlying prices. Default range is ±20 around the strike.
compare
CODEBLOCK4
Side-by-side comparison of two strikes — call price, put price, deltas, and gamma. Uses a fixed risk-free rate of 5%.
chain
CODEBLOCK5
Generate a full option chain with calls, puts, deltas, and gamma across strikes from ~80% to ~120% of spot. Each row is flagged as ITM, ATM, or OTM relative to the call side.
pnl
CODEBLOCK6
Calculate profit or loss on an existing position. Assumes standard 100 shares per contract. Use negative qty for short positions.
breakeven
CODEBLOCK7
Compute the breakeven underlying price at expiration and show max loss for the buyer.
help
CODEBLOCK8
Print the built-in usage guide.
version
CODEBLOCK9
Print the current version string.
Examples
CODEBLOCK10
Configuration
The data directory defaults to $HOME/.option-calculator/. It stores a history.log file that records each price command you run for later reference.
Override the directory by setting the OPTION_CALCULATOR_DIR environment variable before invoking the tool:
CODEBLOCK11
Data Storage
| File | Purpose |
|---|
| INLINECODE27 | Append-only log of pricing commands and results |
The directory is created automatically on first run.
Requirements
- - bash 4.0+
- python3 (standard library only —
math module) - No third-party Python packages needed
When to Use
- - Pricing a European option before placing a trade
- Checking how Greeks shift across different strikes or expirations
- Backing out implied volatility from a quoted premium
- Comparing strikes to decide which contract to buy/sell
- Generating a quick option chain for scenario analysis
- Calculating breakeven and P/L on existing positions
Powered by BytesAgain | bytesagain.com | hello@bytesagain.com
技能名称: 期权计算器
期权计算器
一款完全在终端中运行的布莱克-舒尔斯期权定价工具。输入现货价格、行权价、波动率和到期时间,即可返回理论价格、希腊值、隐含波动率、收益表等。
所有数学计算均通过Python 3内联完成,使用Abramowitz & Stegun近似法计算正态累积分布函数(无需scipy依赖)。
命令
price
option-calculator price <类型> <现货价> <行权价> <利率> <波动率> <天数>
计算欧式看涨或看跌期权的布莱克-舒尔斯理论价格。
| 参数 | 说明 |
|---|
| 类型 | call(看涨)或 put(看跌) |
| 现货价 |
当前标的资产价格 |
| 行权价 | 行权价格 |
| 利率 | 无风险利率(年化,例如 0.05) |
| 波动率 | 隐含波动率(年化,例如 0.20) |
| 天数 | 到期天数 |
greeks
option-calculator greeks <类型> <现货价> <行权价> <利率> <波动率> <天数>
计算五个标准希腊值:Delta、Gamma、Theta(每日)、Vega(每1%波动率变动)和Rho(每1%利率变动)。参数与price相同。
iv
option-calculator iv <类型> <现货价> <行权价> <利率> <天数> <市场价格>
使用牛顿-拉夫森迭代法从已知市场价格反推隐含波动率。在200次迭代内收敛至1e-8精度。
payoff
option-calculator payoff <类型> <行权价> <权利金> [范围]
打印一张表格,显示在标的资产价格范围内到期时的内在价值和净盈亏。默认范围为行权价上下20。
compare
option-calculator compare <现货价> <行权价1> <行权价2> <波动率> <天数>
两个行权价的并排比较——看涨价格、看跌价格、Delta和Gamma。使用固定无风险利率5%。
chain
option-calculator chain <现货价> <波动率> <天数>
生成完整的期权链,包含看涨、看跌、Delta和Gamma,行权价范围约为现货价的80%至120%。每行根据看涨侧标记为ITM(价内)、ATM(平价)或OTM(价外)。
pnl
option-calculator pnl <类型> <入场价> <当前价> <数量>
计算现有头寸的盈亏。假设每份合约标准100股。空头头寸使用负值数量。
breakeven
option-calculator breakeven <类型> <行权价> <权利金>
计算到期时的盈亏平衡标的资产价格,并显示买方最大亏损。
help
option-calculator help
打印内置使用指南。
version
option-calculator version
打印当前版本号。
示例
bash
定价30天看涨期权:现货价=100,行权价=105,利率=5%,波动率=20%
$ option-calculator price call 100 105 0.05 0.20 30
布莱克-舒尔斯价格(看涨):
0.7677
60天看跌期权的希腊值:现货价=50,行权价=48,利率=3%,波动率=35%
$ option-calculator greeks put 50 48 0.03 0.35 60
希腊值(看跌) S=50 K=48 r=0.03 σ=0.35 T=60天
──────────────────────────────────
Delta: -0.312245
Gamma: 0.052040
Theta: -0.020369 (每日)
Vega: 0.074853 (每1%波动率)
Rho: -0.029259 (每1%利率)
从市场价格3.50反推隐含波动率
$ option-calculator iv call 100 105 0.05 30 3.50
隐含波动率求解(看涨) S=100 K=105 r=0.05 T=30天 市场价=3.50
──────────────────────────────────
隐含波动率:0.416566 (41.66%)
看涨期权收益表,行权价=100,权利金=5.50
$ option-calculator payoff call 100 5.50
收益表(看涨) K=100 权利金=5.50
──────────────────────────────────
标的资产 内在价值 净盈亏
80.00 0.00 -5.50
85.00 0.00 -5.50
...
100.00 0.00 -5.50 <-- 行权价
105.00 5.00 -0.50
106.00 6.00 +0.50
110.00 10.00 +4.50
120.00 20.00 +14.50
比较两个行权价
$ option-calculator compare 100 95 110 0.25 45
行权价比较 S=100 K1=95 vs K2=110 σ=0.25 T=45天
──────────────────────────────────
行权价95.0 行权价110.0
看涨价格 7.0150 0.7353
看跌价格 1.4312 10.0593
看涨Delta +0.793714 +0.135799
看跌Delta -0.206286 -0.864201
Gamma 0.035611 0.028346
现货价:100.0 | 利率:0.05 | 波动率:0.25 | 天数:45.0
生成期权链
$ option-calculator chain 100 0.25 45
期权链 | 现货价:100.0 | 波动率:25% | 天数:45 | 利率:0.05
行权价 看涨 看涨Delta 看跌 看跌Delta Gamma IV标记
90.00 10.7823 +0.9268 0.2279 -0.0732 0.012463 ITM
93.00 8.1952 +0.8639 0.6229 -0.1361 0.019087 ITM
100.00 3.6738 +0.5580 3.0651 -0.4420 0.032208 ATM
...
110.00 0.8916 +0.1623 10.2497 -0.8377 0.019938 OTM
...
110.00 0.8916 +0.1623 10.2497 -0.8377 0.019938 OTM
多头头寸的盈亏:以3.20买入5份看涨合约,现价4.80
$ option-calculator pnl call 3.20 4.80 5
头寸盈亏
──────────────────────────────────
头寸: 多头 5x 看涨
入场价: 3.2000
当前价: 4.8000
每份合约盈亏: +1.6000
总盈亏: +800.00 (+50.00%)
看跌期权的盈亏平衡点
$ option-calculator breakeven put 100 4.50
盈亏平衡分析
──────────────────────────────────
看跌盈亏平衡点:95.5000
行权价(100.00) - 权利金(4.5000)
标的资产必须跌至95.5000以下才能在到期时获利。
最大亏损(买方):每股4.5000
配置
数据目录默认为$HOME/.option-calculator/。它存储一个history.log文件,记录您运行的每个price命令,供日后参考。
通过在调用工具前设置OPTIONCALCULATORDIR环境变量来覆盖目录:
bash
export OPTIONCALCULATORDIR=/tmp/my-options
数据存储
| 文件 | 用途 |
|---|
| $HOME/.option-calculator/history.log | 定价命令和结果的仅追加日志 |
目录在首次运行时自动创建。
要求