Skip to content

Commit 4815f50

Browse files
committed
Version 6.2.0
- Improvement in calculation speed of duplication_matrix, duplication_elimination_matrix and duplication_summation_matrix functions using a vectorized formula. - Fixed formulation of risk parity with risk factors model that produced incorrect results when using the MOSEK solver. - Fixed some bugs in PlotFunctions module. - Fixed some bugs in HCPortfolio related to custom_mu vector and use of Kurtosis and Semi Kurtosis as risk measures. - Standardized the way additional parameters to estimate mean vector and covariance matrix are entered.
1 parent 79654c3 commit 4815f50

File tree

66 files changed

+25227
-23704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+25227
-23704
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,8 @@ jobs:
3535
strategy:
3636
fail-fast: false
3737
matrix:
38-
os: [ ubuntu-20.04, macos-11, windows-2022 ]
39-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
40-
# include:
41-
# - os: ubuntu-20.04
42-
# python-version: 3.8
43-
# openmp: "True"
44-
# - os: ubuntu-20.04
45-
# python-version: 3.8
46-
# - os: macos-11
47-
# python-version: 3.8
48-
# single_action_config: "True"
49-
# - os: windows-2022
50-
# python-version: 3.8
51-
38+
os: [ ubuntu-20.04, macos-12, windows-2022 ]
39+
python-version: ["3.9", "3.10", "3.11", "3.12"]
5240

5341
env:
5442
RUNNER_OS: ${{ matrix.os }}
@@ -90,16 +78,8 @@ jobs:
9078
strategy:
9179
fail-fast: false
9280
matrix:
93-
os: [ ubuntu-20.04, macos-11, windows-2022 ]
94-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
95-
# include:
96-
# - os: ubuntu-20.04
97-
# python-version: 3.8
98-
# - os: macos-11
99-
# python-version: 3.8
100-
# single_action_config: "True"
101-
# - os: windows-2022
102-
# python-version: 3.8
81+
os: [ ubuntu-20.04, macos-12, windows-2022 ]
82+
python-version: ["3.9", "3.10", "3.11", "3.12"]
10383

10484
env:
10585
RUNNER_OS: ${{ matrix.os }}

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ Changelog
1414
<a href='https://ko-fi.com/B0B833SXD' target='_blank'><img height='36'style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi1.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
1515

1616

17+
Version 6.2.0
18+
=============
19+
20+
- Improvement in calculation speed of duplication_matrix, duplication_elimination_matrix and duplication_summation_matrix functions using a vectorized formula.
21+
- Fixed formulation of risk parity with risk factors model that produced incorrect results when using the MOSEK solver.
22+
- Fixed some bugs in PlotFunctions module.
23+
- Fixed some bugs in HCPortfolio related to custom_mu vector and use of Kurtosis and Semi Kurtosis as risk measures.
24+
- Standardized the way additional parameters to estimate mean vector and covariance matrix are entered.
1725

1826
Version 6.1.0
1927
=============

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ Some of key functionalities that Riskfolio-Lib offers:
163163
- Tools to build views on assets and asset classes.
164164
- Tools to build views on risk factors.
165165
- Tools to build risk contribution constraints per asset classes.
166+
- Tools to build risk contribution constraints per risk factor using explicit risk factors and principal components.
166167
- Tools to build bounds constraints for Hierarchical Clustering Portfolios.
167168
- Tools to calculate risk measures.
168169
- Tools to calculate risk contributions per asset.
170+
- Tools to calculate risk contributions per risk factor.
169171
- Tools to calculate uncertainty sets for mean vector and covariance matrix.
170172
- Tools to calculate assets clusters based on codependence metrics.
171173
- Tools to estimate loadings matrix (Stepwise Regression and Principal Components Regression).
@@ -230,18 +232,18 @@ POW - refers to problems with 3-dimensional power cone constraints.
230232

231233
## Dependencies
232234

233-
Riskfolio-Lib supports Python 3.8|.
235+
Riskfolio-Lib supports Python 3.9 or higher.
234236

