Run live strategy powered by your local ML system

Hi,
My goal is automate ML model workflow in such a way that my local ml system is run as a live strategy or/and designer model and, most importantly, all operations are automated, without manual intervention.
I'm not experienced in LS/DM so please correct me if I'm wrong in my thinking.

START.

Initial step, manual step:

  1. Create ranking system in p123 (call it ml_rank), where the only one node is:
    eval(StockID=X, 100, Eval(StockID=Y, 90, 0), Eval(StockID=Z, 80, 0))
    This ranking assumes that stocks Z is has highest predicted return, and so on. (The formula possibly needs to be reconsidered but this it the overall idea)
  2. Create Live Strategy with ml_rank as your ranking system, with automatic recommendations.

Periodic automatic steps:

  1. Train ml model locally
  2. After that, every Sunday night
  • Call data_universe() to get current data,
  • Infer predictions
  • Call rank_update() to to update predictions in ml_rank

END.

Does it make sense ?
It is not a perfect solution... you will not be able to use some functionalities in LS as PrevRankPos() and others...
But the main goal is to run ml model without manual intervention in fully automated way.

1 Like

Sounds good! Another option is to upload your own stock factor based on your ML results, then you don't have to update the ranking system and your single node is going to look a bit simpler. Or is there something problematic with doing that?

1 Like

yes, there is function stock_factor_create_update() so this 'ml_factor' could store also historical values.
So it seems like we have a plan :slight_smile:

2 Likes

That is what I do (as test_user said)
Create a file programmatically with prediction data then upload it as a stock factor with the API.
Date;Ticker;Prediction

The file could contain recent as well historical predictions.
You then simple create a single node ranking system ($$Name)
That is it.

The advantage is that you can backtest your prediction using all P123 tools/features.

For example:
You can try different RankPos as sell rule to avoid selling a stock if the prediction doesn't fall too much and thus avoid having a lot of turnover, which is one of the main problem with AI model if you prediction target is short term (like weekly).

1 Like

Edit: I think i answered my own question. For those, like me, trying to catch up with this thread-- Research -> Imported Stock Factors--is probably what is being talked about as far as uploading ML predictions..

You can import a csv file with date, value, ticker or stock ID there..

'Value' would probably be the prediction with no need to sort or turn the predicitons into a rank yourself, I believe. Thank you @azouz110 for posting this method.

You can do this with data updated overnight using the API. You will need the API to rebalance daily.

Maybe P123 will essentially do this method internally for the upcoming AI/ML. Anyway, at a tentative fee (not necessarily final) of $1,200 per year to be able to rebalance your model, you will be able to accomplish at least some of this with the upcoming P123 AI/ML.

Jim

1 Like

Exactly Jim. Sorry I wasn't clear.

You need to loop through every stock, create a file that contains the date, ticker and the prediction value (no ranking needed as this will be done in P123).
Then use the "stock_factor_upload" API function to import the data into a stock factor. Finally reference that stock factor in your ranking system or even in your buy rules.

Another way to reduce turnover would be to buy the top N stocks that have the highest prediction then only sell those whose predictions for subsequent weeks drops below 0.

1 Like

I just want to say that is an awesome idea that many who like low turnover will love! Thanks.

Jim

What is LS/DM?

Are you able to update a specific ranking system other than the built in one called APIRankingSystem?

I just reread the API doc and it looks like you can update any RS now?
Has that always been there? I thought that APIRankingSystem was the only RS that could be updated via the API.

  # Optional parameters
    # ranking system id. 
    # If missing the ranking system 'ApiRankingSystem' is updated
    'id': 123 

Tony

Maybe my post is better suited to this thread: My real crappy ML code

That parameter has been available since the launch of the API. The initial design heavily promoted ease of use, namely that you don't need to specify an existing ranking system to run rank operations, so this functionality is easily overlooked.

I'm trying to replicate some of the new AI features on my own computer and I'm struggling a bit. I suspect a possible issue is that P123 AI module uses "Minimum price bars" of 260 as a filter for the universe. Is there any way to implement this as a rule in my own universes? (i.e. remove stocks with a shorter history than 260 bars.)

You could add the rule Close(260) != NA to your universe.

2 Likes