-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Description
Thanks very much for making the library available @marcdemers. You've saved me a ton of time!
One issue I noticed straight away in my own code is that my source dataframe for the price_dataframe api function has a non-standard index and this breaks the results.
Three examples below show what I mean. The first two (failing) examples can be fixed by using the to_numpy() method on the price, sigma and greek[] returns. The third example (your original in the docs) is not impacted by this change.
tuples = [(1, 'red'), (2, 'blue')]
idx = pd.MultiIndex.from_tuples(tuples, names=('number', 'color'))
df = pd.DataFrame(index=idx)
df['Flag'] = ['c', 'p']
df['S'] = 95
df['K'] = [100, 90]
df['T'] = 0.2
df['R'] = 0.2
df['IV'] = 0.2
# first example multiindex (NaNs)
result = price_dataframe(df, flag_col='Flag', underlying_price_col='S', strike_col='K', annualized_tte_col='T',
riskfree_rate_col='R', sigma_col='IV', model='black_scholes', inplace=False)
print(result)
# second example index not starting at zero (results shifted/NaNs)
idx = pd.Index([1, 2])
df.index = idx
result = price_dataframe(df, flag_col='Flag', underlying_price_col='S', strike_col='K', annualized_tte_col='T',
riskfree_rate_col='R', sigma_col='IV', model='black_scholes', inplace=False)
print(result)
# third example index starting at zero (results OK)
idx = pd.Index([0, 1])
df.index = idx
result = price_dataframe(df, flag_col='Flag', underlying_price_col='S', strike_col='K', annualized_tte_col='T',
riskfree_rate_col='R', sigma_col='IV', model='black_scholes', inplace=False)
print(result)
The fix is to apply to_numpy() like this in price_dataframe:
...
if inplace:
df["Price"] = price.to_numpy()
else:
output_df["Price"] = price.to_numpy()
....
Metadata
Metadata
Assignees
Labels
No labels