Python: Stock Portfolio Backtesting and Visualization

Jatin
Oct 31, 2020

Portfolio backtesting seeks to determine the effectiveness of a trading model using historical data. Using this Python script you can build portfolios with different assets and allocation, compare the performance to benchmarks like S&P 500, Dow Jones Industrial Average, and Nasdaq Composite.

In this example, I’ve taken MSFT, FB, AAPL, and CRM stocks to build the portfolio with the following allocation.

Next, I calculated the cumulative return of the portfolio and compared it to the S&P500 benchmark for the 1st Jan 2019 to 30th Oct 2020 period.

Source: investopedia.com

Now, let’s visualize the Growth of 10K initial investment using Plotly.

--

--