option-yield

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

期权权利金年化收益计算器

Option Premium Annualized Return Calculator

通过截图或文字输入期权信息,计算权利金年化收益率。基于段永平的计算方法。
Calculate the annualized return rate of option premiums by inputting option information via screenshots or text. Based on Duan Yongping's calculation method.

前置条件

Prerequisites

  • Python 3.x(无额外依赖,仅用标准库)
  • ~/.longerian/scripts/option_yield_calculator.py
    (安装时自动复制)
  • Web 搜索能力(用于获取实时无风险利率)
  • Python 3.x (no additional dependencies, only uses standard libraries)
  • ~/.longerian/scripts/option_yield_calculator.py
    (automatically copied during installation)
  • Web search capability (used to obtain real-time risk-free interest rates)

目录约定

Directory Convention

所有文件使用
~/.longerian/
(持久化、跨 agent):
~/.longerian/
├── scripts/option_yield_calculator.py   # 计算脚本
└── data/option-yield/
    ├── option_input.json                # 输入(临时)
    └── option_result.json               # 输出(临时)
All files are stored in
~/.longerian/
(persistent, cross-agent):
~/.longerian/
├── scripts/option_yield_calculator.py   # Calculation script
└── data/option-yield/
    ├── option_input.json                # Input (temporary)
    └── option_result.json               # Output (temporary)

核心公式

Core Formulas

净资金占用 = 行权价 - 权利金
权利金年化收益 = (权利金 / 净资金占用) × (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

流程

Process

Step 1: 接收输入

Step 1: Receive Input

用户可能提供:
  • 截图:期权交易界面截图
  • 文字:自由格式或结构化的期权信息
Users may provide:
  • Screenshots: Screenshots of option trading interfaces
  • Text: Free-form or structured option information

Step 2: 解析期权参数

Step 2: Parse Option Parameters

从输入中提取以下参数:
参数说明默认值
underlying标的代码(如 AAPL、700)必填
market市场(us / hk)根据标的自动判断
option_type期权类型(put / call)put
strike行权价必填
premium权利金(每股)必填
months剩余到期月数必填
quantity合约数量(张)1
shares_per_contract每张合约股数美股100,港股需查询
市场自动判断规则:
  • 标的代码以数字开头(如 700、9988)→ 港股
  • 标的代码以字母开头(如 AAPL、TSLA)→ 美股
港股每张合约股数查询:
  1. 搜索 "{标的代码} HKEX option shares per contract"
  2. 搜索成功 → 使用查询到的股数
  3. 搜索失败 → 询问用户
如有缺失参数,向用户确认。
Extract the following parameters from the input:
ParameterDescriptionDefault Value
underlyingUnderlying asset code (e.g., AAPL, 700)Required
marketMarket (us / hk)Automatically determined based on the underlying asset
option_typeOption type (put / call)put
strikeStrike priceRequired
premiumPremium (per share)Required
monthsRemaining months to expirationRequired
quantityNumber of contracts1
shares_per_contractNumber of shares per contract100 for US stocks, need to query for HK stocks
Automatic Market Determination Rules:
  • If the underlying code starts with a number (e.g., 700, 9988) → HK market
  • If the underlying code starts with a letter (e.g., AAPL, TSLA) → US market
Query for Shares per Contract in HK Market:
  1. Search for "{underlying code} HKEX option shares per contract"
  2. If search is successful → Use the queried number of shares
  3. If search fails → Ask the user
If any parameters are missing, confirm with the user.

Step 3: 搜索无风险利率

Step 3: Search for Risk-Free Interest Rate

根据市场搜索对应的无风险利率:
市场搜索关键词利率来源
美股"US 1-year Treasury yield"美国1年期国债收益率
港股"HK HIBOR rate"香港银行间同业拆借利率
验证数据时效性:
  • 检查数据日期是否在最近 7 天内
  • 超过 7 天 → 警告用户数据可能过时
  • 搜索失败 → 要求用户手动输入当前利率
Search for the corresponding risk-free interest rate based on the market:
MarketSearch KeywordsInterest Rate Source
US"US 1-year Treasury yield"US 1-year Treasury yield
HK"HK HIBOR rate"Hong Kong Interbank Offered Rate
Data Timeliness Verification:
  • Check if the data date is within the last 7 days
  • If it exceeds 7 days → Warn the user that the data may be outdated
  • If search fails → Ask the user to manually input the current interest rate

Step 4: 运行计算

Step 4: Run Calculation

写入输入文件:
bash
undefined
Write to input file:
bash
undefined

写入 ~/.longerian/data/option-yield/option_input.json

Write to ~/.longerian/data/option-yield/option_input.json


运行计算:
```bash
python3 ~/.longerian/scripts/option_yield_calculator.py
读取结果:
bash
undefined

Run calculation:
```bash
python3 ~/.longerian/scripts/option_yield_calculator.py
Read results:
bash
undefined

读取 ~/.longerian/data/option-yield/option_result.json

Read from ~/.longerian/data/option-yield/option_result.json

undefined
undefined

Step 5: 输出结果

Step 5: Output Results

单笔交易输出格式:
📊 期权权利金年化收益计算
━━━━━━━━━━━━━━━━━━━━━━━
标的: 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%
⚠️ 重要:计算规则
  • 每笔合约权利金收入 = 权利金/股 × 每张合约股数 × 张数(已含股数)
  • 多笔汇总时,总权利金 = 各合约收入之和(不要重复乘以总股数)
  • 综合年化 = 总权利金 / 总净资金占用 × (12 / 平均剩余月数)
Single Transaction Output Format:
📊 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%
Multiple Transactions Summary Output Format:
When there are multiple transactions with different strike prices, calculate each transaction individually and then summarize:
📊 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%
⚠️ Important: Calculation Rules
  • Premium income per contract = Premium per share × Shares per contract × Number of contracts (already includes shares)
  • When summarizing multiple transactions, total premium = sum of income from each contract (do not multiply by total shares repeatedly)
  • Comprehensive annualized return = Total premium / Total net capital occupied × (12 / Average remaining months)

错误处理

Error Handling

场景处理
权利金 >= 行权价报错:参数不合理
到期月数 <= 0报错:已过期
无风险利率搜索失败要求用户手动输入
无风险利率数据超过 7 天警告数据可能过时
截图无法识别要求用户提供文字信息
市场无法自动判断询问用户是美股还是港股
港股股数查询失败询问用户每张合约对应多少股
ScenarioHandling
Premium >= Strike PriceError: Unreasonable parameters
Remaining months <= 0Error: Expired
Failed to search for risk-free interest rateAsk user to input manually
Risk-free interest rate data exceeds 7 daysWarn user that data may be outdated
Screenshot cannot be recognizedAsk user to provide text information
Market cannot be automatically determinedAsk user whether it is US stocks or HK stocks
Failed to query shares per contract in HK marketAsk user how many shares correspond to each contract