Metadata-Version: 2.1
Name: anshul-quantfin
Version: 0.1.3
Summary: A Python library for mathematical finance.
Author: Anshul Deewan
Author-email: Anshul Deewan <asharma800077@gmail.com>
License: MIT
Project-URL: Homepage, https://pypi.org/project/anshul-quantfin/
Keywords: python,finance,quant,options,stochastic,monte-carlo
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy

# anshul-quantfin
A Python library for mathematical finance, continuous-time stochastic modeling, and derivatives pricing engines.

## Installation
Available on PyPI: [anshul-quantfin](https://pypi.org/project/anshul-quantfin/)

```bash
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.

```python
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.

```python
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.

```python
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.

```python
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

```python
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

```python
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

```python
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

```python
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.

```

```
