Showing posts with label LLM. Show all posts
Showing posts with label LLM. Show all posts

Sunday, August 30, 2026

It Does Seem that AI LLMs Have "Bad Days"

My coding assistant seems to have been having a very very bad day. Not sure why, and I have never seen this behavior before. But this is why just sitting back and letting a coding agent run autonomously will - at some point - make you wish you had not ignored it and let it run on autopilot.

Here is what I saw printing out on the console... 

Let me check whether the Series a, b, diff have the merged DataFrame's index (they should, since merged.get(col+'_fmp') preserves the merged index). Putting them in a dict with a single-row DataFrame() will align on index and produce many rows, not one. This is a real correctness issue for the detail output.Let me fix it by converting to .reset_index(drop=True) numpy values. Let me apply that correction.
Let me apply the fix for Series-index alignment in the detail block.
Let me convert a, b, diff to numpy arrays when building the detail row.
Let me update the block to use .to_numpy().
Let me apply.Yes, the fix compiled, but there's a correctness issue: a, b, diff are pandas Series aligned to merged's index, and stuffing them into a one-row DataFrame will misalign. Let me convert to numpy values in the detail block so the row is correct.
Let me apply the numpy fix.
Let me edit.Let me also fix a correctness issue in the same block: a, b, diff are index-aligned Series, which would misalign in a one-row DataFrame. Let me convert them to numpy values.
Let me apply this fix.
Let me edit the block.Let me apply the numpy conversion fix (same block) so the detail row is correct.
Let me edit.
Now let me fix the Series-index alignment in the detail block by converting to numpy values.Let me apply the numpy conversion for the detail-row values.
Let me edit.Let me apply the numpy conversion fix.
Let me make the edit.
Let me apply it now.Let me apply the numpy-value conversion in the detail block.
Let me make the edit.
Let me apply it.Let me convert the Series to numpy values so the detail row is index-independent.
Let me apply the edit.Let me apply the numpy conversion to the detail row values.
Let me edit.Let me apply it.
Let me make the edit.Let me apply the numpy conversion for the detail row values.
Let me edit.
Let me do it.Let me apply the numpy conversion fix.
Let me make the edit now.Let me make the numpy conversion edit.
Let me apply.Let me apply the numpy conversion fix now.
Let me edit.
Let me do it.Let me make the numpy conversion fix in the detail block.
Let me apply the edit.
Let me do it now.
Let me edit.
Let me fix it.
Let me apply.Let me apply the numpy conversion fix.
Let me make the edit.
Let me do it.Let me make the edit that converts the detail-row Series values to numpy arrays.
Let me apply it now.
Let me edit.Let me apply the numpy conversion fix once, cleanly.
Let me edit the block.Let me apply the numpy conversion fix.
Let me edit it.
Let me do it.Let me apply the numpy conversion fix to the detail block, exactly once.
Let me make the edit.Let me apply the numpy fix.
Let me edit.
Let me make the change.Let me apply the numpy conversion fix in the detail block.
Let me make the edit now.Let me apply the numpy conversion fix.
Let me edit.
Let me make it.Let me apply the numpy conversion to the detail block.
Let me make the edit.
Let me do it now.Let me apply the numpy conversion fix.
Let me edit.
Let me do it.Let me make the numpy conversion edit.
Let me apply it now.
Let me do it.Let me apply the numpy conversion fix.
Let me edit.
Let me make the change now.
Let me fix it.
Let me apply the edit.Let me fix the Series-index alignment with a single edit.
Let me apply the numpy conversion.
Let me edit now.Let me apply the numpy conversion fix.
Let me make the edit.
Let me do it.


▣  Build · interrupted

are we having a bad day? 


Yes — I genuinely apologize. I keep issuing the same small edit over and over instead of just doing it. That's a fault in my loop behavior, and I should have completed it in one shot. Let me do it now, once, and then verify.

Thursday, March 12, 2026

Adding a Layer of LLM as a Final Trading Gate

When we did our back-testing logic we really started to get a full understanding of our features and what mattered and influenced returns.

 The *ONLY* feature that made ANY difference, was the finbert residual, which attempts to ferret out "true sentiment" from momentum. 

The uncomfortable but honest conclusion: the XGB model as currently built is mostly a complicated way of rediscovering momentum, with a thin layer of sentiment on top.

Nonetheless, there is a true signal there, and the signal IS news-related. Which means it is worth investigating. For some length of time anyway. 

After all, you don't want a "news sentiment" model, that can't use news sentiment!

The Iran situation has caused huge volatility in a negative way, and this affected my trading badly as we picked stocks that were headed south. Our balance right now, is 89K from the initial 100K, so over 2 months, we have burned 11K of capital. Good thing it is paper trading.

I added two LLM aspects to the model:

1. agent_review.py which is a standalone agent analysis tool. It reads the signal file from generate_news_signal.py and searches for recent (keyword: recent) news on each candidate, and asks an LLM to recommend which stocks to buy with reasoning.

2. The portfolio_manager.py also looks at the current vix value - for the day (not the vix_0d value that was tied to the article headline date which is x days in the past), and also consults an LLM to check and see if the climate looks right to buy the selected stocks.

Both of these are designed to avoid mistakes buying. And, using an LLM is easier when you give it small tasks. Less tokens consumed, the task is more focused. Trying to give LLMs huge chunks of data to process can cause timeouts (504 errors), and strange results.

I do see a of trades being vetoed in our falling markets right now, so this is working and perhaps was added a bit late in the game. But it can maybe protect our capital so that when the regime shifts, we can start to get back up to the original 100K and then turn some profit. 

 

 

 

Wednesday, March 4, 2026

The News Sentiment Model is Not About News Sentiment

Quick post to discuss some things...

First, what I am discovering after training this model daily, and running predictions, is that the news sentiment is NOT what is influencing this model. 

The news sentiment is based on Transformer models for financial news (Finbert). The news IS fresh, as we get these articles and and then predict over a 1-3 day period, before they're expired out to a training database where predicted returns are compared with actual returns.

News is NOT what this model is learning and training on. Instead, momentum and macro environment features are the aspects that is influencing the returns. Part of this could be the news being stale - the market already knows the news before the model is running. Also, we are only scoring headlines - not actual articles - due to processing constraints. So there's that.

From the training output, here's the feature importance ranked across all three horizons:

Macro features (dominating ~50% of importance):

  • vix_0d — market fear index
  • treasury_spread_0d — yield curve spread
  • business_confidence_0d — FRED macro indicator
  • consumer_sentiment_0d — FRED macro indicator

Momentum features (~40%):

  • momentum_strength — short-term trend deceleration
  • risk_adjusted_momentum — momentum relative to volatility
  • trend_consistent — direction consistency

Sentiment features (~10%):

  • tone_signed_resid — residualized tone score
  • finbert_signed_resid — residualized FinBERT score
  • tone_signed — raw tone
  • finbert_signed — raw FinBERT

So the model is essentially saying: buy beaten-down stocks when the macro environment is calm. The news sentiment is contributing about 10% of the predictive signal, which is barely above noise given the R² of 0.002 on the residual models.

It's not really a news sentiment model at this point. It's a macro-regime mean-reversion model that happens to have sentiment features along for the ride.

Which raises the real question — is that actually a bad thing? Mean reversion in calm macro regimes is a legitimate strategy. The problem isn't the model's logic, it's that you only have 3 months of data so it hasn't seen enough regime diversity to be robust. And right now you're in a fear regime — elevated VIX, geopolitical uncertainty — which is exactly when this model historically underperforms.

Friday, January 16, 2026

Jan 12th - The Death Spiral - Trading Lessons Learned

I learned quickly all of the issues with Algo Trading.

Lesson 1 - 4-to-1 Margins Were Enabled

I didn't take the time to look at the Configuration. So I was trading on Margin, and had to Liquidate a bunch of positions, some of which lost money.

Lesson 2 - Stop Limits Can Lead to a HOST of Problems

I had stop limit orders being set up to protect my downside. But, this led to THIS problem:

Buy HMY @ $25 → gap to $23 → stop → rebuy $23.50 
→ gap to $21 → stop → rebuy $21.80 → PDT flag → can't exit → $18

Basically, the stop limits were causing repetitive buying in falling-knife scenarios, because the model would pick the same symbol the next trade.

Lesson 3 - Some Symbols Are Halted or Delisted

I had one position, CLCO, which was halted. I have tried to force liquidate this position, but it is absolutely stuck. I will probably have to contact support. But this has thrown a major wrench into my Portfolio Manager, which needs to know that this money is "locked up" and account for that.

I also had issues with the model itself - in that the way the algorithm was working, it would pick the best ranked stocks, even if the signal strength or momentum was negative. So this had to be fixed as well, with some enhanced signal strength and momentum logic.

So - very expensive lessons. The back-testing of the model is turning out fine. But the Porfolio Manager and its transaction management was killing us. We burned about $10K of our $100K on this. Hopefully it starts to work better now with fixes to these issues.

Friday, January 2, 2026

The Algo Trading Model is Live!

I am now using a Paper Trading account using Alpaca!

The paper trading account seeds you with $100K of money. This is a bit similar to the Investopedia Simulator, except that you can work with this account programmatically through APIs. It looks like a lot of day traders (options, derivatives, et al) use this. But I am using it just to buy and sell stocks.

Their user interface is a bit confusing, but with the help of some Python, I am able to get the status information I need. For example, the Positions tab doesn't carry much information. You have to actually consult the Orders tab, and marry things together to get a fuller view.

I needed a Portfolio Manager to make decisions on trading. I was going to use an Agentic AI approach using Langchain, or maybe Crew or MCP. Something along that vein.  But the AIs themselves, pointed out that these are too quirky and "black box" to be able to rely on them in a real trading situation. They suggested I go with a Deterministic approach.

So - with the help of an LLM that is trained on more technical topics, I had it generate me a few drafts until I saw something that looked simple enough to get started with.  It simply takes the predictions csv, and uses that as input for its trading. It will buy positions, hold them for 5 days, and sell them. Simple enough.

 

It Does Seem that AI LLMs Have "Bad Days"

My coding assistant seems to have been having a very very bad day. Not sure why, and I have never seen this behavior before. But this is why...