A stock price simulation that optimizes the rolling net sharpe ratio of a portfolio. The model supports several heuristic optimization algorithms.
main_rebalancing.py is a little sandbox that let's you play around with the parameters. The underlining data is from the german stock market (germanstocks.csv). The data is being bootstrapped to ensure a different outcome for every simulation. The objective function is the effective (net) sharpe ratio after transaction costs.
experiment_rebalancing.py is an experimental design to try several hyperparameters. Multi processing is included. The script writes a .csv and evaluates several performance measures.
Currently the implementation support several parameters.
strategyis the algorithm that optimizes the objective function which is the effective (or net) sharpe ratio. Possible values are:- Differential Evolution Alorithm on the portfolio weights
x - Differential Evolution Algorithm on the delta of portfolio weights
dx - A simple neighborhood search
- Sequential Least Squares Programming from scipy
- Equally weightd portfolio strategy
- Differential Evolution Alorithm on the portfolio weights
perfectForesightdetermines if the covariance matrix is estimated based on the true data generating process (True) or on past observations (False).rSis the interest (daily) rate of the risk-free asset.w0is the starting budget.T_prioris the rolling time horizon used for the estimation of the covariance matrix.T_invstis the investment horizon.BLis the block length for the bootstrap.cvaris the amount of variable transaction costs.
Example of a three year portfolio simulation based on Sequential Least Squares Programming optimization. The plot shows:
( a ) Stock market prices
( b ) Portfolio weights over time
( c ) portfolio balance the dynamic portfolio (net/gross) and a portfolio without rebalancing.
( d ) Rolling sharpe ratio w.r.t. to marturity

Example of an "equally weighted portfolio"-strategy:

- numpy
- matplotlib
- pandas
- scipy
To install requirements, cd to the directory of the repository and run pip install -r requirements.txt. A virtual environment is recommended.
- other evolutionary optimization algorithms, i.e. Particle Swarm Optimization
- other objective functions
I am very thankful for any kind of feedback. Also, if you have questions, please contact gregor.lenhard@unibas.ch .