DEV Community

calleb
calleb

Posted on

Let's build an Agentic Trading System. Together

My role?
Basically building mathematical models to estimate market risk for all financial derivatives at one of the largest European banks.

Was it fun?
Yes, of course! It was my dream job back then (the fact that it was the first job out of Maths school probably helped).

I used to spend my days fitting statistical models to price and hedge financial derivatives, way before Machine Learning was cool.

It was all about MATLAB (not my cup of tea, but my best friend at the time. Is that too sad? xD).

Apart from maths and MATLAB, a big part of my job was talking to traders, the guys at the bank that were using these models to make trading decisions that fit their (and the bank's) risk appetite.

Then something happened
I entered a trading floor for the first time in my life, and I got a glimpse of what actual trading looks like.

Bloomberg terminals, fax machines, phone booths.

Risk management, portfolio construction, and of course trading.

One of the things that caught my attention, was the amount of screens showing Bloomberg news 24/7.

Traders would constantly have one eye on their Bloomberg terminal, and the other on Bloomberg news.

Why?
Because they knew that some news can really move the market.

So they wanted to be the first to know, take action and profit.

Back then there was no such thing as Large Language Models. But there were a lot of smart tricks to extract sentiment from news.

Simple regular expressions, helped quant traders build C++ functions running on Bloomberg terminals, generating numeric scores for potential market moves.

These inputs were then used to make trading decisions (by traders), that had to be approved by risk management.

That was the Prehistory of Natural Language Processing.

Fast forward 13 years….

Sentiment analysis is a solved problem in 2025
Large Language Models are universal functions that can map any given text to any structured output you want.

For example, map a piece of market news to a JSON formatted list of sentiment scores.

Of course, you need to wrestle a bit with your prompts to get there.

And this is something I want to quickly show you if you have 5 minutes. Do you?

A 5-minutes straight-to-the-point prompt engineering example
All the source code I am showing you here is in this repo I put together.

Link to the repo

We will be using [BAML](https://github.com/BoundaryML/baml) (Basically a Made up Language) to ensure our LLM generates the type of structured output we want.

Why BAML?

I personally prefer BAML to all-in-one frameworks like LangChain, as it makes fast prompt experimentation (the key to success for 99% of LLM problems) easier.

I also strongly recommend you use uv to package your project.

curl -LsSf https://astral.sh/uv/install.sh | sh
For example, to create the project structure you just need to run:

uv init crypto-sentiment-parser
Nice, let's now install the BAML client and the BAML cli.

uv add baml-py
To generate some boilerplate BAML code under baml_src run:

uv run baml-cli init
From these *.baml typed files, you can generate the equivalent Python code with:

uv run baml-cli generate
And here is where the magic starts to happen → In the BAML language a prompt is a function with strict types.

You define your types in BAML

class CryptoSentiment {
coin Coin
score Score
reason string
}

enum Coin {
Bitcoin
Ethereum
}

enum Score {
Positive @description("Positive sentiment")
Negative @description("Negative sentiment")
Neutral @description("Neutral sentiment")
}
and from there, you prompt becomes a typed function. Genius.

For example, here is our ExtractCryptoSentiment function, that maps a string to a list of CryptoSentiment objects.

Image description

From here, the BAML client will generate the Python code for you and put it in the baml_client folder.

So, whenever you need to invoke this very simple sentiment extraction agent, you just need to use a super simple function like this:

Image description

If you want to play around, check out this repository I put together. Feel free to adjust the code to your own needs.

So what now?
Building a sentiment extraction parser like we just did is very cool and all that.
But this is just one piece of the trading puzzle.

Trading in the real world takes more than that. WAY more.

Trading smartly is all about:

Finding a good trading idea

Testing with hard data if this idea is really a good idea

Executing the idea

Image description

So, the question that I kept asking myself last week was

Can we take things to the next level, and build not only a single news sentiment service, but a semi-autonomous fleet of agents that can find, test and execute trading strategies as the human traders I met 13 years ago did?

And you know what?

I think WE can.

And I say WE, because I want you to join me in this journey.

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.