fyne.blackscholes¶
-
fyne.blackscholes.
delta
(underlying_price, strike, expiry, sigma, put=False)[source]¶ Black-Scholes Greek delta
Computes the Greek delta of the option – i.e. the option price sensitivity with respect to its underlying price – according to the Black-Scholes model.
Parameters: - underlying_price (float) – Price of the underlying asset.
- strike (float) – Strike of the option.
- expiry (float) – Time remaining until the expiry of the option.
- sigma (float) – Volatility parameter.
- put (bool, optional) – Whether the option is a put option. Defaults to False.
Returns: float – Greek delta according to Black-Scholes formula.
Example
>>> import numpy as np >>> from fyne import blackscholes >>> sigma = 0.2 >>> underlying_price = 100. >>> strike = 90. >>> expiry = 0.5 >>> call_delta = blackscholes.delta(underlying_price, strike, expiry, sigma) >>> np.round(call_delta, 2) 0.79 >>> put_delta = blackscholes.delta(underlying_price, strike, expiry, sigma, ... put=True) >>> np.round(put_delta, 2) -0.21
-
fyne.blackscholes.
formula
(underlying_price, strike, expiry, sigma, put=False)[source]¶ Black-Scholes formula
Computes the price of the option according to the Black-Scholes formula.
Parameters: - underlying_price (float) – Price of the underlying asset.
- strike (float) – Strike of the option.
- expiry (float) – Time remaining until the expiry of the option.
- sigma (float) – Volatility parameter.
- put (bool, optional) – Whether the option is a put option. Defaults to False.
Returns: float – Option price according to Black-Scholes formula.
Example
>>> import numpy as np >>> from fyne import blackscholes >>> sigma = 0.2 >>> underlying_price = 100. >>> strike = 90. >>> expiry = 0.5 >>> call_price = blackscholes.formula(underlying_price, strike, expiry, ... sigma) >>> np.round(call_price, 2) 11.77 >>> put_price = blackscholes.formula(underlying_price, strike, expiry, ... sigma, put=True) >>> np.round(put_price, 2) 1.77
-
fyne.blackscholes.
implied_vol
(underlying_price, strike, expiry, option_price, put=False, assert_no_arbitrage=True)[source]¶ Implied volatility function
Inverts the Black-Scholes formula to find the volatility that matches the given option price. The implied volatility is computed using Newton’s method.
Parameters: - underlying_price (float) – Price of the underlying asset.
- strike (float) – Strike of the option.
- expiry (float) – Time remaining until the expiry of the option.
- option_price (float) – Option price according to Black-Scholes formula.
- put (bool, optional) – Whether the option is a put option. Defaults to False.
- assert_no_arbitrage (bool, optional) – Whether to throw an exception upon no arbitrage bounds violation. Defaults to True.
Returns: float – Implied volatility.
Example
>>> import numpy as np >>> from fyne import blackscholes >>> call_price = 11.77 >>> put_price = 1.77 >>> underlying_price = 100. >>> strike = 90. >>> expiry = 0.5 >>> implied_vol = blackscholes.implied_vol(underlying_price, strike, ... expiry, call_price) >>> np.round(implied_vol, 2) 0.2 >>> implied_vol = blackscholes.implied_vol(underlying_price, strike, ... expiry, put_price, put=True) >>> np.round(implied_vol, 2) 0.2
-
fyne.blackscholes.
vega
(underlying_price, strike, expiry, sigma)[source]¶ Black-Scholes Greek vega
Computes the Greek vega of the option – i.e. the option price sensitivity with respect to its volatility parameter – according to the Black-Scholes model. Note that the Greek vega is the same for calls and puts.
Parameters: - underlying_price (float) – Price of the underlying asset.
- strike (float) – Strike of the option.
- expiry (float) – Time remaining until the expiry of the option.
- sigma (float) – Volatility parameter.
Returns: float – Greek vega according to Black-Scholes formula.
Example
>>> import numpy as np >>> from fyne import blackscholes >>> sigma = 0.2 >>> underlying_price = 100. >>> strike = 90. >>> maturity = 0.5 >>> vega = blackscholes.vega(underlying_price, strike, maturity, sigma) >>> np.round(vega, 2) 20.23