GithubHelp home page GithubHelp logo

patrickfrank1 / trading-sp500 Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 1.0 13.68 MB

A case study in betting on the S&P 500 using the Kelly criterion

Jupyter Notebook 99.74% Python 0.26%
algorithmic-trading kelly-criterion interactive-data-analysis snp500 stock-market

trading-sp500's Introduction

trading-sp500

Testing a Kelly Sizing based betting strategy on the s&p 500

Run the notebooks with binder Binder

Motivation

I got excited about this project while reading Paul Butler's Article on Kelly sized bets. It offers an excellent introduction into the topic and I encourage you to read it until the very end.

This gambling strategy only works on games with a expected positive return in the long run, so natually I thought "Can this strategy be applied to trading the S&P 500?". As as a google search revealed some people have had the same idea before and the foundations were already laid ouf by Edward Thorp and Sheen Kassouf in the 1960s.

I stumbled across an excellent bolg post abou algorithmic trading, which can be found here: https://raposa.trade/blog/how-to-improve-your-trading-system-with-the-kelly-criterion/. This article was also the basis for my experiments in this repository. Here I extend the previous results by:

  • analyses on much more historical data (S&P 500 from 1885 to 2022)
  • an interactive strategy simulator [1]
  • more robust backtesting simulations agains historical data [2]

Further reading:

Contents

The the contents of the four notebooks in this repository are briefly summarized below:

  1. Data Analysis: prepare the data for later analysis, plot summary statistics
  2. Interactive Kelly Strategy: examine different strategies interactively by tuning the important parameters of the strategy
  3. Analysis Kelly Strategy: My own analysis using notebook 2 and building on the analysis of the raposa blog post
  4. Robustness analysis: backtesting on historical data

Results

You can view the notebooks with simulations plots and explainations directly here in github.

If you want to dig deeper and use the interactive widget or analyse the data youself download the repository and install the dependencies as follows.

git clone https://github.com/patrickfrank1/trading-sp500.git
cd trading-sp500
python -m pip install -r requirements.txt

Alternatively you can also run the notebooks using google colab.

Interactive strategy builder

In the picture below is a screenshot of the interactive widget.

[1]: image

Optimal Kelly strategy

The main finding of the analysis in notebook 3 is that daily portfolio rebalancing is strictly nessecary to run a profitable Kelly Sizing strategy. Also positions need to be leveraged at times if you want to beat the baseline buy and hold strategy. The leaverage and therefore the risk that is taken on, can be adjusted.

Robustness of the strategy on historical data

The strategy is more profitable than buy and hold on the long run only. That is an investment horizon of 30+ years.

[2]: image

The simulation runs can be ploteed and further analysed.

[3]: gif

trading-sp500's People

Contributors

dependabot[bot] avatar patrickfrank1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fortressrain

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.