Content by the Judge on X

Judge,

I just saw you posted a bunch of stuff on X.

Why not post them also on the forum? (just a suggestion)

Below is just one post, the judge is also sharing a lot of info (some I don’t fully understand since I haven’t picked up on AIfactor).

Highly recommend P123 members to follow him (and the rest of the P123 AIfactor crowd on X).

Regards

James

Copied from X

Example -->

Tree = Context matters

Traditional = One-size-fits-all

--------------------------------

Traditional Ranking ("Quality is always good", Same formula for all stocks) Score = 0.6×Value + 0.4×Quality

--------------------------------

Tree Logic ("it depends!!!)

if Value > 90: // Deep value

if Quality < 30: +10 (BUY) // Distressed = opportunity

else: -5 (AVOID) // Expensive value = trap

if Value > 70: // Moderate value

if Quality > 70: +7 (BUY) // Quality at fair price

else: -3 (AVOID) if Value < 70: // Expensive

if Quality > 90: +2 (MAYBE) // Pay for excellence

else: -8 (SELL)

Result: Traditional ranks: Quality=80, Value=95 as BEST (score=89)

Tree ranks same stock as WORST (score=-5) - "value trap"

Traditional misses distressed opportunities (Value=95, Quality=20)

Tree captures them as BEST (score=+10)

Why it matters: Traditional: Quality always good Tree: Quality sometimes bad (with deep value), sometimes good

Thank you!!!

reach is a higher, idea is to get new subscribers on bord (goal is to grow P123), so I concentrate on my blogs, twitter, LinkedIn etc. Also, I post a lot of “Try and Error stuff”, e.g. I am quite wrong from time to time; it is more like 90% success with 10% the work, a lot of posts I shoot from the hip. For this forum I do not think my quality is high enough.

Here is my twitter @GfI_HimmelreichGfI_HimmelreichGfI_HimmelreichGfI_Himmelreich
Here is my LinkedIn handle https://www.linkedin.com/in/dr-andreas-himmelreich/

Blogs are here –> https://systematicportfolios.substack.com/ general stuff about P123, do not pay, posts are free (the paying members do so, that substack is not kicking me out, but there are enough right now FREE MEMBERSHIP DO NOT PAY!!!

https://systematicportfolios.substack.com/ –> the posts are also free, I also market there two strategy books, had to make it (the sharing of the strategy books) expensive because now working together with two startup funds that do not wanting me to share too much (geeee!). The idea for the blog was also to attract allocators which worked well so far.

But I also use it to document my findings with AI Factor (which I corrected at least 5 times, so documenting my way so to say) and again all posts are free…
FREE MEMBERSHIPDO NOT PAY!!!

It would be great if we could post more on X, we have quite some momentum right now and again those discussions grow our P123 community…

Great follows on X are

@RTelford_invest@ManuelBlay3
@ScifoSpace
@Quant_Kurtis
@AlgoManX
@VSai2314
@P123Finance
@systvest
@RTelford_invest
@Quant_Morales

THANK YOU!!!

Best regards,
Andreas

4 Likes

I also enjoy content from @judgetrade.

While the analysis of tree mechanics is very insightful, it is naturally quite general. I decided to ground it more empirically within the P123 environment to analyze the economic rationale behind the trained model. I hope this helps less experienced users better grasp how tree-based strategies work.

I locally trained a Random Forest (RF) model using only factors from the Small and Micro Cap Focus ranking on a small-cap universe. The training period was 2012-2024.

I used a very simple tree algorithm (10 trees with a max depth of 2):
model = RandomForestRegressor(n_estimators=10, max_depth=2, random_state=8, min_samples_leaf=100)

Then, I asked Gemini to explain the model.


AI - GEMINI ANALYSIS

Model Breakdown: The "Sentiment-Led Growth" Strategy

This model represents an aggressive Fundamental Momentum strategy. It creates a hierarchy of decision-making that prioritizes Analyst Sentiment and Operational Growth above all else, while utilizing Industry Momentum strictly as a risk-management "kill switch."

Notably, this is not a Value strategy . Despite the availability of value factors (like FCF Yield or EV/EBITDA) in the dictionary, the decision trees ignore them entirely. The model does not care how cheap a stock is; it only cares if the fundamental picture is improving and if the industry is stable.

1. The "Big Picture" & Equity Styles

The strategy splits the investment universe into two primary buckets based on the root node of the decision trees. It asks one of two questions immediately: "Is Wall Street getting more bullish?" or "Is the company growing operating income?"

Based on the frequency and structural position of the factors, the style weights are:

  • Analyst Sentiment (45%): The primary driver. The model seeks stocks with upward estimate revisions, earnings surprises, and falling short interest.

  • Growth (40%): The secondary driver. The model requires both Historical growth (Operating Income) to enter the trade and Forecasted growth (Future EPS) to confirm the trade.

  • Sector Momentum (10%): Used exclusively as a risk filter. The model refuses to hold stocks in crashing industries, regardless of the company's individual quality.

  • Liquidity (5%): A minor filter ensuring the stock has sufficient trading volume.

  • Value (0%): Valuation metrics are completely excluded.


2. How the Decision Logic Works

The 10 decision trees operate on a distinct three-step flow:

Step A: The Gatekeepers (The Root Node)
Every single decision tree begins by checking one of two "Gatekeeper" factors. If a stock fails this test, it is almost immediately relegated to a "Sell" or "Neutral" bucket.

  • 60% of Trees check $20 (Core Sentiment) . They generally require a Rank > 74-75.

  • 40% of Trees check $16 (Operating Income Growth) . They generally require a Rank > 36-41.

Step B: The Closer (The Buy Signal)
If a stock passes the Gatekeeper (i.e., it has High Sentiment or High Growth), the model looks for confirmation using $2 (Forecasted EPS Growth) .

  • Even if Sentiment is high, if the Forecasted Growth ($2) is weak (Rank < 40), the model usually assigns a neutral score (0 or 1).

  • If Forecasted Growth is also high, the model assigns the maximum scores (+8 or +9).

Step C: The Kill Switch (Risk Management)
If a stock fails the Gatekeeper test (Low Sentiment or Low Growth), the model checks $12 (Industry RSI) .

  • This is a "crash detector." If the Industry RSI rank is very low (e.g., < 8 or < 35), the model assigns massive penalties (Scores of -7 to -13). This prevents "catching falling knives" in collapsing sectors.

3. Feature Importance Statistics

The table below highlights which factors drive the actual buy/sell decisions. The "Times in Starting Node" column is crucial—it identifies which factors dictate the strategy's primary direction versus which factors act as filters.

Rank Factor ID Factor Name Role in Model Total Usage Times in Starting Node
1 $12 Industry RSI (Momentum) The "Kill Switch" 9 of 10 0
2 $2 Forecasted EPS Growth The "Buy" Confirmation 8 of 10 0
3 $20 Core Sentiment Primary Filter (Root) 6 of 10 6
4 $16 Op. Income Growth (PYQ) Secondary Filter (Root) 5 of 10 4
5 $26 Median Daily Total Liquidity Filter 2 of 10 0

Note: All other factors provided in the dictionary are unused in the active model.


4. Factor Definitions

  • $20 (Core Sentiment): A composite factor defined as:

    • 45% Estimate Revisions: Changes in Current Year and Current Quarter EPS estimates, plus variability.

    • 25% Surprises: Earnings surprises in the last two quarters.

    • 15% Recommendations: Change in analyst Buy/Sell ratings.

    • 15% Short Interest: Short interest as a % of shares outstanding.

  • $16 (Op. Income Growth): OpIncGr%PYQ. Growth of Operating Income vs. the same quarter last year.

  • $2 (Forecasted Growth): (CurQEPSMean- HistQ4EPSActual)/Abs(HistQ4EPSActual). A measure of "Forecasted Momentum"—comparing the consensus estimate for the current quarter against the actual result from a year ago.

  • $12 (Industry Momentum): Aggregate("RSI(200)",#industry). The long-term relative strength of the industry group. Used to identify sector crashes.


TRAINED TREES:

tree rules
r1 Eval($16<=41,Eval($12<=8,-13,-2),Eval($2<=41,-3,4))
r2 Eval($16<=37,Eval($12<=35,-7,-1),Eval($2<=40,-4,5))
r3 Eval($20<=75,Eval($12<=71,-3,3),Eval($2<=36,-1,8))
r4 Eval($20<=75,Eval($12<=73,-3,4),Eval($2<=41,-0,8))
r5 Eval($20<=74,Eval($16<=36,-5,1),Eval($2<=36,-0,8))
r6 Eval($20<=74,Eval($12<=72,-3,4),Eval($2<=37,-0,8))
r7 Eval($16<=36,Eval($12<=35,-7,-1),Eval($26<=70,1,8))
r8 Eval($16<=41,Eval($12<=8,-12,-2),Eval($26<=71,1,8))
r9 Eval($20<=75,Eval($12<=75,-3,4),Eval($2<=37,-1,9))
r10 Eval($20<=74,Eval($12<=35,-5,1),Eval($2<=40,-1,8))

FACTORS USED:

factor_name factor
$1 FRank(LoopSum("EPSExclXor(Ctr,Qtr) > EPSExclXor(Ctr+4,Qtr)",6,0), #all, #desc, #NANeutral)
$2 FRank((CurQEPSMean- HistQ4EPSActual)/Abs(HistQ4EPSActual), #sector, #desc, #NANeutral)
$3 FRank(EPSExclXorGr%PYQ, #sector, #desc, #NANeutral)
$4 FRank(FCF%AssetsQ, #all, #desc, #NANeutral)
$5 FRank(FCFGr%TTM, #sector, #desc, #NANeutral)
$6 FRank((FCFQ-FCFPYQ)/MktCap, #sector, #desc, #NANeutral)
$7 FRank(CurFYEPSMean / Price, #industry, #desc, #NANeutral)
$8 FRank(ConsEstMean(#EBITDANTM,0)/EV, #industry, #desc, #NANeutral)
$9 FRank(CurFYSalesMean/MktCap, #industry, #desc, #NANeutral)
$10 FRank(Abs(GrossPlantA/SalesA-FMedian("GrossPlantA/SalesA",#industry)), #all, #asc, #NANeutral)
$11 FRank(GrossProfit%AssetsA, #industry, #desc, #NANeutral)
$12 FRank(Aggregate("RSI(200)",#industry), #all, #desc, #NANeutral)
$13 FRank((InventoryA-InventoryPY)/AstTotPY, #all, #asc, #NANeutral)
$14 FRank(LoopMedian("ROE%(Ctr,TTM)",12), #all, #desc, #NANeutral)
$15 FRank(MktCap, #all, #asc, #NANeutral)
$16 FRank(OpIncGr%PYQ, #sector, #desc, #NANeutral)
$17 FRank(Abs (PEGST - 1), #all, #asc, #NANeutral)
$18 FRank(ROA%Q, #all, #desc, #NANeutral)
$19 FRank(SalesGr%PYQ, #all, #desc, #NANeutral)
$20 FRank($R_Core_Sentiment, #all, #desc, #NANeutral)
$21 FRank(MedianVol(252)/SharesCur(126), #all, #asc, #NANeutral)
$22 FRank(MedianVol(65)/SharesCur(0), #all, #asc, #NANeutral)
$23 FRank(Aggregate("TotalReturn",#subindustry), #all, #desc, #NANeutral)
$24 FRank((OperCashFlTTM - CapExTTM + (1-TaxRate%TTMInd/100)*IntExpTTM)/EV, #all, #desc, #NANeutral)
$25 FRank((SMA(150,21)-SMA(150,252))/ATRN(150), #all, #desc, #NANeutral)
$26 FRank(MedianDailyTot(126), #all, #asc, #NANeutral)
$27 FRank(AvgVol(13)/AvgVol(13,30), #all, #desc, #NANeutral)
6 Likes

Very helpful for new AI users! How did you ask Gemini to explain this?

It involves a specific workflow:

Data Prep: I provided Gemini with the P123 factor formulas/definitions so it understands the inputs..
Local Training: I trained the Random Forest in Python and exported the decision paths (the rules) as text.
Prompting: I pasted the factor definitions and the tree rules into Gemini.
Analysis: Finally, I asked the AI to synthesize the "Big Picture" strategy based on those specific rules.

1 Like

If you just want a simple visualization of a tree model you can use supertree:

GitHub - mljar/supertree: Visualize decision trees in Python

It isn’t as elegant and won’t give you as much information as Pitmaster’s method but easier.

2 Likes

Interesting

1 Like

Wow. This kind of analysis is incredibly useful, and I thank you for providing it.

My philosophy has always been that the safest way to invest is to look at every investment from every available angle. That is why ranking systems are so much better than screens from my point of view. It's a revelation to me that decision-tree-based models don't share my philosophy in the least. They're approaching investing from a completely different point of view. Not only does this one ignore all value factors, it ignores all quality factors. Now I understand that with a longer backtest and more factors, the decisions would be more complex than this. But the basic mode is still a decision tree, which is a bit like a bunch of linked Eval statements in a very complex screener.

What I don't understand is this: The tree models available in Portfolio123 can be converted to rank. This one can't be: it's completely Boolean. Perhaps you can explain?

1 Like

The only reason why some typically important factors (like value) was ignored is because of the simple structure of the tree he used as an example.

Kind of, but not. It uses the “screeners'“ (on a complex system there are millions of them) to create a rank. So it’s still a scoring or ranking system but by checking how many times a stock passes a “test” (branches), just not a linear rank (where we hope a high score in one area offsets a low score in another).

3 Likes

Actually, this is precisely how the current P123 AI Factor works. A trained AI Factor returns a predicted return for each stock, which is then used in a ranking system as FRank("AI Factor"). More specifically, each individual tree outputs a predicted return for a stock, and the final AI Factor value is simply the average of all those trees (for RF and ET models).

My post was focused more on the transparency and interpretability perspective. From that angle, you can think of each individual tree as a stand-alone factor.

For example, the simple "factor" below (based on a Depth 2 tree) returns only 4 discrete values (expected returns): [4, -2, -3, -13]
f1 = Eval($16<=41,Eval($12<=8,-13,-2),Eval($2<=41,-3,4))

If you apply FRank(f1), the output will not be very granular—it will simply group stocks into 4 large buckets.

To solve this, the idea is to increase max_depth. If you increase it to, say, 6, you get a maximum of 64 unique outcomes per tree. This creates a much smoother distribution.

Then, the factor FRank(f1) behaves like a regular factor that can be used in a ranking system or screener. Once you have converted each tree into a proper factor, you can handle them just like traditional metrics—for example, by combining all trees [FRank(f1), FRank(f2) ... FRank(f100)] into one composite ranking system.

Furthermore, you might be interested in whether such a factor preserves a proper monotonic relationship with returns. With a max_depth of 6 or higher, the rules can become complicated to read manually. However, analyzing the splits allows us to check for economic sanity. Below is the additional Gemini output regarding the model (max_depth=2) in my previous post (this analysis can also be done deterministically using Python code).


GEMINI OUTPUT BELOW:

2. Monotonicity & Directionality (The Sanity Check)

A common risk in Machine Learning models is "curve fitting," where the model learns that "Medium Growth is good" but "High Growth is bad."

However, an analysis of the split points in this specific model reveals 100% Positive Monotonicity across all factors. In every single decision node (30 out of 30 splits), a higher Rank resulted in a higher predicted return.

  • No Mean Reversion Logic: The model never bets on mean reversion (e.g., buying oversold industries).

  • No "Goldilocks" Zones: There are no cases where the model prefers "middle" values. It strictly prefers Higher Sentiment, Higher Growth, and Higher Industry Momentum.

This suggests the underlying economic drivers are robust and linear, even though the decision structure is non-linear.

3. Feature Importance & Monotonicity Statistics

The table below highlights which factors drive the decisions. The "Pos. Monotonicity" column indicates the proportion of splits where a higher factor value resulted in a higher expected return.

Rank Factor ID Factor Name Role in Model Times in Root Node Pos. Monotonicity
1 $12 Industry RSI (Momentum) The "Kill Switch" 0 of 10 100% (9/9)
2 $2 Forecasted EPS Growth The "Buy" Confirmation 0 of 10 100% (8/8)
3 $20 Core Sentiment Primary Filter 6 of 10 100% (6/6)
4 $16 Op. Income Growth (PYQ) Secondary Filter 4 of 10 100% (5/5)
5 $26 Median Daily Total Liquidity Filter 0 of 10 100% (2/2)

Note: 100% Positive Monotonicity means that for every split using this factor, the "Higher" branch always had a higher predicted return than the "Lower" branch.

3 Likes

Wrote a post on p-hacking on x in case anyone is interested. I see this issue a lot so I thought it would be useful to post in the forum too

3 Likes

SZ,

Just saw your x post while watching the market. Nice infographics.

Regards

James

2 Likes

Trying out gemini! Seems like it does decent ones. Nano Banana pro

1 Like

I don't get this. If I run a screen on the Easy to Trade Universe with Core: Value > 90 and Core: Quality < 30 the results are worse than if I run it without the Core: Quality system or if I run it with Core: Quality > 50. Even with deep value stocks, you want to avoid poor quality stocks. If you run it with Core: Quality < 20, the results are horrible.

I am also new in RF/Tree models.

Judge: Do you want to answer the question to the example?

Regards

James

it is Just an example.

What it means is –> quality might be good sometimes; in other situations, low quality might be good (hard to find turnaround stocks with good quality).
In a traditional ranking system quality is (usually) always good…

Not in a decision tree –> it is nonlinear and it depends. ML might find out that small cap stocks with terrible quality, low stock price, deep value (trading price well below cash levels), super high short interest, decreasing cash burn rate and an upgrade in earnings estimates is a killer stock (it does not mean it is a good company long term) on a 3 MonthRel Target.

In this case a linear rule “High Quality is always good” might miss it.
Therefore also the term “Our Stocks we play screen badly” (deep value / turnaround investors, Harris Kuppermann is a good example)…

1 Like

Thanks Judge,

Learned something more about non-linear today from the reply.

Just want to point out that I did try the Easy to Trade Universe and it seems Core Value >90 + Core Quality <30 works better than Core Quality > 50. Not sure the reason for the discrepancies.

Core Value > 90 and Core Quality < 30 was worse for me than Core Value > 90 and Core Quality > 50. I was using Compustat, not FactSet, but whatever.

2 Likes

not sure if you can compare a screen with an AI Factor Model / Predictor:

A Typical non-linear AI Factor ML Model (XGB, LightGBM, ExtraTrees) built (depending on number of features and Hyperparameters) about 10.000 - 65.000 nonlinear (!) rules in about 250 – 1000 Trees (e.g. this is not replicable with a screen and a couple of trad. Ranking systems) All rules get weighed in one ensemble AI Factor Score (e.g. every tree fires and gives a vote), e.g. every stock’s data (All features from it!) goes through every tree (every day, if you want to, in a portfolio strategy every week) to determine the AI Factor Score, which then gets used in a ranking system…

It is very different :slight_smile:

1 Like

This is not easy to learn all these and with the different parameters to explore (LightGBM and Random Forest/Tree models.)

I think it is better if there is a hedge fund backed by the P123 AIfactor that we can all put money in for those who are interested.

For instance, I will seriously consider paying 2/20 to invest in Algoman near 100% out-of-sample annualzed return (with his real money also invested).

Regards

James

EDIT : I have saved this screenshot by Algoman which show a Sharpe ratio of 2.66 and 1 year MAR ratio of more than 4 times (1 year MDD around 20% which I find acceptable)