This is my first Quantopian algo, so be easy on me :).
The idea is to bin consecutive stock movements based on the price differences and to mark those frequencies in a probability transition matrix, where the Pij entry denotes the movement from state i to state j. The matrix is then divided by the total number of transitions to obtain a probability of moving states. If the rowsum, for j>i, is a decently large probability (aka the probability of it transitioning upwards, or stock price increasing), then buy shares, and vice versa.
Perceived errors:
I believe the main issue with this algorithm is the binning method that I chose in line 34. Instead of binning the stock movements based on the average, perhaps it would be better to bin it by dividing by the closing price or current stock price. The rowsums of the probability transition matrix don't appear to sum of 1. I also did not compute any μ values because I did not know how to utilize them, as used in some identity like Pij * μ = μ. Would implement a bigger matrix if the run time wasn't so slow as is.
Any feedback or helpful insight would be greatly appreciated.