235237
Installation requires:
236238
- [numpy](http://www.numpy.org/) >= 1.24.0
237239
- [scipy](https://www.scipy.org/) >= 1.10.0
238240
- [pandas](https://pandas.pydata.org/) >= 2.0.0
239-
- [matplotlib](https://matplotlib.org/) >= 3.7.0
241+
- [matplotlib](https://matplotlib.org/) >= 3.8.0
240242
- [clarabel](https://oxfordcontrol.github.io/ClarabelDocs/stable/) >= 0.6.0
241-
- [cvxpy](https://www.cvxpy.org/) >= 1.4.0
243+
- [cvxpy](https://www.cvxpy.org/) >= 1.5.2
242244
- [scikit-learn](https://scikit-learn.org/stable/) >= 1.3.0
243245
- [statsmodels](https://www.statsmodels.org/) >= 0.13.5
244-
- [arch](https://bashtage.github.io/arch/) >= 5.4
246+
- [arch](https://bashtage.github.io/arch/) >= 7.0
245247
- [xlsxwriter](https://xlsxwriter.readthedocs.io) >= 3.1.2
246248
- [networkx](https://networkx.org) >= 3.0
247249
- [astropy](https://www.astropy.org) >= 5.1
@@ -260,7 +262,7 @@ If you use Riskfolio-Lib for published work, please use the following BibTeX ent
260262
```
261263
@misc{riskfolio,
262264
author = {Dany Cajas},
263-
title = {Riskfolio-Lib (6.1.0)},
265+
title = {Riskfolio-Lib (6.2.0)},
264266
year = {2024},
265267
url = {https://github.com/dcajasn/Riskfolio-Lib},
266268
}

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
copyright = '2020-2024, Dany Cajas'
2626
author = 'Dany Cajas'
2727

28-
__version__ = "6.1.1"
28+
__version__ = "6.2.0"
2929

3030
# The short X.Y version
3131
version = '.'.join(__version__.split('.')[:2])

docs/source/examples.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ Hierarchical Clustering Portfolio Optimization
7979
* `Hierarchical Equal Risk Contribution (HERC) with Constraints <https://nbviewer.jupyter.org/github/dcajasn/Riskfolio-Lib/blob/master/examples/Tutorial%2044%20-%20Hierarchical%20Equal%20Risk%20Contribution%20(HERC)%20Portfolio%20Optimization%20with%20Constraints.ipynb>`_.
8080
* `Nested Clustered Optimization (NCO) with Constraints <https://nbviewer.jupyter.org/github/dcajasn/Riskfolio-Lib/blob/master/examples/Tutorial%2045%20-%20Nested%20Clustered%20Optimization%20(NCO)%20Portfolio%20Optimization%20with%20Constraints.ipynb>`_.
8181

82+
8283
Graph Theory Constraints
8384
------------------------
8485
* `Hierarchical Clustering and Networks <https://nbviewer.jupyter.org/github/dcajasn/Riskfolio-Lib/blob/master/examples/Tutorial%2028%20-%20Hierarchical%20Clustering%20and%20Networks.ipynb>`_.
8586
* `Classic Mean Risk Optimization with Network and Dendrogram Constraints <https://nbviewer.jupyter.org/github/dcajasn/Riskfolio-Lib/blob/master/examples/Tutorial%2046%20-%20Classic%20Mean%20Risk%20Optimization%20with%20Network%20and%20Dendrogram%20Constraints.ipynb>`_.
8687

88+
8789
Backtesting
8890
-----------
89-
* `Multi Assets Algorithmic Trading Backtesting with transaction cost and slippage using Backtrader <https://nbviewer.jupyter.org/github/dcajasn/Riskfolio-Lib/blob/master/examples/Tutorial%205%20-%20Multi%20Assets%20Algorithmic%20Trading%20Backtesting%20with%20Backtrader.ipynb>`_ (matplotlib=3.2.2 for compatibility with backtrader=1.9.76.123).
90-
* `Multi Assets Algorithmic Trading Backtesting with Vectorbt <https://nbviewer.jupyter.org/github/dcajasn/Riskfolio-Lib/blob/master/examples/Tutorial%2018%20-%20Multi%20Assets%20Algorithmic%20Trading%20Backtesting%20with%20Vectorbt.ipynb>`_ (vectorbt=0.23.0).
91+
* `Multi Assets Algorithmic Trading Backtesting with transaction cost and slippage using Backtrader <https://nbviewer.jupyter.org/github/dcajasn/Riskfolio-Lib/blob/master/examples/Tutorial%205%20-%20Multi%20Assets%20Algorithmic%20Trading%20Backtesting%20with%20Backtrader.ipynb>`_ (matplotlib=3.2.2 for compatibility with backtrader=1.9.76.123. We don't recommend to try to reproduce this example due the compatibility problems of Backtrader).
92+
* `Multi Assets Algorithmic Trading Backtesting with Vectorbt <https://nbviewer.jupyter.org/github/dcajasn/Riskfolio-Lib/blob/master/examples/Tutorial%2018%20-%20Multi%20Assets%20Algorithmic%20Trading%20Backtesting%20with%20Vectorbt.ipynb>`_ (vectorbt=0.26.1).
9193

9294

9395
Excel and Reporting

docs/source/index.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ Riskfolio-Lib
4444
Description
4545
===========
4646

47-
Riskfolio-Lib is a library for making portfolio optimization and quantitative strategic asset allocation in Python made in Peru |:peru:|. Its objective is to help students, academics and practitioners to build investment portfolios based on mathematically complex models with low effort. It is built on top of
48-
`CVXPY <https://www.cvxpy.org/>`_ and closely integrated
49-
with `Pandas <https://pandas.pydata.org/>`_ data structures.
47+
Riskfolio-Lib is a library for making portfolio optimization and quantitative strategic asset allocation
48+
in Python made in Peru |:peru:|. Its objective is to help students, academics and practitioners to build
49+
investment portfolios based on mathematically complex models with low effort. It is built on top of
50+
`CVXPY <https://www.cvxpy.org/>`_ and closely integrated with `Pandas <https://pandas.pydata.org/>`_ data structures.
5051

5152
Some of key functionalities that Riskfolio-Lib offers:
5253

@@ -178,9 +179,11 @@ Some of key functionalities that Riskfolio-Lib offers:
178179
- Tools to build views on assets and asset classes.
179180
- Tools to build views on risk factors.
180181
- Tools to build risk contribution constraints per asset classes.
182+
- Tools to build risk contribution constraints per risk factor using explicit risk factors and principal components.
181183
- Tools to build bounds constraints for Hierarchical Clustering Portfolios.
182184
- Tools to calculate risk measures.
183185
- Tools to calculate risk contributions per asset.
186+
- Tools to calculate risk contributions per risk factor.
184187
- Tools to calculate uncertainty sets for mean vector and covariance matrix.
185188
- Tools to calculate assets clusters based on codependence metrics.
186189
- Tools to estimate loadings matrix (Stepwise Regression and Principal Components Regression).
@@ -307,7 +310,7 @@ If you use Riskfolio-Lib for published work, please use the following BibTeX ent
307310

308311
@misc{riskfolio,
309312
author = {Dany Cajas},
310-
title = {Riskfolio-Lib (6.1.0)},
313+
title = {Riskfolio-Lib (6.2.0)},
311314
year = {2024},
312315
url = {https://github.com/dcajasn/Riskfolio-Lib},
313316
}

docs/source/install.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ Dependencies
6969

7070
Riskfolio-Lib has the following dependencies:
7171

72-
* numpy>=1.18.0
73-
* scipy>=1.1.0
74-
* pandas>=1.0.0
75-
* matplotlib>=3.5.0
76-
* cvxpy>=1.3.1
77-
* scikit-learn>=1.0.0
78-
* statsmodels>=0.10.1
79-
* arch>=4.15
80-
* xlsxwriter>=1.3.7
81-
* networkx>=2.5.1
82-
* astropy>=4.3.1 (if there are problems check `astropy installation instructions <https://www.astropy.org>`_)
72+
* numpy>=1.24.0
73+
* pandas>=2.0.0
74+
* matplotlib>=3.8.0
75+
* clarabel>=0.6.0
76+
* cvxpy>=1.5.2
77+
* scikit-learn>=1.3.0
78+
* statsmodels>=0.13.5
79+
* arch>=7.0
80+
* xlsxwriter>=3.1.2
81+
* networkx>=3.0
82+
* astropy>=5.1 (if there are problems check `astropy installation instructions <https://www.astropy.org>`_)
8383
* pybind11>=2.10.1

docs/source/portfolio.rst

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ one of the following 4 objective functions:
2727
.. math::
2828
\begin{aligned}
2929
&\underset{w}{\max} & & R (w)\\
30-
&\text{s.t.} & & Aw \geq B\\
30+
&\text{s.t.} & & Aw \leq B\\
3131
& & &\phi_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,13] \\
3232
& & & R (w) \geq \overline{\mu}
3333
\end{aligned}
3434
35+
3536
- **Minimum Risk Portfolio:**
3637

3738
.. math::
3839
\begin{aligned}
3940
&\underset{w}{\min} & & \phi_{k}(w)\\
40-
&\text{s.t.} & & Aw \geq B\\
41+
&\text{s.t.} & & Aw \leq B\\
4142
& & &\phi_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,13] \\
4243
& & & R (w) \geq \overline{\mu}
4344
\end{aligned}
@@ -48,7 +49,7 @@ one of the following 4 objective functions:
4849
.. math::
4950
\begin{aligned}
5051
&\underset{w}{\max} & & \frac{R (w) - r_{f}}{\phi_{k}(w)}\\
51-
&\text{s.t.} & & Aw \geq B\\
52+
&\text{s.t.} & & Aw \leq B\\
5253
& & &\phi_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,13] \\
5354
& & & R (w) \geq \overline{\mu}
5455
\end{aligned}
@@ -59,13 +60,13 @@ one of the following 4 objective functions:
5960
.. math::
6061
\begin{aligned}
6162
&\underset{w}{\max} & & R (w) - \lambda \phi_{k}(w)\\
62-
&\text{s.t.} & & Aw \geq B\\
63+
&\text{s.t.} & & Aw \leq B\\
6364
& & &\phi_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,13] \\
6465
& & & R (w) \geq \overline{\mu}
6566
\end{aligned}
6667
6768
68-
Where:
69+
where:
6970

7071
:math:`R (w)` is the return function, posible values are:
7172

@@ -81,7 +82,7 @@ Where:
8182

8283
:math:`r`: is the matrix of assets returns.
8384

84-
:math:`Aw \geq B`: is a set of linear constraints.
85+
:math:`Aw \leq B`: is a set of linear constraints.
8586

8687
:math:`\phi_{i}(w)`: are 20 available risk measures. The available risk
8788
measures are:
@@ -128,20 +129,20 @@ the general vanilla risk parity model :cite:`a-Roncalli` :cite:`a-RichardRoncall
128129
&\underset{w}{\min} & & \phi(w) \\
129130
&\text{s.t.} & & b \log(w) \geq c \\
130131
& & & \mu w \geq \overline{\mu} \\
131-
& & & Aw \geq B \\
132+
& & & Aw \leq B \\
132133
& & & w \geq 0 \\
133134
\end{aligned}
134135
135136
136-
Where:
137+
where:
137138

138139
:math:`w`: is the vector of weights of the optimum portfolio.
139140

140141
:math:`\mu`: is the vector of expected returns.
141142

142143
:math:`b`: is a vector of risk contribution constraints.
143144

144-
:math:`Aw \geq B`: is a set of linear constraints.
145+
:math:`Aw \leq B`: is a set of linear constraints.
145146

146147
:math:`\phi(w)`: are 16 available risk measures. The available risk
147148
measures are:
@@ -182,13 +183,13 @@ the relaxed risk parity model :cite:`a-GambetaKwon`:
182183
& & & w_{i} \zeta_{i} \geq \gamma^{2} b_{i} & \forall i=1 , \ldots , N \\
183184
& & & \lambda x^{T} \Theta x \leq \rho^{2} & \\
184185
& & & \mu w \geq \overline{\mu} & \\
185-
& & & Aw \geq B & \\
186+
& & & Aw \leq B & \\
186187
& & & \sum^{N}_{i=1} w_{i} = 1 & \\
187188
& & & \psi, \gamma, \rho, w \geq 0 & \\
188189
\end{aligned}
189190
190191
191-
Where:
192+
where:
192193

193194
:math:`w`: is the vector of weights of the optimum portfolio.
194195

@@ -210,7 +211,7 @@ Where:
210211

211212
:math:`\Theta = \text{diag}(\Sigma)`
212213

213-
:math:`Aw \geq B`: is a set of linear constraints.
214+
:math:`Aw \leq B`: is a set of linear constraints.
214215

215216

216217
Worst Case Mean Variance Portfolio Optimization
@@ -226,7 +227,7 @@ that results from optimize one of the following 4 objective functions:
226227
.. math::
227228
\begin{aligned}
228229
&\underset{w}{\max} & & \underset{\mu \, \in \, U_{\mu}}{\min} \mu w\\
229-
&\text{s.t.} & & Aw \geq B\\
230+
&\text{s.t.} & & Aw \leq B\\
230231
\end{aligned}
231232
232233
@@ -235,7 +236,7 @@ that results from optimize one of the following 4 objective functions:
235236
.. math::
236237
\begin{aligned}
237238
&\underset{w}{\min} & & \underset{\Sigma \, \in \, U_{\Sigma}}{\max} w^{T} \Sigma w\\
238-
&\text{s.t.} & & Aw \geq B\\
239+
&\text{s.t.} & & Aw \leq B\\
239240
\end{aligned}
240241
241242
@@ -245,7 +246,7 @@ that results from optimize one of the following 4 objective functions:
245246
\begin{aligned}
246247
&\underset{w}{\max} & & \cfrac{\underset{\mu \, \in \, U_{\mu}}{\min} \mu w - r_{f}}
247248
{\underset{\Sigma \, \in \, U_{\Sigma}}{\max} \sqrt{w^{T} \Sigma w}}\\
248-
&\text{s.t.} & & Aw \geq B\\
249+
&\text{s.t.} & & Aw \leq B\\
249250
\end{aligned}
250251
251252
@@ -255,11 +256,11 @@ that results from optimize one of the following 4 objective functions:
255256
\begin{aligned}
256257
&\underset{w}{\max} & & \underset{\mu \, \in \, U_{\mu}}{\min} \mu w
257258
- \underset{\Sigma \, \in \, U_{\Sigma}}{\max} \lambda w^{T} \Sigma w\\
258-
&\text{s.t.} & & Aw \geq B\\
259+
&\text{s.t.} & & Aw \leq B\\
259260
\end{aligned}
260261
261262
262-
Where:
263+
where:
263264

264265
:math:`w` are the weights of the portfolio.
265266

@@ -285,7 +286,7 @@ Where:
285286
\end{aligned}
286287
287288
288-
:math:`Aw \geq B`: is a set of linear constraints.
289+
:math:`Aw \leq B`: is a set of linear constraints.
289290

290291
:math:`r_{f}`: is the risk free rate.
291292

@@ -303,7 +304,7 @@ this function to calculate the Higher L-Moment portfolio optimization model :cit
303304
.. math::
304305
\begin{aligned}
305306
&\underset{w}{\min} & & \sum^{T}_{i=0} v_{[i]}y_{[i]} \\
306-
&\text{s.t.} & & Aw \geq B\\
307+
&\text{s.t.} & & Aw \leq B\\
307308
& & & y = rw \\
308309
& & & R (w) \geq \overline{\mu} \\
309310
\end{aligned}
@@ -313,7 +314,7 @@ this function to calculate the Higher L-Moment portfolio optimization model :cit
313314
.. math::
314315
\begin{aligned}
315316
&\underset{w}{\max} & & \frac{R (w) - r_{f}}{\sum^{T}_{i=0} v_{[i]}y_{[i]}}\\
316-
&\text{s.t.} & & Aw \geq B\\
317+
&\text{s.t.} & & Aw \leq B\\
317318
& & & y = rw \\
318319
& & & R (w) \geq \overline{\mu} \\
319320
\end{aligned}
@@ -323,7 +324,7 @@ this function to calculate the Higher L-Moment portfolio optimization model :cit
323324
.. math::
324325
\begin{aligned}
325326
&\underset{w}{\max} & & R (w) - \lambda \left ( \sum^{T}_{i=0} v_{[i]}y_{[i]} \right) \\
326-
&\text{s.t.} & & Aw \geq B\\
327+
&\text{s.t.} & & Aw \leq B\\
327328
& & & y = rw \\
328329
& & & R (w) \geq \overline{\mu} \\
329330
\end{aligned}

0 commit comments

Comments
 (0)