Python

Backtesting algorithms… with Python!

Nicolás Forteza

06/09/2018

No Comments

In financial markets, some agent’s goal is to beat the market while other’s priority is to preserve capital. However, what we know for sure is that all the agents wonder if they made their optimal choice. Having the right tools can help us to make better investment decisions. 

______

Hey! Welcome back! I hope you guys enjoyed the summer. For an easier return from holidays -and also for a quick test of your best quantitative asset management ideas- we bring you the Python Backtest Simulator! This tool will allow you to simulate over a data frame of returns, so you can test your stock picking algorithm and your weight distribution function. Momentum or Low volatility? Equally weighted or inverse volatility weighted? Maybe risk parity? What’s the optimal number of assets to have in the portfolio? Go and run some simulations!

Some Factor Investing strategies are implemented in the code. I decided to compare the 1Y Momentum factor vs. the 6M Momentum factor vs. the 1Y Low Volatility, all of them set to an Equally Weighted distribution asset allocation algorithm. To keep things simple we have decided to model financial returns as independent random variables drawn from a normal distribution. The code does not take into account some financial biases, but it is enough to show the core functionalities of the program. It delivers the result of several computations.

What’s your best quantitative investment strategy?  Please, feel free to show your results in the comments!