Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Option Calculator - 期权计算器

一个完整的期权分析工具包,包含期权收益率计算和价格反推功能,帮助投资者进行期权策略分析和定价决策。

🆕 主要功能

✨ 期权收益率计算器

  • 根据期权价格计算年化收益率
  • 分析行权和不行权两种情况
  • 支持看涨和看跌期权
  • 提供详细的收益分析报告

✨ 期权价格计算器

  • 双重目标收益率设置:分别设置行权和不行权情况的目标收益率
  • 智能策略选择:自动分析可行方案,提供最优策略建议
  • 根据预期年化收益率反推期权价格
  • 提供价格合理性评估

📅 支持的日期格式

  • 绝对日期2026-01-022025-12-31
  • 相对天数7d30d365d
  • 相对月数1m3m12m
  • 相对年数1y2y

🚀 安装

# 从源码安装
git clone https://github.com/apollo/option-calculator.git
cd option-calculator
pip install -e .

# 或者直接使用
python3 -m option_calculator

📖 使用方法

交互式模式(推荐)

# 期权收益率计算
python3 -m option_calculator yield

# 期权价格计算
python3 -m option_calculator price

命令行模式

收益率计算示例

# 看涨期权收益率计算
python3 -m option_calculator yield call \
  --option-price 3.2 --strike-price 32.0 --expiry-date 3m \
  --contracts 10 --current-price 31.0 --stock-cost 30.0

# 看跌期权收益率计算
python3 -m option_calculator yield put \
  --option-price 2.5 --strike-price 28.0 --expiry-date 30d \
  --contracts 5 --current-price 29.0 --cash-reserved 14000

价格计算示例

# 看涨期权价格计算(双重目标收益率)
python3 -m option_calculator price call \
  --current-price 47.0 --strike-price 50.0 --expiry-date 30d \
  --target-yield 0.20 --no-exercise-yield 0.15 --contracts 3

# 看跌期权价格计算
python3 -m option_calculator price put \
  --current-price 47.0 --strike-price 45.0 --expiry-date 3m \
  --target-yield 0.25 --no-exercise-yield 0.20 --contracts 3

🔧 API 使用

from option_calculator import YieldCalculator, PriceCalculator

# 收益率计算
yield_calc = YieldCalculator()
yields, details = yield_calc.calculate_call_option_yield(
    option_price=3.2,
    strike_price=32.0,
    expiry_date="3m",
    option_contracts=10,
    stock_quantity=1000,
    stock_cost=30.0,
    current_stock_price=31.0
)

print(f"最大年化收益率: {yields['最大年化收益率']:.2%}")

# 价格计算
price_calc = PriceCalculator()
result = price_calc.calculate_call_option_price(
    current_stock_price=47.0,
    strike_price=50.0,
    expiry_date="30d",
    target_yield=0.20,
    no_exercise_target_yield=0.15,
    option_contracts=3
)

print(f"建议期权价格: ¥{result['期权价格']:.2f}/张")

📊 功能特点

🎯 双重目标收益率

解决传统方法的问题:当行权价过高或过低时,系统总是选择最优情况,用户无法控制具体策略偏好。

新方案:分别设置行权和不行权情况的目标收益率

  • 行权目标收益率:股价超过行权价时的期望收益
  • 不行权目标收益率:股价未达行权价时的期望收益

📅 灵活的日期输入

支持多种日期格式,提高用户体验:

  • 2026-06-15 - 具体日期
  • 30d - 30天后
  • 3m - 3个月后
  • 1y - 1年后

🧠 智能策略选择

  • 双重保障:两种情况都能满足目标收益率
  • 单一可行:只有一种情况可行,给出相应建议
  • 可行性分析:显示所有可行方案的详细信息

🛡️ 错误处理

系统提供友好的错误提示和参数建议:

  • 目标收益率过低时的详细说明
  • 日期格式错误的格式提示
  • 参数验证和合理性检查

📈 计算原理

收益率计算

  • 投入资本:使用当前市价计算(反映机会成本)
  • 不行权情况:收益 = 期权收入
  • 行权情况:收益 = 期权收入 + 股票收益
  • 年化收益率 = (收益 / 投入资本) × (365 / 持有天数)

价格反推

  • 根据目标收益率计算所需期权收入
  • 分析两种情况的可行性
  • 选择最优策略确定期权价格
  • 验证计算结果的准确性

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License - 详见 LICENSE 文件

👨‍💻 作者

Apollo Yang - apollo@example.com


免责声明:本工具仅供教育和研究目的,不构成投资建议。投资有风险,决策需谨慎。

About

期权计算器 - Option Calculator

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages