Loading...
Loading...
Compare original and translation side by side
~/.longerian/scripts/option_yield_calculator.py~/.longerian/scripts/option_yield_calculator.py~/.longerian/~/.longerian/
├── scripts/option_yield_calculator.py # 计算脚本
└── data/option-yield/
├── option_input.json # 输入(临时)
└── option_result.json # 输出(临时)~/.longerian/~/.longerian/
├── scripts/option_yield_calculator.py # Calculation script
└── data/option-yield/
├── option_input.json # Input (temporary)
└── option_result.json # Output (temporary)净资金占用 = 行权价 - 权利金
权利金年化收益 = (权利金 / 净资金占用) × (12 / 到期月数)
总年化收益 = 权利金年化收益 + 无风险利率Net Capital Occupied = Strike Price - Premium
Annualized Premium Return = (Premium / Net Capital Occupied) × (12 / Remaining Months to Expiration)
Total Annualized Return = Annualized Premium Return + Risk-Free Interest Rate| 参数 | 说明 | 默认值 |
|---|---|---|
| underlying | 标的代码(如 AAPL、700) | 必填 |
| market | 市场(us / hk) | 根据标的自动判断 |
| option_type | 期权类型(put / call) | put |
| strike | 行权价 | 必填 |
| premium | 权利金(每股) | 必填 |
| months | 剩余到期月数 | 必填 |
| quantity | 合约数量(张) | 1 |
| shares_per_contract | 每张合约股数 | 美股100,港股需查询 |
| Parameter | Description | Default Value |
|---|---|---|
| underlying | Underlying asset code (e.g., AAPL, 700) | Required |
| market | Market (us / hk) | Automatically determined based on the underlying asset |
| option_type | Option type (put / call) | put |
| strike | Strike price | Required |
| premium | Premium (per share) | Required |
| months | Remaining months to expiration | Required |
| quantity | Number of contracts | 1 |
| shares_per_contract | Number of shares per contract | 100 for US stocks, need to query for HK stocks |
| 市场 | 搜索关键词 | 利率来源 |
|---|---|---|
| 美股 | "US 1-year Treasury yield" | 美国1年期国债收益率 |
| 港股 | "HK HIBOR rate" | 香港银行间同业拆借利率 |
| Market | Search Keywords | Interest Rate Source |
|---|---|---|
| US | "US 1-year Treasury yield" | US 1-year Treasury yield |
| HK | "HK HIBOR rate" | Hong Kong Interbank Offered Rate |
undefinedundefined
运行计算:
```bash
python3 ~/.longerian/scripts/option_yield_calculator.pyundefined
Run calculation:
```bash
python3 ~/.longerian/scripts/option_yield_calculator.pyundefinedundefinedundefined📊 期权权利金年化收益计算
━━━━━━━━━━━━━━━━━━━━━━━
标的: AAPL
市场: 美股
期权类型: Sell Put
行权价: $195.00
权利金: $14.45/股
到期日: 2026-01-16(剩余7个月)
数量: 999张(99,900股)
💰 收益分析
━━━━━━━━━━━━━━━━━━━━━━━
净资金占用: $180.55/股
总权利金收入: $1,443,555.00
权利金年化收益率: 13.7%
无风险利率: 4.3%(US 1Y Treasury, 2026-05-01)
总年化收益率: 18.0%📊 期权权利金年化收益计算(汇总)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┌──────┬────────┬────────┬────────────┬──────────┬───────────────┬──────────┐
│ 期权 │ 行权价 │ 权利金 │ 到期日 │ 剩余月数 │ 净资金占用/股 │ 权利金年化 │
├──────┼────────┼────────┼────────────┼──────────┼───────────────┼──────────┤
│ #1 │ $27 │ $1.544 │ 2026-09-18│ ~4.6个月 │ $25.456 │ 16.2% │
│ #2 │ $33 │ $1.08 │ 2026-06-18│ ~1.5个月 │ $31.92 │ 27.1% │
│ #3 │ $38 │ $0.975 │ 2026-05-15│ ~0.5个月 │ $37.025 │ 63.4% │
└──────┴────────┴────────┴────────────┴──────────┴───────────────┴──────────┘
无风险利率: 4.4%(US 1Y Treasury)
💰 汇总收益分析
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
每笔合约权利金收入(已含股数):
#1: $1.544 × 100股 = $154.40
#2: $1.08 × 100股 = $108.00
#3: $0.975 × 100股 = $97.50
合计: $359.90
总净资金占用: $25.456×100 + $31.92×100 + $37.025×100 = $9,440.10
综合权利金年化收益率: $359.90 / $9,440.10 × (12 / 平均月数) = ~34%
含无风险利率总年化: ~38%📊 Option Premium Annualized Return Calculation
━━━━━━━━━━━━━━━━━━━━━━━
Underlying: AAPL
Market: US Stocks
Option Type: Sell Put
Strike Price: $195.00
Premium: $14.45/share
Expiration Date: 2026-01-16 (7 months remaining)
Quantity: 999 contracts (99,900 shares)
💰 Return Analysis
━━━━━━━━━━━━━━━━━━━━━━━
Net Capital Occupied: $180.55/share
Total Premium Income: $1,443,555.00
Annualized Premium Return Rate: 13.7%
Risk-Free Interest Rate: 4.3% (US 1Y Treasury, 2026-05-01)
Total Annualized Return Rate: 18.0%📊 Option Premium Annualized Return Calculation (Summary)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┌──────┬────────┬────────┬────────────┬──────────┬───────────────┬──────────┐
│ Optn │ Strike │ Premium │ Expiration │ Remaining│ Net Capital │ Annualized│
│ │ Price │ │ Date │ Months │ Occupied/Share│ Premium │
├──────┼────────┼────────┼────────────┼──────────┼───────────────┼──────────┤
│ #1 │ $27 │ $1.544 │ 2026-09-18│ ~4.6 mths│ $25.456 │ 16.2% │
│ #2 │ $33 │ $1.08 │ 2026-06-18│ ~1.5 mths│ $31.92 │ 27.1% │
│ #3 │ $38 │ $0.975 │ 2026-05-15│ ~0.5 mths│ $37.025 │ 63.4% │
└──────┴────────┴────────┴────────────┴──────────┴───────────────┴──────────┘
Risk-Free Interest Rate: 4.4% (US 1Y Treasury)
💰 Summary Return Analysis
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Premium income per contract (including shares):
#1: $1.544 × 100 shares = $154.40
#2: $1.08 × 100 shares = $108.00
#3: $0.975 × 100 shares = $97.50
Total: $359.90
Total Net Capital Occupied: $25.456×100 + $31.92×100 + $37.025×100 = $9,440.10
Comprehensive Annualized Premium Return Rate: $359.90 / $9,440.10 × (12 / Average Months) = ~34%
Total Annualized Return Including Risk-Free Rate: ~38%| 场景 | 处理 |
|---|---|
| 权利金 >= 行权价 | 报错:参数不合理 |
| 到期月数 <= 0 | 报错:已过期 |
| 无风险利率搜索失败 | 要求用户手动输入 |
| 无风险利率数据超过 7 天 | 警告数据可能过时 |
| 截图无法识别 | 要求用户提供文字信息 |
| 市场无法自动判断 | 询问用户是美股还是港股 |
| 港股股数查询失败 | 询问用户每张合约对应多少股 |
| Scenario | Handling |
|---|---|
| Premium >= Strike Price | Error: Unreasonable parameters |
| Remaining months <= 0 | Error: Expired |
| Failed to search for risk-free interest rate | Ask user to input manually |
| Risk-free interest rate data exceeds 7 days | Warn user that data may be outdated |
| Screenshot cannot be recognized | Ask user to provide text information |
| Market cannot be automatically determined | Ask user whether it is US stocks or HK stocks |
| Failed to query shares per contract in HK market | Ask user how many shares correspond to each contract |