One of the five parts of our stock score is news tone: how positive or negative the recent headlines about a company are. We used FinBERT , a BERT model fine-tuned on financial text, to read them.
How it works
Collect headlines per company.
Run each one through FinBERT, which gives probabilities for positive, negative and neutral.
Turn that into one number from −1 to +1 (positive minus negative).
Average the recent headlines per stock, then rank against the other stocks.
from transformers import pipeline
clf = pipeline ( " text-classification " , model = " ProsusAI/finbert " , top_k = None )
def tone ( headline ): p = { d [ " label " ]: d [ " score " ] for d in clf ( headline )[ 0 ]} return p [ " positive " ] - p [ " negative " ]
Enter fullscreen mode
Exit fullscreen mode
The timing detail that matters
A headline published at 5 pm New York time, after the market closed, couldn't have affected that day's trading. So headlines after the US close count for the next trading day.…