用Python编写的选项价格计算器棒极了,但是很轻
option-price的Python项目详细描述
期权价格
option-price
是一个基于Python的功能强大但简单的期权价格计算器。它使用矢量化,这使得它非常快。在
GUI版本可用here。在
文档可用here。在
安装
pip install option-price
快速入门
^{pr2}$选项可以通过以下方式初始化:
some_option=Option(european=True,kind='put',s0=100,k=120,t=45,sigma=0.01,r=0.05,dv=0)
或者
some_option=Option(european=False,kind='call',s0=120,k=100,sigma=0.01,r=0.05,start='2008-2-14',end='2008-3-14',dv=0)
你可以通过
print(some_option)
它将打印出选项的信息。在
Type: European Kind: call Price initial: 80 Price strike: 120 Volatility: 1.0% Risk free rate: 5.0% Start Date: 2020-03-24 Expire Date: 2020-04-24 Time span: 31.0 days
属性
Name | Type | Definition |
---|---|---|
european | boolean | True if the option is an European option and False if it's an American one. |
kind | str | ‘call’ for call option while ‘put’ for put option. Other strs are not valid. |
s0 | number | initial price |
k | int | strike price |
sigma | float | volatility of stock |
r | float | risk free interest rate per annum |
[optional] dv | float | dividend rate. 0 for non-stock option, which is also the default |
[optional] t | int | length of option in days |
[optional] start | str | beginning date of the option, string like '2008-02-14',default today |
[optional] end | str | end date of the option, string like '2008-02-14',default today plus param t |
注意,如果start、end和t都给定,那么t将选择end和start之间的差
而且,要么是t要么是(start and end)
计算
option-price
有三种计算期权价格的方法。是的
- B-S-M公司
- 蒙特卡洛
- 二叉树
默认情况下,option-price
将选择B-S-M算法。价格可以简单地用
price=some_option.getPrice()
其他计算方法可通过添加一些参数来实现。例如
price=some_option.getPrice(method='MC',iteration=500000)
或者
price=some_option.getPrice(method='BT',iteration=1000)
MC代表蒙特卡罗,BT代表二叉树。在
迭代有一个默认值。请注意,值越大,价格越慢、越精确。在
默认值是速度和精度的平衡。在
- 项目
标签: