Member-only story
I Needed Money, So I Wrote An Algorithm.
We all know that programmers on Wall Street make fortunes with their high-tech code. But let’s actually dive into one and see how it’s really done.
Let’s first go over the theory of our algorithm. The backing of this strategy revolves around the assumption that the prices of non-derivative assets will trade in a normal distribution. This means that when an asset price’s stock moves greater than 2.5 standard deviations away from its normal range, it can be considered an outlier that must be traded against.
Determining whether a price is a relative outlier or not all depends on the z-score. The Z-score is simply how many standard deviations a value is compared to the average. So a Z-Score of 3 would mean that the value is 3 standard deviations away from the average, a 0.13% probability. Below is the theoretical calculation:
To begin, you will need to be able to run Python 3, you will also need to install a few dependencies.
import yfinance as yf
import pandas as pd
import numpy as np
Next, we will create a class that will store our data and perform the calculations.