quantlite 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quantlite-0.1.0/LICENSE +22 -0
- quantlite-0.1.0/PKG-INFO +247 -0
- quantlite-0.1.0/README.md +209 -0
- quantlite-0.1.0/pyproject.toml +29 -0
- quantlite-0.1.0/setup.cfg +4 -0
- quantlite-0.1.0/src/QuantLite.egg-info/PKG-INFO +247 -0
- quantlite-0.1.0/src/QuantLite.egg-info/SOURCES.txt +24 -0
- quantlite-0.1.0/src/QuantLite.egg-info/dependency_links.txt +1 -0
- quantlite-0.1.0/src/QuantLite.egg-info/requires.txt +5 -0
- quantlite-0.1.0/src/QuantLite.egg-info/top_level.txt +1 -0
- quantlite-0.1.0/src/quantlite/__init__.py +29 -0
- quantlite-0.1.0/src/quantlite/backtesting.py +110 -0
- quantlite-0.1.0/src/quantlite/data_generation.py +131 -0
- quantlite-0.1.0/src/quantlite/instruments/__init__.py +2 -0
- quantlite-0.1.0/src/quantlite/instruments/bond_pricing.py +53 -0
- quantlite-0.1.0/src/quantlite/instruments/exotic_options.py +121 -0
- quantlite-0.1.0/src/quantlite/instruments/option_pricing.py +60 -0
- quantlite-0.1.0/src/quantlite/metrics.py +38 -0
- quantlite-0.1.0/src/quantlite/monte_carlo.py +118 -0
- quantlite-0.1.0/src/quantlite/visualisation.py +139 -0
- quantlite-0.1.0/tests/test_backtesting.py +64 -0
- quantlite-0.1.0/tests/test_data_generation.py +61 -0
- quantlite-0.1.0/tests/test_instruments.py +82 -0
- quantlite-0.1.0/tests/test_metrics.py +33 -0
- quantlite-0.1.0/tests/test_monte_carlo.py +54 -0
- quantlite-0.1.0/tests/test_visualisation.py +45 -0
quantlite-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Prasant Sudhakaran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
quantlite-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: QuantLite
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A robust quant finance library
|
|
5
|
+
Author-email: Prasant Sudhakaran <code@prasant.net>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Prasant Sudhakaran
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
Keywords: quant,finance,monte carlo,exotic options
|
|
30
|
+
Requires-Python: >=3.8
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Requires-Dist: numpy
|
|
34
|
+
Requires-Dist: pandas
|
|
35
|
+
Requires-Dist: scipy
|
|
36
|
+
Requires-Dist: matplotlib
|
|
37
|
+
Requires-Dist: mplfinance
|
|
38
|
+
|
|
39
|
+
# QuantLite
|
|
40
|
+
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+
## Table of Contents
|
|
44
|
+
|
|
45
|
+
* [Installation](#installation)
|
|
46
|
+
* [Modules Overview](#modules-overview)
|
|
47
|
+
* [Data Generation](#data-generation)
|
|
48
|
+
* [Instruments (Bond, Vanilla Options, Exotic Options)](#instruments)
|
|
49
|
+
* [Monte Carlo](#monte-carlo)
|
|
50
|
+
* [Backtesting](#backtesting)
|
|
51
|
+
* [Visualisation](#visualisation)
|
|
52
|
+
* [Usage Examples & Synergy](#usage-examples--synergy)
|
|
53
|
+
* [1. Data Generation + Backtesting + Visualisation](#1-data-generation--backtesting--visualisation)
|
|
54
|
+
* [2. Monte Carlo + Backtesting + Visualisation](#2-monte-carlo--backtesting--visualisation)
|
|
55
|
+
* [3. Exotic Options Pricing](#3-exotic-options-pricing)
|
|
56
|
+
* [Roadmap](#roadmap)
|
|
57
|
+
* [Licence](#license)
|
|
58
|
+
* [Contact/Support](#contact)
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
QuantLite is available on [PyPI](https://pypi.org/project/quantlite/). Install it simply by:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install quantlite
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
(Ensure you’re using Python 3.8+.)
|
|
69
|
+
## Modules Overview
|
|
70
|
+
|
|
71
|
+
### 1. Data Generation
|
|
72
|
+
Location: `quantlite.data_generation`
|
|
73
|
+
* `geometric_brownian_motion`: Single-asset GBM path generation.
|
|
74
|
+
* `correlated_gbm`: Multi-asset correlated path generation using covariance matrices.
|
|
75
|
+
* `ornstein_uhlenbeck`: Mean-reverting process.
|
|
76
|
+
* `merton_jump_diffusion`: GBM with Poisson jump arrivals (Merton’s model).
|
|
77
|
+
|
|
78
|
+
#### Example:
|
|
79
|
+
```python
|
|
80
|
+
import quantlite.data_generation as qd
|
|
81
|
+
prices = qd.geometric_brownian_motion(S0=100, mu=0.05, sigma=0.2, steps=252)
|
|
82
|
+
print(prices[:10]) # First 10 days
|
|
83
|
+
```
|
|
84
|
+
### 2. Instruments (Bond, Vanilla Options, Exotic Options)
|
|
85
|
+
Location: `quantlite.instruments`
|
|
86
|
+
|
|
87
|
+
* Bond Pricing (bond_pricing.py): bond_price, bond_yield_to_maturity, bond_duration, etc.
|
|
88
|
+
* Vanilla Options (option_pricing.py): black_scholes_call, black_scholes_put, plus Greeks.
|
|
89
|
+
* Exotic Options (exotic_options.py): barrier_option_knock_out, asian_option_arithmetic
|
|
90
|
+
|
|
91
|
+
Example:
|
|
92
|
+
```python
|
|
93
|
+
from quantlite.instruments.option_pricing import black_scholes_call
|
|
94
|
+
call_val = black_scholes_call(S=100, K=95, T=1, r=0.01, sigma=0.2)
|
|
95
|
+
print("Vanilla call option price:", call_val)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 3. Monte Carlo
|
|
99
|
+
Location: `quantlite.monte_carlo`
|
|
100
|
+
|
|
101
|
+
* run_monte_carlo_sims: Single-asset multi-sim approach with different random "modes."
|
|
102
|
+
* multi_asset_correlated_sim: Direct correlated multi-asset simulation (similar to * data_generation.correlated_gbm, but designed for scenario testing).
|
|
103
|
+
|
|
104
|
+
Example:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
import pandas as pd
|
|
108
|
+
from quantlite.monte_carlo import run_monte_carlo_sims
|
|
109
|
+
|
|
110
|
+
price_data = pd.Series([100, 101, 99, 102], index=[1,2,3,4])
|
|
111
|
+
def always_buy(idx, series):
|
|
112
|
+
return 1
|
|
113
|
+
|
|
114
|
+
mc_results = run_monte_carlo_sims(price_data, always_buy, n_sims=5)
|
|
115
|
+
for i, res in enumerate(mc_results):
|
|
116
|
+
print("Sim", i, "final value:", res["final_value"])
|
|
117
|
+
```
|
|
118
|
+
### 4. Backtesting
|
|
119
|
+
Location: `quantlite.backtesting`
|
|
120
|
+
|
|
121
|
+
A robust function `run_backtest` with partial capital, short-selling toggles, and transaction cost modelling.
|
|
122
|
+
|
|
123
|
+
Example:
|
|
124
|
+
```python
|
|
125
|
+
def run_backtest(
|
|
126
|
+
price_data,
|
|
127
|
+
signal_function,
|
|
128
|
+
initial_capital=10_000.0,
|
|
129
|
+
fee=0.0,
|
|
130
|
+
partial_capital=False,
|
|
131
|
+
capital_fraction=1.0,
|
|
132
|
+
allow_short=True,
|
|
133
|
+
per_share_cost=0.0
|
|
134
|
+
):
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 5. Visualisation
|
|
138
|
+
Location: `quantlite.visualisation`
|
|
139
|
+
|
|
140
|
+
* `plot_time_series`: Basic line chart with optional indicators.
|
|
141
|
+
* `plot_ohlc`: Candlesticks or OHLC bars via mplfinance.
|
|
142
|
+
* `plot_return_distribution`: Histogram + KDE for returns.
|
|
143
|
+
* `plot_equity_curve`: Equity curve with optional drawdown shading.
|
|
144
|
+
* `plot_multiple_equity_curves`: Compare multiple strategies and optionally show rolling Sharpe.
|
|
145
|
+
|
|
146
|
+
Example:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from quantlite.visualisation import plot_equity_curve
|
|
150
|
+
# Suppose we have a backtest result with result["portfolio_value"]
|
|
151
|
+
plot_equity_curve(result["portfolio_value"], drawdowns=True)
|
|
152
|
+
```
|
|
153
|
+
## Usage Examples & Synergy
|
|
154
|
+
Below are extended examples to show how modules can be combined.
|
|
155
|
+
|
|
156
|
+
### 1. Data Generation + Backtesting + Visualisation
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
import quantlite.data_generation as qd
|
|
160
|
+
from quantlite.backtesting import run_backtest
|
|
161
|
+
from quantlite.visualisation import plot_equity_curve
|
|
162
|
+
import pandas as pd
|
|
163
|
+
|
|
164
|
+
# 1. Create synthetic price data
|
|
165
|
+
prices_array = qd.merton_jump_diffusion(S0=100, mu=0.06, sigma=0.25, steps=252, rng_seed=42)
|
|
166
|
+
prices_series = pd.Series(prices_array, index=range(253))
|
|
167
|
+
|
|
168
|
+
# 2. Simple signal: Buy if today's price < yesterday's
|
|
169
|
+
def naive_signal(idx, series):
|
|
170
|
+
if idx == 0:
|
|
171
|
+
return 0
|
|
172
|
+
return 1 if series.iloc[idx] < series.iloc[idx-1] else 0
|
|
173
|
+
|
|
174
|
+
# 3. Run backtest with partial capital
|
|
175
|
+
result = run_backtest(prices_series, naive_signal, fee=1.0, partial_capital=True, capital_fraction=0.5)
|
|
176
|
+
|
|
177
|
+
# 4. Visualise
|
|
178
|
+
plot_equity_curve(result["portfolio_value"], drawdowns=True)
|
|
179
|
+
print("Final portfolio value:", result["final_value"])
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 2. Monte Carlo + Backtesting + Visualisation
|
|
183
|
+
```python
|
|
184
|
+
import pandas as pd
|
|
185
|
+
from quantlite.monte_carlo import run_monte_carlo_sims
|
|
186
|
+
from quantlite.visualisation import plot_multiple_equity_curves
|
|
187
|
+
|
|
188
|
+
prices = pd.Series([100, 101, 102, 103, 99, 98, 101, 102], index=range(8))
|
|
189
|
+
def always_long(idx, series):
|
|
190
|
+
return 1
|
|
191
|
+
|
|
192
|
+
# Multiple sims
|
|
193
|
+
results = run_monte_carlo_sims(prices, always_long, n_sims=3, mode="replace")
|
|
194
|
+
curves = {}
|
|
195
|
+
for i, res in enumerate(results):
|
|
196
|
+
curves[f"Sim {i}"] = res["portfolio_value"]
|
|
197
|
+
|
|
198
|
+
plot_multiple_equity_curves(curves_dict=curves, rolling_sharpe=True)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### 3. Exotic Options Pricing
|
|
202
|
+
```python
|
|
203
|
+
from quantlite.instruments.exotic_options import barrier_option_knock_out, asian_option_arithmetic
|
|
204
|
+
|
|
205
|
+
barrier_val = barrier_option_knock_out(
|
|
206
|
+
S0=120, K=100, H=90, T=1.0, r=0.01, sigma=0.2,
|
|
207
|
+
option_type="call", barrier_type="down-and-out",
|
|
208
|
+
steps=252, sims=10000, rng_seed=42
|
|
209
|
+
)
|
|
210
|
+
print("Knock-out barrier call value:", barrier_val)
|
|
211
|
+
|
|
212
|
+
asian_val = asian_option_arithmetic(
|
|
213
|
+
S0=120, K=100, T=1.0, r=0.01, sigma=0.2,
|
|
214
|
+
option_type="call", steps=252, sims=10000, rng_seed=42
|
|
215
|
+
)
|
|
216
|
+
print("Arithmetic average Asian call value:", asian_val)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
## Roadmap
|
|
221
|
+
|
|
222
|
+
1. More Data Generation:
|
|
223
|
+
* Stochastic volatility (Heston model)
|
|
224
|
+
* Regime-switching
|
|
225
|
+
2. Deeper Monte Carlo:
|
|
226
|
+
* Correlated jumps
|
|
227
|
+
* Advanced param sweeps
|
|
228
|
+
* Multi-factor models
|
|
229
|
+
3. Backtesting Enhancements:
|
|
230
|
+
* Multi-asset portfolio rebalancing
|
|
231
|
+
* Advanced slippage
|
|
232
|
+
* Partial fills.
|
|
233
|
+
4. More Exotic Instruments:
|
|
234
|
+
* Up-and-out barrier
|
|
235
|
+
* Lookback options
|
|
236
|
+
5. Interactive Visualisation:
|
|
237
|
+
* Plotly or Bokeh integration
|
|
238
|
+
* Auto-report generation.
|
|
239
|
+
|
|
240
|
+
## Licence
|
|
241
|
+
This project is distributed under the MIT License.
|
|
242
|
+
See the LICENSE file for the full text.
|
|
243
|
+
|
|
244
|
+
## Contact/Support
|
|
245
|
+
**Need help or want to contribute?**
|
|
246
|
+
> Please open an issue on our [GitHub repo](https://github.com/prasants/quantlite).
|
|
247
|
+
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# QuantLite
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
* [Installation](#installation)
|
|
8
|
+
* [Modules Overview](#modules-overview)
|
|
9
|
+
* [Data Generation](#data-generation)
|
|
10
|
+
* [Instruments (Bond, Vanilla Options, Exotic Options)](#instruments)
|
|
11
|
+
* [Monte Carlo](#monte-carlo)
|
|
12
|
+
* [Backtesting](#backtesting)
|
|
13
|
+
* [Visualisation](#visualisation)
|
|
14
|
+
* [Usage Examples & Synergy](#usage-examples--synergy)
|
|
15
|
+
* [1. Data Generation + Backtesting + Visualisation](#1-data-generation--backtesting--visualisation)
|
|
16
|
+
* [2. Monte Carlo + Backtesting + Visualisation](#2-monte-carlo--backtesting--visualisation)
|
|
17
|
+
* [3. Exotic Options Pricing](#3-exotic-options-pricing)
|
|
18
|
+
* [Roadmap](#roadmap)
|
|
19
|
+
* [Licence](#license)
|
|
20
|
+
* [Contact/Support](#contact)
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
QuantLite is available on [PyPI](https://pypi.org/project/quantlite/). Install it simply by:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install quantlite
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
(Ensure you’re using Python 3.8+.)
|
|
31
|
+
## Modules Overview
|
|
32
|
+
|
|
33
|
+
### 1. Data Generation
|
|
34
|
+
Location: `quantlite.data_generation`
|
|
35
|
+
* `geometric_brownian_motion`: Single-asset GBM path generation.
|
|
36
|
+
* `correlated_gbm`: Multi-asset correlated path generation using covariance matrices.
|
|
37
|
+
* `ornstein_uhlenbeck`: Mean-reverting process.
|
|
38
|
+
* `merton_jump_diffusion`: GBM with Poisson jump arrivals (Merton’s model).
|
|
39
|
+
|
|
40
|
+
#### Example:
|
|
41
|
+
```python
|
|
42
|
+
import quantlite.data_generation as qd
|
|
43
|
+
prices = qd.geometric_brownian_motion(S0=100, mu=0.05, sigma=0.2, steps=252)
|
|
44
|
+
print(prices[:10]) # First 10 days
|
|
45
|
+
```
|
|
46
|
+
### 2. Instruments (Bond, Vanilla Options, Exotic Options)
|
|
47
|
+
Location: `quantlite.instruments`
|
|
48
|
+
|
|
49
|
+
* Bond Pricing (bond_pricing.py): bond_price, bond_yield_to_maturity, bond_duration, etc.
|
|
50
|
+
* Vanilla Options (option_pricing.py): black_scholes_call, black_scholes_put, plus Greeks.
|
|
51
|
+
* Exotic Options (exotic_options.py): barrier_option_knock_out, asian_option_arithmetic
|
|
52
|
+
|
|
53
|
+
Example:
|
|
54
|
+
```python
|
|
55
|
+
from quantlite.instruments.option_pricing import black_scholes_call
|
|
56
|
+
call_val = black_scholes_call(S=100, K=95, T=1, r=0.01, sigma=0.2)
|
|
57
|
+
print("Vanilla call option price:", call_val)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 3. Monte Carlo
|
|
61
|
+
Location: `quantlite.monte_carlo`
|
|
62
|
+
|
|
63
|
+
* run_monte_carlo_sims: Single-asset multi-sim approach with different random "modes."
|
|
64
|
+
* multi_asset_correlated_sim: Direct correlated multi-asset simulation (similar to * data_generation.correlated_gbm, but designed for scenario testing).
|
|
65
|
+
|
|
66
|
+
Example:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import pandas as pd
|
|
70
|
+
from quantlite.monte_carlo import run_monte_carlo_sims
|
|
71
|
+
|
|
72
|
+
price_data = pd.Series([100, 101, 99, 102], index=[1,2,3,4])
|
|
73
|
+
def always_buy(idx, series):
|
|
74
|
+
return 1
|
|
75
|
+
|
|
76
|
+
mc_results = run_monte_carlo_sims(price_data, always_buy, n_sims=5)
|
|
77
|
+
for i, res in enumerate(mc_results):
|
|
78
|
+
print("Sim", i, "final value:", res["final_value"])
|
|
79
|
+
```
|
|
80
|
+
### 4. Backtesting
|
|
81
|
+
Location: `quantlite.backtesting`
|
|
82
|
+
|
|
83
|
+
A robust function `run_backtest` with partial capital, short-selling toggles, and transaction cost modelling.
|
|
84
|
+
|
|
85
|
+
Example:
|
|
86
|
+
```python
|
|
87
|
+
def run_backtest(
|
|
88
|
+
price_data,
|
|
89
|
+
signal_function,
|
|
90
|
+
initial_capital=10_000.0,
|
|
91
|
+
fee=0.0,
|
|
92
|
+
partial_capital=False,
|
|
93
|
+
capital_fraction=1.0,
|
|
94
|
+
allow_short=True,
|
|
95
|
+
per_share_cost=0.0
|
|
96
|
+
):
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 5. Visualisation
|
|
100
|
+
Location: `quantlite.visualisation`
|
|
101
|
+
|
|
102
|
+
* `plot_time_series`: Basic line chart with optional indicators.
|
|
103
|
+
* `plot_ohlc`: Candlesticks or OHLC bars via mplfinance.
|
|
104
|
+
* `plot_return_distribution`: Histogram + KDE for returns.
|
|
105
|
+
* `plot_equity_curve`: Equity curve with optional drawdown shading.
|
|
106
|
+
* `plot_multiple_equity_curves`: Compare multiple strategies and optionally show rolling Sharpe.
|
|
107
|
+
|
|
108
|
+
Example:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from quantlite.visualisation import plot_equity_curve
|
|
112
|
+
# Suppose we have a backtest result with result["portfolio_value"]
|
|
113
|
+
plot_equity_curve(result["portfolio_value"], drawdowns=True)
|
|
114
|
+
```
|
|
115
|
+
## Usage Examples & Synergy
|
|
116
|
+
Below are extended examples to show how modules can be combined.
|
|
117
|
+
|
|
118
|
+
### 1. Data Generation + Backtesting + Visualisation
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import quantlite.data_generation as qd
|
|
122
|
+
from quantlite.backtesting import run_backtest
|
|
123
|
+
from quantlite.visualisation import plot_equity_curve
|
|
124
|
+
import pandas as pd
|
|
125
|
+
|
|
126
|
+
# 1. Create synthetic price data
|
|
127
|
+
prices_array = qd.merton_jump_diffusion(S0=100, mu=0.06, sigma=0.25, steps=252, rng_seed=42)
|
|
128
|
+
prices_series = pd.Series(prices_array, index=range(253))
|
|
129
|
+
|
|
130
|
+
# 2. Simple signal: Buy if today's price < yesterday's
|
|
131
|
+
def naive_signal(idx, series):
|
|
132
|
+
if idx == 0:
|
|
133
|
+
return 0
|
|
134
|
+
return 1 if series.iloc[idx] < series.iloc[idx-1] else 0
|
|
135
|
+
|
|
136
|
+
# 3. Run backtest with partial capital
|
|
137
|
+
result = run_backtest(prices_series, naive_signal, fee=1.0, partial_capital=True, capital_fraction=0.5)
|
|
138
|
+
|
|
139
|
+
# 4. Visualise
|
|
140
|
+
plot_equity_curve(result["portfolio_value"], drawdowns=True)
|
|
141
|
+
print("Final portfolio value:", result["final_value"])
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 2. Monte Carlo + Backtesting + Visualisation
|
|
145
|
+
```python
|
|
146
|
+
import pandas as pd
|
|
147
|
+
from quantlite.monte_carlo import run_monte_carlo_sims
|
|
148
|
+
from quantlite.visualisation import plot_multiple_equity_curves
|
|
149
|
+
|
|
150
|
+
prices = pd.Series([100, 101, 102, 103, 99, 98, 101, 102], index=range(8))
|
|
151
|
+
def always_long(idx, series):
|
|
152
|
+
return 1
|
|
153
|
+
|
|
154
|
+
# Multiple sims
|
|
155
|
+
results = run_monte_carlo_sims(prices, always_long, n_sims=3, mode="replace")
|
|
156
|
+
curves = {}
|
|
157
|
+
for i, res in enumerate(results):
|
|
158
|
+
curves[f"Sim {i}"] = res["portfolio_value"]
|
|
159
|
+
|
|
160
|
+
plot_multiple_equity_curves(curves_dict=curves, rolling_sharpe=True)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 3. Exotic Options Pricing
|
|
164
|
+
```python
|
|
165
|
+
from quantlite.instruments.exotic_options import barrier_option_knock_out, asian_option_arithmetic
|
|
166
|
+
|
|
167
|
+
barrier_val = barrier_option_knock_out(
|
|
168
|
+
S0=120, K=100, H=90, T=1.0, r=0.01, sigma=0.2,
|
|
169
|
+
option_type="call", barrier_type="down-and-out",
|
|
170
|
+
steps=252, sims=10000, rng_seed=42
|
|
171
|
+
)
|
|
172
|
+
print("Knock-out barrier call value:", barrier_val)
|
|
173
|
+
|
|
174
|
+
asian_val = asian_option_arithmetic(
|
|
175
|
+
S0=120, K=100, T=1.0, r=0.01, sigma=0.2,
|
|
176
|
+
option_type="call", steps=252, sims=10000, rng_seed=42
|
|
177
|
+
)
|
|
178
|
+
print("Arithmetic average Asian call value:", asian_val)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
## Roadmap
|
|
183
|
+
|
|
184
|
+
1. More Data Generation:
|
|
185
|
+
* Stochastic volatility (Heston model)
|
|
186
|
+
* Regime-switching
|
|
187
|
+
2. Deeper Monte Carlo:
|
|
188
|
+
* Correlated jumps
|
|
189
|
+
* Advanced param sweeps
|
|
190
|
+
* Multi-factor models
|
|
191
|
+
3. Backtesting Enhancements:
|
|
192
|
+
* Multi-asset portfolio rebalancing
|
|
193
|
+
* Advanced slippage
|
|
194
|
+
* Partial fills.
|
|
195
|
+
4. More Exotic Instruments:
|
|
196
|
+
* Up-and-out barrier
|
|
197
|
+
* Lookback options
|
|
198
|
+
5. Interactive Visualisation:
|
|
199
|
+
* Plotly or Bokeh integration
|
|
200
|
+
* Auto-report generation.
|
|
201
|
+
|
|
202
|
+
## Licence
|
|
203
|
+
This project is distributed under the MIT License.
|
|
204
|
+
See the LICENSE file for the full text.
|
|
205
|
+
|
|
206
|
+
## Contact/Support
|
|
207
|
+
**Need help or want to contribute?**
|
|
208
|
+
> Please open an issue on our [GitHub repo](https://github.com/prasants/quantlite).
|
|
209
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "QuantLite"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A robust quant finance library"
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
|
|
11
|
+
# The license field references the file we just created
|
|
12
|
+
license = { file = "LICENSE" }
|
|
13
|
+
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
authors = [
|
|
16
|
+
{ name = "Prasant Sudhakaran", email = "code@prasant.net" }
|
|
17
|
+
]
|
|
18
|
+
keywords = ["quant", "finance", "monte carlo", "exotic options"]
|
|
19
|
+
|
|
20
|
+
dependencies = [
|
|
21
|
+
"numpy",
|
|
22
|
+
"pandas",
|
|
23
|
+
"scipy",
|
|
24
|
+
"matplotlib",
|
|
25
|
+
"mplfinance"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.packages.find]
|
|
29
|
+
where = ["src"]
|