Financial Portfolio Simulation

click image for results

Introduction

The purpose of this experiment was to create a research environment where you can search through parameters and see whether there is a relationship between that parameter and overall portfolio return. This experiment is based off a small sample size and it was created to fulfill curiosity and build a frame work for a research environment. The hypothetical question was that I wanted to construct a portfolio for the year, and my buy signals are dependent on 5 parameters. Out of these 5 parameters which ones are more important than the others? There’s no exact answer to this, but we can search for a qualitative understanding by running a monte carlo simulation of many constructed portfolios with different parameter weighting. Through a large enough amount of iterations we hope to find some relationship between parameter weighting and overall portfolio return. Backtesting year by year with random weighting of each parameter gives a unique portfolio return. When doing this over different years, we can search for a qualitative trend for a given parameter.

Scope

First, let’s define some rules for our strategy. These rules are mainly based off my personal time at Haugen Equity Signals and a book called “The Little Book That Beats the Market” by Joel Greenblatt. The frequency of trades are based off Haugen as they sold signals to clients on a monthly basis, and the strategy is simillar to what is found in the book because it’s simple enough.

Rules of the portfolio:
  • We are only Long no Shorts.
  • Buys occur on the first trading day of each month.
  • When it is a buying day existing stocks are liquidated at the beginning of the day and the new portfolio is constructed at the end of the day.
  • Our portfolio is always Long 30 stocks and they are equally weighted.

  • Rules of the strategy:
  • It’s a scoring system, there are 5 parameters and 5 scores associated for each ticker.
  • The final score is the summation of all the parameters for that particular stock.
  • The 30 highest scores are the stocks you buy for the month.
  • Stocks are rescored every month.

  • What are the 5 parameters?
  • Market Cap
  • Earnings per Share (EPS), TTM
  • Price/Earnings ratio (P/E), TTM
  • Price/Book ratio (P/B), Most Recent Quarter
  • Price/Sales ratio (P/S), Trailing
  • Parameter weightings can range from [-1, 1] and all weights are normalized once creating a strategy output.

    What’s our database look like?
  • We got 10 years of data ending in December 2021 for 2330 symbols
  • OHLCV pricing and our 5 fundamental parameters are populated

  • Running the Experiment

    The years that we’ll be looking at are from 2016-2021. We’ll do 500 iterations for each year. Each iteration will contain unique weighting for its given parameter and its associated portfolio return.

    Example of the flow for 1 iteration over 1 year:
  • Script 1 produces random weights for parameters 1-5 which are then normalized.
  • These weights are then passed through to Script 2 which generates the monthly buy signals for that given year. These signals are outputted in “.csv” for tracking and passed through to the Script 3, the backtest.
  • The backtest takes the generated signals, runs through the year with the monthly buys, and calculates the total return for that portfolio. The portfolio is tracked and outputted as a “.csv” for the given iteration. The total return is then passed back to Script 1.
  • Script 1 then documents the iteration #, associated parameter weightings, and its total returns.
  • It then moves onto the next iteration to go through the process all over again until we hit 500 iterations for the year.

  • Results

    At the end, the results are documented using Pythons Bokeh data visualization library. Click below for the interactive data for all the years. The legends toggle so you can begin by deselecting all parameters and then toggle one by one to search for a trend.
    click image for results

    Going through the results there’s no smoking gun and that is expected as we are looking at only 5 parameters with 500 iterations per year, which is quite a small sample size. The purpose of this project was to build the framework in which research can be conducted when constructing a strategy through quantitative evidence.

    Note

    The source code for this project can be found on my GitHub.