Skip to content

Using backtrader to backtest markowitz's tangency portfolio (max sharpe portfolio) for a set of stock symbols.

Notifications You must be signed in to change notification settings

DYSIM/PortfolioBacktesting

Repository files navigation

Hobby Project: Portfolio Backtesting with BackTrader

Implementing Markowitz portfolio optimization with pyportfolioopt, backtest a strategy to rebalance the tangency portfolio (max sharpe) every half a month.

Instructions:

  1. Run 'pip install -r requirements.txt'

  2. Run 'Python backtest.py'

Price data of the tickers will be downloaded as csv files.

Backtesting framework used is backtrader.


Theory

Under Markowitz's portfolio theory, the efficient frontier is the curve which consists of all the portfolios that generate highest return for the given level of risk in the set of all portfolios. Mathematically, can be obtained by minimizing the variance of the portfolio, subject to constraints.

alt text

Tangency portfolio

The most optimal portfolio in terms of risk and reward is not the minimum variance portfolio, but instead the one with maximum sharpe ration. Sharpe ratio is the expected return, accounting for the amount of risk taken

alt text

To locate this portfolio, we require the Capital Market Line as well, as the point where CML is tangent to efficient frontier is the tangency portfolio. The sharpe ratio is actually the the slope of the CML.

alt text

Using the Capital Market Line, an optimization problem can be stated and solved by pyportfolioopt.

ALL images found on google

About

Using backtrader to backtest markowitz's tangency portfolio (max sharpe portfolio) for a set of stock symbols.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages