Stock Alpha Prediction API

In this example, we use the betas table derived in the previous example to demonstrate a machine learning – based time series prediction of single stock alpha vs the market.

We are using https://www.modelbit.com/ to host an api endpoint to generate “next day” alpha predictions.*

With a modelbit account, you can paste the following code in a jupyter notebook and get the output.

import modelbit

mb = modelbit.login()

symbol = "JPM US"
modelbit.get_inference(
region="us-east-1",
workspace="reckoningmachines",
deployment="predict_stock_one_day_alpha",
data=symbol
)

The code above will return:

{'data': 'Model accuracy: 0.52, ticker: JPM US,trade date:2024-05-25,outperformance probability:0.52'}

Which is to say, with an accuracy score of 52%, we predict the alpha for 5/25/2024 will be positive with a probability of 52%.

Our example feature set starts with the daily returns of the various exogenous price feeds we’ve ingested in our previous blog post.

Our target vector is 0 or 1 and is simply whether the stock has outperformed the market on that day or not, going back in time. We refer to this as “earned alpha”.

The final example feature set itself is simple: we take the diff of returns (or the second derivative of daily returns) and shift the day’s target back by 1 day (since we are looking to predict returns the day after), and hold back the last record for the final prediction of what the stock will do tomorrow. In our example the last day of the record set is 5/24/2024 and that would render a prediction for the next day 5/25/2024.

Our final accuracy of 52% is weak, but can be improved both with an improved feature set – perhaps one which includes KPI forecasts – and a better tuned model vs an off the shelf Logistic Regression which has little regularization (outlier adjustment).

However, it is worth noting that professional stock pickers only have a 52-53% accuracy on average.

Lastly, our probability of outperformance of 52% can be used as a “conviction” level to weight the position size for a portfolio.

* I’m not affiliated with modelbit, I just happen to like their framework. Essentially they offer a hosted flask solution, saving you having to develop a flask app and deploy it to a hosted service like Heroku. Also, they allow for large includes like scikit-learn without size constraints.