我有一些选项的数据,我想用看涨或看跌的条件绘制数据。以下数据如下所示:
underlying_last exchange ... IVBid IVAsk
underlying ...
BP 39.00 * ... 0.0000 4.0743
BP 39.00 * ... 0.0000 3.0846
BP 39.00 * ... 0.0000 3.9024
BP 39.00 * ... 0.0000 2.6644
BP 39.00 * ... 0.0000 3.3525
有一列'type'
包含期权是看涨期权还是看跌期权。我只想选择看涨期权价值并根据价格绘制报价日期。我有以下代码:
#import modules needed
import numpy as np
import pandas_datareader as web
import matplotlib.pyplot as plt
import datetime as dt
import pandas as pd
from matplotlib import style
from matplotlib import rc
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import GPy
from numpy.random import randn
#styel of plot
style.use('default')
df = pd.read_csv('BP_2019.csv',index_col = 'underlying',parse_dates = ['expiration','quotedate'])
c = df['type'] = "call"
x = df[c].index
y = df[c]['bid'].tolist()
fig, ax = plt.subplots()
ax.plot(x,y)
我收到以下错误:
File "pandas/_libs/hashtable_class_helper.pxi", line 1614, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'call'
尝试以下操作:
代替 c = df['type'] = "call"
采用 c = df[df['type'] == "call"]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句