Options Pricing API Reference¶
financelib.quant.options.black_scholes(S: float, K: float, T: float, r: float, sigma: float, option_type: str = 'call') -> float
¶
Calculate European option price using Black-Scholes formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
float
|
Current stock price. |
required |
K
|
float
|
Strike price. |
required |
T
|
float
|
Time to expiration in years. |
required |
r
|
float
|
Risk-free interest rate (annualized). |
required |
sigma
|
float
|
Volatility (annualized). |
required |
option_type
|
str
|
'call' or 'put'. |
'call'
|
Returns:
| Type | Description |
|---|---|
float
|
Option price. |
Example
black_scholes(S=100, K=100, T=1, r=0.05, sigma=0.2) 10.4506...
Source code in financelib/quant/options.py
financelib.quant.options.greeks(S: float, K: float, T: float, r: float, sigma: float, option_type: str = 'call') -> Dict[str, float]
¶
Calculate option Greeks (delta, gamma, theta, vega, rho).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
float
|
Current stock price. |
required |
K
|
float
|
Strike price. |
required |
T
|
float
|
Time to expiration in years. |
required |
r
|
float
|
Risk-free interest rate. |
required |
sigma
|
float
|
Volatility. |
required |
option_type
|
str
|
'call' or 'put'. |
'call'
|
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dictionary with delta, gamma, theta, vega, rho. |
Source code in financelib/quant/options.py
financelib.quant.options.implied_volatility(market_price: float, S: float, K: float, T: float, r: float, option_type: str = 'call', tol: float = 1e-06, max_iter: int = 100) -> float
¶
Calculate implied volatility using Newton-Raphson method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
market_price
|
float
|
Observed market price of the option. |
required |
S
|
float
|
Current stock price. |
required |
K
|
float
|
Strike price. |
required |
T
|
float
|
Time to expiration in years. |
required |
r
|
float
|
Risk-free interest rate. |
required |
option_type
|
str
|
'call' or 'put'. |
'call'
|
tol
|
float
|
Convergence tolerance. |
1e-06
|
max_iter
|
int
|
Maximum iterations. |
100
|
Returns:
| Type | Description |
|---|---|
float
|
Implied volatility as a decimal. |
Source code in financelib/quant/options.py
financelib.quant.options.binomial_tree(S: float, K: float, T: float, r: float, sigma: float, n_steps: int = 100, option_type: str = 'call', american: bool = False) -> float
¶
Price an option using the Cox-Ross-Rubinstein binomial tree.
Supports both European and American options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
float
|
Current stock price. |
required |
K
|
float
|
Strike price. |
required |
T
|
float
|
Time to expiration in years. |
required |
r
|
float
|
Risk-free interest rate. |
required |
sigma
|
float
|
Volatility. |
required |
n_steps
|
int
|
Number of time steps in the tree. |
100
|
option_type
|
str
|
'call' or 'put'. |
'call'
|
american
|
bool
|
If True, price an American option (early exercise). |
False
|
Returns:
| Type | Description |
|---|---|
float
|
Option price. |