Tool to test the out-of-sample performance of different portfolio optimization strategy
Still under construction…
This project comprises of three part, a Python package, a GUI and a web server. The package is the core of the project, it contains the functions to optimize the portfolio and to test the out-of-sample performance of the portfolio. The GUI is a simple interface to interact with the package, and the web server is a locally run api which fetches the latest data from the internet and runs the optimization and performance test.
Based on the paper: Optimal Versus Naive Diversification
The GUI is available at sidnand.github.io/Portfolio-Lab/.
The web server is available on GitHub.
This project was went to turn the original research paper into a general purpose application that could be used by finance hobbiests and researchers alike. It includes 11 pre-built models and for the tech savvy, the ability to create their own models. The models included are talked about below.
We will let:
This is the simplest model, it assigns equal weight to all the assets in the portfolio.
\[w = \frac{1}{n}\]This model seeks to minimize the variance of the portfolio, focusing on reducing risk without considering expected returns. This approach aims to find the portfolio that achieves the lowest risk (variance) while maintaining full investment (i.e., the sum of the weights equals 1).
subject to:
\[w^T \mathbf{1} = 1\]where:
The mean-variance optimization model seeks to maximize the return of a portfolio for a given level of risk, balancing expected returns and the variance of portfolio returns.
The optimization problem is formulated as:
\[\max \quad w^T r - \lambda w^T C w\]subject to:
\[w^T \mathbf{1} = 1\]where:
This model allows investors to choose an optimal portfolio based on their risk preferences, adjusting the weight of each asset to achieve the desired return-risk trade-off.
MacKinlay and Pastor’s work on asset pricing models examines the relationship between theoretical models and their application to portfolio optimization and expected returns
The foundation of their analysis lies in the mean-variance optimization framework proposed by Markowitz, expressed mathematically as:
\[\min_w \ w^\top \Sigma w\]subject to:
\[w^\top \mu = \mu_p \quad \text{and} \quad w^\top \mathbf{1} = 1\]where:
MacKinlay and Pastor extend this model by incorporating Bayesian techniques. They introduce prior distributions for parameters like \(\mu\) and \(\Sigma\), which are then updated using observed data to generate posterior distributions. These posterior estimates are used in the optimization process, mitigating the risks of overfitting to historical returns. This Bayesian adjustment is particularly impactful for improving out-of-sample portfolio performance.
A key innovation in their work is the concept of shrinkage towards a benchmark, such as the market portfolio. By blending the model’s estimates with the benchmark’s characteristics, they reduce the impact of estimation errors, offering a practical solution to the challenges of real-world portfolio management.
To compare the performance of different models, we use the Sharpe ratio, which measures the risk-adjusted return of a portfolio. This ratio allows for the evaluation of portfolio returns relative to the amount of risk taken, with higher values indicating better risk-adjusted performance. It is defined as:
\[\text{Sharpe Ratio} = \frac{r_p - r_f}{\sigma_p}\]where:
To assess the statistical significance of the Sharpe ratio, we use the Jobson-Korkie Z test
where: