我正在尝试运行此函数:
def delta(d_1, contract_type):
if contract_type == 'c':
return norm.cdf(d1)
if contract_type == 'p':
return -norm.cdf(-d_1)通过数据帧执行以下操作:
S = test.strike
K = test.stock_price_close
t = test.TtM/365
r = test.Rf
sigma = test.VSMI
test.apply(lambda x: delta(d1,'p'), axis=1, raw=False, result_type='expand')但得到与result相同的值:
2001-11-01 -0.752478
2001-11-02 -0.752478
2001-11-05 -0.752478
2001-11-06 -0.752478
2001-11-08 -0.752478
...
2006-10-26 -0.752478
2006-10-27 -0.752478
2006-10-30 -0.752478
2006-10-31 -0.752478
2006-11-01 -0.752478
Length: 960, dtype: float64有什么想法吗?
发布于 2021-03-17 17:59:59
如果您使用变量x,该函数将只返回变量答案。
如果你应用一个常量lambda函数,那么你会得到一个常量序列。例如:
import pandas as pd
df = pd.DataFrame([1,2,3,4], columns=['col1'])
df['col1'].apply(lambda x: 5) # constant lambda function - x is not used
# constant series returned
0 5
1 5
2 5
3 5
Name: col1, dtype: int64https://stackoverflow.com/questions/66651438
复制相似问题