在带有设置参数的矩阵中查找特定元素
我为财务选项创建了一个代码,并且要完成它的最后一件事。我希望我的代码找到特定选项的隐含波动率。我的代码要求用户输入股票的股票股票,到期日期,罢工价格以及该选项是否为呼叫或看台。
这是我想要做的:
- 根据它是通话还是put,寻找合适的 在终端中给出的矩阵。
- 提取有条件的暗示波动率值(我可以在选项中处理日期和股票。 用户输入的
- 返回隐含波动率
我该如何处理?我查看了许多模块(熊猫,熊猫datareader,基本的python函数,numpy,sys等)及其文档,似乎没有什么适合我想要的。这是我从我想要的数据中获得的输出的示例。
from yahoo_fin import options
chain = options.get_options_chain("nflx", "2022-06-10")
print(chain)
$ python implied
{'calls': Contract Name Last Trade Date Strike Last Price Bid Ask Change % Change Volume Open Interest Implied Volatility
0 NFLX220610C00120000 2022-05-04 12:27PM EDT 120.0 75.50 46.50 49.60 0.00 - - 0 87.26%
1 NFLX220610C00130000 2022-05-09 10:25AM EDT 130.0 50.05 0.00 0.00 0.00 - - 0 0.00%
2 NFLX220610C00135000 2022-05-05 1:50PM EDT 135.0 55.75 34.50 35.60 0.00 - - 1 81.37%
3 NFLX220610C00145000 2022-05-10 10:04AM EDT 145.0 36.77 0.00 0.00 0.00 - - 0 0.00%
'puts': Contract Name Last Trade Date Strike Last Price Bid Ask Change % Change Volume Open Interest Implied Volatility
0 NFLX220610P00100000 2022-05-11 3:59PM EDT 100.0 0.59 0.56 0.66 0.19 +47.50% 83 59 100.05%
1 NFLX220610P00105000 2022-05-11 11:43AM EDT 105.0 0.40 0.71 0.86 -0.20 -33.33% 2 1 96.48%
2 NFLX220610P00110000 2022-05-11 3:22PM EDT 110.0 0.97 0.96 1.10 0.38 +64.41% 35 6 93.51%
I created a code for financial options and there is one last thing missing to finish it. I want my code to find the implied volatility for a specific option. My code asks the user to input the stock's ticker, date to maturity, strike price, and if the option is a call or a put.
Here is what I would like it to do:
- Based on whether it is a call or a put, look for the suitable
matrix that is given in the terminal. - Extract the implied volatility value conditional to the strike price (I can already handle the date and ticker in the options.get_options_chain function)
the user inputted - Return the implied volatility
How should I go about this? I looked at many modules (pandas, pandas-DataReader, basic Python functions, NumPy, sys, etc.) and their documentation, and nothing seems to fit what I want. Here is an example of the output that I am getting from the data that I want.
from yahoo_fin import options
chain = options.get_options_chain("nflx", "2022-06-10")
print(chain)
$ python implied
{'calls': Contract Name Last Trade Date Strike Last Price Bid Ask Change % Change Volume Open Interest Implied Volatility
0 NFLX220610C00120000 2022-05-04 12:27PM EDT 120.0 75.50 46.50 49.60 0.00 - - 0 87.26%
1 NFLX220610C00130000 2022-05-09 10:25AM EDT 130.0 50.05 0.00 0.00 0.00 - - 0 0.00%
2 NFLX220610C00135000 2022-05-05 1:50PM EDT 135.0 55.75 34.50 35.60 0.00 - - 1 81.37%
3 NFLX220610C00145000 2022-05-10 10:04AM EDT 145.0 36.77 0.00 0.00 0.00 - - 0 0.00%
'puts': Contract Name Last Trade Date Strike Last Price Bid Ask Change % Change Volume Open Interest Implied Volatility
0 NFLX220610P00100000 2022-05-11 3:59PM EDT 100.0 0.59 0.56 0.66 0.19 +47.50% 83 59 100.05%
1 NFLX220610P00105000 2022-05-11 11:43AM EDT 105.0 0.40 0.71 0.86 -0.20 -33.33% 2 1 96.48%
2 NFLX220610P00110000 2022-05-11 3:22PM EDT 110.0 0.97 0.96 1.10 0.38 +64.41% 35 6 93.51%
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您获得的结果集是用键或
puts
和pd.dataframe
作为值的键。首先访问DICT,然后通过选择
strike
(右行)和隐含波动率
(右列)来选择数据框中所需的数据。使用
ILOC [0]
您将在pd.Series
中获得第一个元素。输出:
The result set you get is a dict with the keys
calls
orputs
and apd.DataFrame
as a value.Access the dict first, then select the required data in the DataFrame by selecting the
strike
(right row) andImplied Volatility
(right column).With
iloc[0]
you will get the first element within thepd.Series
.Output: