A package for Black-Scholes option pricing and implied volatility calculation(European Options only)
Project description
Calculation Of Option Greeks and Implied Volatility in Python
The aim of this package is to calculate Option Greeks and Implied Volatility for European options. The function takes input in a similar form to the popular Hoadley add-in used in Excel.
Functions:
blackScholes(calculation_type, Option_type, K, S, T, sigma, r = 0)
: Calculates option price, delta, gamma, vega, theta, or rho.
implied_volatility(Option_type, K, S, T, Option_price, r = 0, tol = 0.0001, max_iterations = 100)
: Estimates implied volatility using Newton-Ralphson method.
Calculations:
- Performs price, delta, gamma, vega, theta, and rho calculations for both call and put options.
- Implied Volatility: Estimates implied volatility using numerical methods. Input Validation: Includes checks for invalid inputs (e.g., NaN values, zero strike price). Error Handling: Handles potential errors (e.g., incorrect option type, wrong Datatype entry when number is expected, etc.).
Input Parameters:
calculation_type
: Specifies the type of calculation to perform (price, delta, gamma, vega, theta, rho).
i. Use 'p' for price.
ii. Use 'd' for delta.
iii. Use 'g' for gamma.
iv. Use 'v' for vega.
v. Use 't' for theta.
vi. Use 'r' for rho.
Option_type
: Specifies the option type (call or put).
K
: Strike price.
S
: Underlying asset price.
T
: Time to expiration (in Days).
sigma
: Volatility.
r
: Risk-free interest rate.
Option_price
: Market price of the option (used for implied volatility calculation).
tol
: Tolerance level for implied volatility calculation.
max_iterations
: Maximum number of iterations for implied volatility calculation.
Example Usage
Here is an example of how to use the blackScholes
and implied_volatility
functions:
from hoadleyYaPu import hoadleyYaPu
# Calculate call and put prices using the Black-Scholes model
callprice = blackScholes("p", "c", 100, 100, 15, 0.1855, 0)
putprice = blackScholes("p", "p", 1350, 1400, 15, 0.25, 0)
# Calculate the Greeks for a call option using the Black-Scholes model
callDelta = blackScholes("d", "c", 1350, 1400, 15, 0.25, 0)
callgamma = blackScholes("g", "c", 1350, 1400, 15, 0.25, 0)
callvega = blackScholes("v", "c", 1350, 1400, 15, 0.25, 0)
calltheta = blackScholes("t", "c", 1350, 1400, 15, 0.25, 0)
callrho = blackScholes("r", "c", 1350, 1400, 15, 0.25, 0)
# Calculate implied volatility for call and put options
callIV = implied_volatility("c", 42200, 41653.55, 1, 14.05, 0)
putIV = implied_volatility("p", 42200, 41653.55, 15, 550, 0)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hoadleyyapu-0.1.tar.gz
.
File metadata
- Download URL: hoadleyyapu-0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92965d3eed00a3b59d8881f807bb89d0326dc7744612604a55f79ade7d019afc |
|
MD5 | 27438424d6ef867b53ce5cbe0d845d07 |
|
BLAKE2b-256 | d7d6ed75d10733726cec4dfe26bdf82d243edadb4f2074565a5e2857d3ef6d53 |
File details
Details for the file hoadleyYaPu-0.1-py3-none-any.whl
.
File metadata
- Download URL: hoadleyYaPu-0.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56018f2b608c8d81fa0e478e25f666998a6e2efb59423a6c551d90738c8cd2d5 |
|
MD5 | deae76ff6f45c9f1a1ac608342d77dab |
|
BLAKE2b-256 | 1bd79a286ce63959a6a15f1c9053e2a50b5eaf924aa26cb89deb0e6720f473c3 |