Machine learning to use what the news says to make you money in the markets.
By: Zohaib Syed
The objectiveof this project was to implement machine learning to analyze financial sentiment in text to gain market insight from a source that isn’t as saturated as statistics. The data set that was used in this project contains around 5,000 different phrases and their sentiment collected by researchers in 2014 pursuing a similar objective.
Sentence Transformer + MLP
Raw Text
Encoder
Custom MLP
Layer Norm (1024)
Hidden Layer 1
Linear Layer 1024→256
GELU Activation
Dropout (p=0.5)
Hidden Layer 2
Linear Layer 256→64
GELU Activation
Dropout (p=0.4)
Output
Linear 64→3
Prediction
LLM Baseline
Raw Text
Qwen3-VL-2B-Instruct
“You are an expert financial sentiment analyst with 30+ years of experience. Using your expertise, Classify the financial phrase as positive (0), neutral (1), or negative (2). Do not leave anything unclassified. Make your best prediction no matter what. Return only one token: 0, 1, or 2.”
+ 3 labeled few-shot examples → RegEx parse output
Avg response time 0.49 s
Prediction
Key Takeaway — Per Class F1
Qwen avg latency: 0.490 sec/sample · MLP: <1 ms/sample · MLP is ~500× faster
F1 Score for the negative class was significantly worse than others for MLP, but not as bad for Qwen.
Visual Analysis
“Looks like its booking a one way ticket to its 40 week MA near 50. Losing 10 week here $LULU http://chart.ly/7xb9h9b”MLP
Pred: NegativeReal: Neutral“Sold out $TZA 45 $PUT (down $1), which were hedging my 45 $CALL. Letting the calls ride solo now.”MLP
Pred: NegativeReal: Positive“$SIMO Basing nice. A close over 24.18 is bullish $QQQ $SPY $STUDY watch for a close near HOD. Currently up +3%”Qwen
Pred: NegativeReal: Positive
Pattern: Both models struggled with phrases containing stock tickers ($LULU, $TZA) and URLs — noise strings that carry no sentiment but appear to bias predictions toward negative. Neither model learned to ignore non-sentiment tokens. This suggests future improvement via pre-processing to strip tickers and URLs before encoding.
Conclusion / Takeaways
- MLP dominates across all metrics — +22pt accuracy, +0.22 macro F1 vs Qwen
- Weighted cross-entropy loss effectively handles the 11.1% negative class imbalance
- Simpler is better — 2 hidden layers outperform deeper networks on 5K samples
- Domain-specific encoders (all-roberta-large-v1) are the key performance driver
Recommendations
- Deploy the MLP — superior accuracy, near-zero latency, minimal compute cost
- Do not deploy an LLM for classification without fine-tuning on domain data. Strip tickers, URLs & hashtags as a pre-processing step to reduce noise
- Be wary of accuracy as a metric on imbalanced data — use macro F1