anshul-quantfin
A Python library for mathematical finance, continuous-time stochastic modeling, and derivatives pricing engines.
Installation
Available on PyPI: anshul-quantfin
pip install anshul-quantfin
Version '0.1.3'
anshul-quantfin is structured to leverage object-oriented principles across three primary submodules: options, stochastics, and simulations.
Option Pricing
Black-Scholes Pricing & Greeks
Theoretical European option pricing and analytical Greeks via the options submodule.
import quant_fin as qf
# Signature: (asset_price, asset_volatility, strike_price, time_to_expiration, risk_free_rate)
S = 100 # Asset price ($)
sigma = 0.20 # Volatility (20%)
K = 105 # Strike price ($)
T = 1.0 # Time to maturity (1 Year)
r = 0.05 # Risk-free rate (5%)
call = qf.options.BlackScholesCall(S, sigma, K, T, r)
put = qf.options.BlackScholesPut(S, sigma, K, T, r)
print(f"Call Price : {call.price:.4f}")
print(f"Put Price : {put.price:.4f}")
print(f"Call Delta : {call.delta:.4f}")
print(f"Call Gamma : {call.gamma:.4f}")
print(f"Call Vega : {call.vega:.4f}")
print(f"Call Theta : {call.theta:.4f}")
Arithmetic Brownian Motion Pricing
Analytical vanilla option pricing under the Bachelier model.
import quant_fin as qf
import numpy as np
# ABM parameterized by Bachelier volatility = 0.3
abm = qf.ArithmeticBrownianMotion([0.3])
# Vanilla analytical pricing under ABM (F0, X, T, type)
call_price = abm.vanilla_pricing(101, 100, 1.0, "CALL")
put_price = abm.vanilla_pricing(99, 100, 1.0, "PUT")
# Simulate path dynamics (F0, n, dt, T)
abm.simulate(100, 10000, 1/252, 1.0)
# Monte Carlo expectation from stored path characteristics
payoffs = [max(path[-1] - 99, 0) for path in abm.path_characteristics[0]]
simulated_call_price = np.average(payoffs)
Stochastic Processes
Continuous-time asset price path simulations using stochastic differential equations.
Geometric Brownian Motion
Standard continuous drift-diffusion process.
import quant_fin as qf
import matplotlib.pyplot as plt
import numpy as np
# Parameters: S=100, mu=0.05, sigma=0.20, dt=1/252, T=1.0
S0 = 100
mu = 0.05
sigma = 0.20
dt = 1 / 252
T = 1.0
n_paths = 50
gbm = qf.GeometricBrownianMotion(S0, mu, sigma, dt, T)
plt.figure(figsize=(10, 6))
for _ in range(n_paths):
path = gbm.simulate_path(S0, mu, sigma, dt, T)
time_grid = np.linspace(0, T, len(path))
plt.plot(time_grid, path, lw=1, alpha=0.6)
plt.title("Geometric Brownian Motion Simulation (50 Paths)")
plt.xlabel("Time (Years)")
plt.ylabel("Asset Price ($)")
plt.grid(True, alpha=0.3)
plt.show()
Stochastic Variance Process (Heston Model)
Mean-reverting stochastic volatility modeling.
import quant_fin as qf
# Signature: (S, mu, r, div, kappa, theta, rho, sigma_v, v0, dt, T)
svm = qf.StochasticVarianceModel(100, 0, 0.01, 0.05, 2, 0.25, -0.7, 0.3, 0.09, 1/52, 1)
print(svm.simulated_path)
Simulation Pricing
Monte Carlo derivatives valuation across vanilla, path-dependent, and exotic payoff structures.
Vanilla & Asian Options
import quant_fin as qf
# Signature: (strike, n_sims, r, S, mu, sigma, dt, T)
strike = 100
n_sims = 1000
r = 0.01
S = 100
mu = 0.0
sigma = 0.30
dt = 1 / 52
T = 1.0
# Vanilla Monte Carlo
call_option = qf.MonteCarloCall(strike, n_sims, r, S, mu, sigma, dt, T)
put_option = qf.MonteCarloPut(strike, n_sims, r, S, mu, sigma, dt, T, 2, 0.25, -0.5, 0.02, 0.3)
print("MC Call Price :", call_option.price)
print("MC Put Price :", put_option.price)
# Asian Monte Carlo (Averaging Payoff)
asian_call = qf.MonteCarloAsianCall(strike, n_sims, r, S, mu, sigma, dt, T)
asian_put = qf.MonteCarloAsianPut(strike, n_sims, r, S, mu, sigma, dt, T)
print("Asian Call Price :", asian_call.price)
print("Asian Put Price :", asian_put.price)
Binary Options
import quant_fin as qf
# Signature: (strike, payout, n_sims, r, S, mu, sigma, dt, T)
binary_call = qf.MonteCarloBinaryCall(100, 50, 1000, 0.01, 100, 0, 0.3, 1/52, 1)
binary_put = qf.MonteCarloBinaryPut(100, 50, 1000, 0.01, 100, 0, 0.3, 1/52, 1)
print("Binary Call Price :", binary_call.price)
print("Binary Put Price :", binary_put.price)
Barrier Options
import quant_fin as qf
# Signature: (strike, n_sims, barrier, r, S, mu, sigma, dt, T, up=True/False, out=True/False)
barrier_call = qf.MonteCarloBarrierCall(100, 1000, 150, 0.01, 100, 0, 0.3, 1/52, 1, up=True, out=True)
barrier_put = qf.MonteCarloBarrierCall(100, 1000, 95, 0.01, 100, 0, 0.3, 1/52, 1, up=False, out=False)
print("Barrier Call Price :", barrier_call.price)
print("Barrier Put Price :", barrier_put.price)
Extendible Options
import quant_fin as qf
# Signature: (strike, n_sims, r, S, mu, sigma, dt, T, extension_period)
extendible_call = qf.MonteCarloExtendibleCall(100, 1000, 0.01, 100, 0, 0.3, 1/52, 1, 0.5)
extendible_put = qf.MonteCarloExtendiblePut(100, 1000, 0.01, 100, 0, 0.3, 1/52, 1, 0.5)
print("Extendible Call Price :", extendible_call.price)
print("Extendible Put Price :", extendible_put.price)
License
Distributed under the MIT License. See LICENSE for more information.
Metadata
Release files for anshul-quantfin 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| anshul_quantfin-0.1.3.tar.gz | 7.9 kB | Without provenance | Details for anshul_quantfin-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anshul_quantfin-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for anshul_quantfin-0.1.3-py3-none-any.whl |
Total release size: 15.7 kB
Release files / anshul_quantfin-0.1.3.tar.gz
| Download URL | anshul_quantfin-0.1.3.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43be0c50cab24ec400932cb6b58ac6dfc0dbfaa6bcb535db75f3cfaf6cce497b
|
|
BLAKE2b-256 checksum How to use checksums |
3368888abc7b41774d2b1164799709620e983038a556ee36fe86cdbe7c350a83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / anshul_quantfin-0.1.3-py3-none-any.whl
| Download URL | anshul_quantfin-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7aeeb9d95b0d31e6100bcf98b677f89880e650433b520b2efdc98bca31f0204c
|
|
BLAKE2b-256 checksum How to use checksums |
1837c37edcc99f5a210b8ae1f19081838f8adbdab902856f8f59e5c8b1dd5a11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Security for anshul-quantfin 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.