ML is never too far away from us, and the idea of perceptron algorithm is pretty straight-forward. In this experiment I divided past 30 days of trading data into 6 groups, and see classify that group as "positive" if the average price of the first four days is less than the fifth day (trend of increasing prices), and "negative" vice versa. Then I train these data, starting with a zero vector, using iterative correction to make that vector able to predict whether the next day has a increasing or decreasing price, and decide to buy or sell accordingly. The performance is not bad - even though the max drawdown is almost 100% (not suitable for risk-averse people)
Also note that it takes quite some time to backtest, which suggests that ML algos are generally computation intensive.
For some background, wikipedia or lecture notes from MIT EECS department (1) and (2) can be very helpful.
Some ideas to tweak it:
1) training periods: currently I set it at 5, meaning training data are each visited five times
2) max,min notional: I split 1,000,000 bucks evenly to the seven stocks in my portfolio
3) instead of buying/selling 1000 shares each time, maybe as indicator becomes larger (stronger increase/decrease signal) we can buy/sell more shares
Any comments and suggestions are welcomed!
Please note there is a typo in the code (thanks to Chris). Corrected algo is attached as a later post.
I'm also trying to use set_universe and believe that's gonna be a better approach for choosing stocks :)