Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorized_black gives the undiscounted option price #13 #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions py_vollib_vectorized/_model_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def _black_scholes_vectorized_call(flags, Ss, Ks, ts, rs, sigmas):


@maybe_jit()
def _black_vectorized_call(Fs, Ks, sigmas, ts, flag):
def _black_vectorized_call(Fs, Ks, sigmas, ts, rs, flag):
prices = []
for F, K, sigma, T, q in zip(Fs, Ks, sigmas, ts, flag):
prices.append(black(F, K, sigma, T, q))
for F, K, sigma, T, r, q in zip(Fs, Ks, sigmas, ts, rs, flag):
prices.append(np.exp(-r*T)*black(F, K, sigma, T, q))
return prices


Expand Down
9 changes: 5 additions & 4 deletions py_vollib_vectorized/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def vectorized_black(flag, F, K, t, r, sigma, *, return_as="dataframe", dtype=np
:param K: The strike price.
:param sigma: The Implied Volatility (as a decimal, i.e. 0.10 for 10%).
:param t: The annualized time to expiration. Must be positive. For small TTEs, use a small value (1e-3).
:param r: The risk-free rate
:param flag: For each contract, this should be specified as `c` for a call option and `p` for a put option.
:param return_as: To return as a :obj:`pd.Series` object, use "series". To return as a :obj:`pd.DataFrame` object, use "dataframe". Any other value will return a :obj:`numpy.array` object.
:param dtype: Data type.
:return: The price of the option.
:return: The price of the option (after discounting)
>>> import py_vollib.black
>>> import py_vollib_vectorized
>>> flag = ['c', 'p']
Expand All @@ -32,10 +33,10 @@ def vectorized_black(flag, F, K, t, r, sigma, *, return_as="dataframe", dtype=np
array([1.53408169, 1.38409245])
"""
flag = _preprocess_flags(flag, dtype=dtype)
F, K, sigma, t, flag = maybe_format_data_and_broadcast(F, K, sigma, t, flag, dtype=dtype)
_validate_data(F, K, sigma, t, flag)
F, K, sigma, t, r, flag = maybe_format_data_and_broadcast(F, K, sigma, t, r, flag, dtype=dtype)
_validate_data(F, K, sigma, t, r, flag)

prices = _black_vectorized_call(F, K, sigma, t, flag)
prices = _black_vectorized_call(F, K, sigma, t, r, flag)
prices = np.ascontiguousarray(prices)

if return_as == "series":
Expand Down