Name | QuantLite JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | A robust quant finance library |
upload_time | 2024-12-25 17:51:17 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License Copyright (c) 2024 Prasant Sudhakaran Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
quant
finance
monte carlo
exotic options
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# QuantLite
QuantLite is a feature-rich Python library for quantitative finance. It spans everything from **data generation** and **Monte Carlo** to **exotic options pricing**, **enhanced backtesting**, and **advanced visualisations**. Whether you’re exploring novel strategies or needing robust analytics, QuantLite aims to cover all your bases.
## Table of Contents
* [Installation](#installation)
* [Modules Overview](#modules-overview)
* [Data Generation](#data-generation)
* [Instruments (Bond, Vanilla Options, Exotic Options)](#instruments)
* [Monte Carlo](#monte-carlo)
* [Backtesting](#backtesting)
* [Visualisation](#visualisation)
* [Usage Examples & Synergy](#usage-examples--synergy)
* [1. Data Generation + Backtesting + Visualisation](#1-data-generation--backtesting--visualisation)
* [2. Monte Carlo + Backtesting + Visualisation](#2-monte-carlo--backtesting--visualisation)
* [3. Exotic Options Pricing](#3-exotic-options-pricing)
* [Roadmap](#roadmap)
* [Licence](#license)
* [Contact/Support](#contact)
## Installation
QuantLite is available on [PyPI](https://pypi.org/project/quantlite/). Install it simply by:
```bash
pip install quantlite
```
(Ensure you’re using Python 3.8+.)
## Modules Overview
### 1. Data Generation
Location: `quantlite.data_generation`
* `geometric_brownian_motion`: Single-asset GBM path generation.
* `correlated_gbm`: Multi-asset correlated path generation using covariance matrices.
* `ornstein_uhlenbeck`: Mean-reverting process.
* `merton_jump_diffusion`: GBM with Poisson jump arrivals (Merton’s model).
#### Example:
```python
import quantlite.data_generation as qd
prices = qd.geometric_brownian_motion(S0=100, mu=0.05, sigma=0.2, steps=252)
print(prices[:10]) # First 10 days
```
### 2. Instruments (Bond, Vanilla Options, Exotic Options)
Location: `quantlite.instruments`
* Bond Pricing (bond_pricing.py): bond_price, bond_yield_to_maturity, bond_duration, etc.
* Vanilla Options (option_pricing.py): black_scholes_call, black_scholes_put, plus Greeks.
* Exotic Options (exotic_options.py): barrier_option_knock_out, asian_option_arithmetic
Example:
```python
from quantlite.instruments.option_pricing import black_scholes_call
call_val = black_scholes_call(S=100, K=95, T=1, r=0.01, sigma=0.2)
print("Vanilla call option price:", call_val)
```
### 3. Monte Carlo
Location: `quantlite.monte_carlo`
* run_monte_carlo_sims: Single-asset multi-sim approach with different random "modes."
* multi_asset_correlated_sim: Direct correlated multi-asset simulation (similar to * data_generation.correlated_gbm, but designed for scenario testing).
Example:
```python
import pandas as pd
from quantlite.monte_carlo import run_monte_carlo_sims
price_data = pd.Series([100, 101, 99, 102], index=[1,2,3,4])
def always_buy(idx, series):
return 1
mc_results = run_monte_carlo_sims(price_data, always_buy, n_sims=5)
for i, res in enumerate(mc_results):
print("Sim", i, "final value:", res["final_value"])
```
### 4. Backtesting
Location: `quantlite.backtesting`
A robust function `run_backtest` with partial capital, short-selling toggles, and transaction cost modelling.
Example:
```python
def run_backtest(
price_data,
signal_function,
initial_capital=10_000.0,
fee=0.0,
partial_capital=False,
capital_fraction=1.0,
allow_short=True,
per_share_cost=0.0
):
```
### 5. Visualisation
Location: `quantlite.visualisation`
* `plot_time_series`: Basic line chart with optional indicators.
* `plot_ohlc`: Candlesticks or OHLC bars via mplfinance.
* `plot_return_distribution`: Histogram + KDE for returns.
* `plot_equity_curve`: Equity curve with optional drawdown shading.
* `plot_multiple_equity_curves`: Compare multiple strategies and optionally show rolling Sharpe.
Example:
```python
from quantlite.visualisation import plot_equity_curve
# Suppose we have a backtest result with result["portfolio_value"]
plot_equity_curve(result["portfolio_value"], drawdowns=True)
```
## Usage Examples & Synergy
Below are extended examples to show how modules can be combined.
### 1. Data Generation + Backtesting + Visualisation
```python
import quantlite.data_generation as qd
from quantlite.backtesting import run_backtest
from quantlite.visualisation import plot_equity_curve
import pandas as pd
# 1. Create synthetic price data
prices_array = qd.merton_jump_diffusion(S0=100, mu=0.06, sigma=0.25, steps=252, rng_seed=42)
prices_series = pd.Series(prices_array, index=range(253))
# 2. Simple signal: Buy if today's price < yesterday's
def naive_signal(idx, series):
if idx == 0:
return 0
return 1 if series.iloc[idx] < series.iloc[idx-1] else 0
# 3. Run backtest with partial capital
result = run_backtest(prices_series, naive_signal, fee=1.0, partial_capital=True, capital_fraction=0.5)
# 4. Visualise
plot_equity_curve(result["portfolio_value"], drawdowns=True)
print("Final portfolio value:", result["final_value"])
```
### 2. Monte Carlo + Backtesting + Visualisation
```python
import pandas as pd
from quantlite.monte_carlo import run_monte_carlo_sims
from quantlite.visualisation import plot_multiple_equity_curves
prices = pd.Series([100, 101, 102, 103, 99, 98, 101, 102], index=range(8))
def always_long(idx, series):
return 1
# Multiple sims
results = run_monte_carlo_sims(prices, always_long, n_sims=3, mode="replace")
curves = {}
for i, res in enumerate(results):
curves[f"Sim {i}"] = res["portfolio_value"]
plot_multiple_equity_curves(curves_dict=curves, rolling_sharpe=True)
```
### 3. Exotic Options Pricing
```python
from quantlite.instruments.exotic_options import barrier_option_knock_out, asian_option_arithmetic
barrier_val = barrier_option_knock_out(
S0=120, K=100, H=90, T=1.0, r=0.01, sigma=0.2,
option_type="call", barrier_type="down-and-out",
steps=252, sims=10000, rng_seed=42
)
print("Knock-out barrier call value:", barrier_val)
asian_val = asian_option_arithmetic(
S0=120, K=100, T=1.0, r=0.01, sigma=0.2,
option_type="call", steps=252, sims=10000, rng_seed=42
)
print("Arithmetic average Asian call value:", asian_val)
```
## Roadmap
1. More Data Generation:
* Stochastic volatility (Heston model)
* Regime-switching
2. Deeper Monte Carlo:
* Correlated jumps
* Advanced param sweeps
* Multi-factor models
3. Backtesting Enhancements:
* Multi-asset portfolio rebalancing
* Advanced slippage
* Partial fills.
4. More Exotic Instruments:
* Up-and-out barrier
* Lookback options
5. Interactive Visualisation:
* Plotly or Bokeh integration
* Auto-report generation.
## Licence
This project is distributed under the MIT License.
See the LICENSE file for the full text.
## Contact/Support
**Need help or want to contribute?**
> Please open an issue on our [GitHub repo](https://github.com/prasants/quantlite).
Raw data
{
"_id": null,
"home_page": null,
"name": "QuantLite",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "quant, finance, monte carlo, exotic options",
"author": null,
"author_email": "Prasant Sudhakaran <code@prasant.net>",
"download_url": "https://files.pythonhosted.org/packages/d2/ef/7852fd063258a274eeb974d052200a419e7f787ac1f599fd531bebeb3c20/quantlite-0.1.0.tar.gz",
"platform": null,
"description": "# QuantLite\n\nQuantLite is a feature-rich Python library for quantitative finance. It spans everything from **data generation** and **Monte Carlo** to **exotic options pricing**, **enhanced backtesting**, and **advanced visualisations**. Whether you\u2019re exploring novel strategies or needing robust analytics, QuantLite aims to cover all your bases.\n\n## Table of Contents\n\n* [Installation](#installation)\n* [Modules Overview](#modules-overview)\n * [Data Generation](#data-generation)\n * [Instruments (Bond, Vanilla Options, Exotic Options)](#instruments)\n * [Monte Carlo](#monte-carlo)\n * [Backtesting](#backtesting)\n * [Visualisation](#visualisation)\n* [Usage Examples & Synergy](#usage-examples--synergy)\n * [1. Data Generation + Backtesting + Visualisation](#1-data-generation--backtesting--visualisation)\n * [2. Monte Carlo + Backtesting + Visualisation](#2-monte-carlo--backtesting--visualisation)\n * [3. Exotic Options Pricing](#3-exotic-options-pricing)\n* [Roadmap](#roadmap)\n* [Licence](#license)\n* [Contact/Support](#contact)\n\n## Installation\n\nQuantLite is available on [PyPI](https://pypi.org/project/quantlite/). Install it simply by:\n\n```bash\npip install quantlite\n```\n\n(Ensure you\u2019re using Python 3.8+.)\n## Modules Overview\n\n### 1. Data Generation\nLocation: `quantlite.data_generation`\n* `geometric_brownian_motion`: Single-asset GBM path generation.\n* `correlated_gbm`: Multi-asset correlated path generation using covariance matrices.\n* `ornstein_uhlenbeck`: Mean-reverting process.\n* `merton_jump_diffusion`: GBM with Poisson jump arrivals (Merton\u2019s model).\n\n#### Example:\n```python\nimport quantlite.data_generation as qd\nprices = qd.geometric_brownian_motion(S0=100, mu=0.05, sigma=0.2, steps=252)\nprint(prices[:10]) # First 10 days\n```\n### 2. Instruments (Bond, Vanilla Options, Exotic Options)\nLocation: `quantlite.instruments`\n\n* Bond Pricing (bond_pricing.py): bond_price, bond_yield_to_maturity, bond_duration, etc.\n* Vanilla Options (option_pricing.py): black_scholes_call, black_scholes_put, plus Greeks.\n* Exotic Options (exotic_options.py): barrier_option_knock_out, asian_option_arithmetic\n\nExample:\n```python\nfrom quantlite.instruments.option_pricing import black_scholes_call\ncall_val = black_scholes_call(S=100, K=95, T=1, r=0.01, sigma=0.2)\nprint(\"Vanilla call option price:\", call_val)\n```\n\n### 3. Monte Carlo\nLocation: `quantlite.monte_carlo`\n\n* run_monte_carlo_sims: Single-asset multi-sim approach with different random \"modes.\"\n* multi_asset_correlated_sim: Direct correlated multi-asset simulation (similar to * data_generation.correlated_gbm, but designed for scenario testing).\n\nExample:\n\n```python\nimport pandas as pd\nfrom quantlite.monte_carlo import run_monte_carlo_sims\n\nprice_data = pd.Series([100, 101, 99, 102], index=[1,2,3,4])\ndef always_buy(idx, series):\n return 1\n\nmc_results = run_monte_carlo_sims(price_data, always_buy, n_sims=5)\nfor i, res in enumerate(mc_results):\n print(\"Sim\", i, \"final value:\", res[\"final_value\"])\n```\n### 4. Backtesting\nLocation: `quantlite.backtesting`\n\nA robust function `run_backtest` with partial capital, short-selling toggles, and transaction cost modelling.\n\nExample:\n```python\ndef run_backtest(\n price_data,\n signal_function,\n initial_capital=10_000.0,\n fee=0.0,\n partial_capital=False,\n capital_fraction=1.0,\n allow_short=True,\n per_share_cost=0.0\n):\n```\n\n### 5. Visualisation\nLocation: `quantlite.visualisation`\n\n* `plot_time_series`: Basic line chart with optional indicators.\n* `plot_ohlc`: Candlesticks or OHLC bars via mplfinance.\n* `plot_return_distribution`: Histogram + KDE for returns.\n* `plot_equity_curve`: Equity curve with optional drawdown shading.\n* `plot_multiple_equity_curves`: Compare multiple strategies and optionally show rolling Sharpe.\n\nExample:\n\n```python\nfrom quantlite.visualisation import plot_equity_curve\n# Suppose we have a backtest result with result[\"portfolio_value\"]\nplot_equity_curve(result[\"portfolio_value\"], drawdowns=True)\n```\n## Usage Examples & Synergy\nBelow are extended examples to show how modules can be combined.\n\n### 1. Data Generation + Backtesting + Visualisation\n\n```python\nimport quantlite.data_generation as qd\nfrom quantlite.backtesting import run_backtest\nfrom quantlite.visualisation import plot_equity_curve\nimport pandas as pd\n\n# 1. Create synthetic price data\nprices_array = qd.merton_jump_diffusion(S0=100, mu=0.06, sigma=0.25, steps=252, rng_seed=42)\nprices_series = pd.Series(prices_array, index=range(253))\n\n# 2. Simple signal: Buy if today's price < yesterday's\ndef naive_signal(idx, series):\n if idx == 0:\n return 0\n return 1 if series.iloc[idx] < series.iloc[idx-1] else 0\n\n# 3. Run backtest with partial capital\nresult = run_backtest(prices_series, naive_signal, fee=1.0, partial_capital=True, capital_fraction=0.5)\n\n# 4. Visualise\nplot_equity_curve(result[\"portfolio_value\"], drawdowns=True)\nprint(\"Final portfolio value:\", result[\"final_value\"])\n```\n\n### 2. Monte Carlo + Backtesting + Visualisation\n```python\nimport pandas as pd\nfrom quantlite.monte_carlo import run_monte_carlo_sims\nfrom quantlite.visualisation import plot_multiple_equity_curves\n\nprices = pd.Series([100, 101, 102, 103, 99, 98, 101, 102], index=range(8))\ndef always_long(idx, series):\n return 1\n\n# Multiple sims\nresults = run_monte_carlo_sims(prices, always_long, n_sims=3, mode=\"replace\")\ncurves = {}\nfor i, res in enumerate(results):\n curves[f\"Sim {i}\"] = res[\"portfolio_value\"]\n\nplot_multiple_equity_curves(curves_dict=curves, rolling_sharpe=True)\n```\n\n### 3. Exotic Options Pricing\n```python\nfrom quantlite.instruments.exotic_options import barrier_option_knock_out, asian_option_arithmetic\n\nbarrier_val = barrier_option_knock_out(\n S0=120, K=100, H=90, T=1.0, r=0.01, sigma=0.2,\n option_type=\"call\", barrier_type=\"down-and-out\",\n steps=252, sims=10000, rng_seed=42\n)\nprint(\"Knock-out barrier call value:\", barrier_val)\n\nasian_val = asian_option_arithmetic(\n S0=120, K=100, T=1.0, r=0.01, sigma=0.2,\n option_type=\"call\", steps=252, sims=10000, rng_seed=42\n)\nprint(\"Arithmetic average Asian call value:\", asian_val)\n```\n\n\n## Roadmap\n\n1. More Data Generation: \n * Stochastic volatility (Heston model)\n * Regime-switching\n2. Deeper Monte Carlo: \n * Correlated jumps\n * Advanced param sweeps\n * Multi-factor models\n3. Backtesting Enhancements: \n * Multi-asset portfolio rebalancing\n * Advanced slippage\n * Partial fills.\n4. More Exotic Instruments: \n * Up-and-out barrier\n * Lookback options\n5. Interactive Visualisation:\n * Plotly or Bokeh integration \n * Auto-report generation.\n\n## Licence\nThis project is distributed under the MIT License.\nSee the LICENSE file for the full text.\n\n## Contact/Support\n**Need help or want to contribute?** \n> Please open an issue on our [GitHub repo](https://github.com/prasants/quantlite).\n \n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Prasant Sudhakaran Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "A robust quant finance library",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [
"quant",
" finance",
" monte carlo",
" exotic options"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4f527b70b5822307b0fc58c1e6902a0124c204aabf677a2cab40793413beca21",
"md5": "e8e85bec1833b17185d46a8bb10f4e63",
"sha256": "4fb1b5b8e46230e8550eb4bf5f8814ba8cd427a5ff7bc0f54dea09354a4fae3f"
},
"downloads": -1,
"filename": "QuantLite-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e8e85bec1833b17185d46a8bb10f4e63",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 15031,
"upload_time": "2024-12-25T17:51:15",
"upload_time_iso_8601": "2024-12-25T17:51:15.046795Z",
"url": "https://files.pythonhosted.org/packages/4f/52/7b70b5822307b0fc58c1e6902a0124c204aabf677a2cab40793413beca21/QuantLite-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d2ef7852fd063258a274eeb974d052200a419e7f787ac1f599fd531bebeb3c20",
"md5": "f3101f59f9c29ee70553958b1be47465",
"sha256": "212f2a3e09a5672205bc3fb9a70650d929cefc9b6c4da2899a8fd42c9bf01653"
},
"downloads": -1,
"filename": "quantlite-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "f3101f59f9c29ee70553958b1be47465",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 15137,
"upload_time": "2024-12-25T17:51:17",
"upload_time_iso_8601": "2024-12-25T17:51:17.489808Z",
"url": "https://files.pythonhosted.org/packages/d2/ef/7852fd063258a274eeb974d052200a419e7f787ac1f599fd531bebeb3c20/quantlite-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-25 17:51:17",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "quantlite"
}