Is News Sentiment the Missing Edge? Backtest Results Say… Yes!

Trading is a journey packed with emotions, and even the best traders admit that it’s tough to keep feelings out of the game, especially when news headlines are flying. This post explores whether we can measure market emotions and use them to trade smarter. By diving into backtested strategies, Python code, and data-driven results, we’ll see how news sentiment impacts returns. Spoiler: the answer is a delightful YES!

This is a summary of my full article on Medium. For the complete deep dive, check out the original post here. You can find the full Python code here if you’re interested in the technical details.

Tools and Data Used

  • EODHD API for daily sentiment scores and historical prices (stocks, ETFs, crypto)
  • Python (requests, pandas, numpy, matplotlib, seaborn, requests_cache)
  • Two years of Apple (AAPL.US) stock data as the primary example

Findings

First, I gathered price and sentiment data for Apple stock using the EODHD API. The sentiment score, ranging from -1 (very negative) to 1 (very positive), is calculated daily from news and social media. After merging and cleaning the data, I plotted daily price percentage change against sentiment to visualize their relationship. The trend line, while not steep, clearly showed that more positive news sentiment is linked to better daily returns.

Next, I implemented two simple moving average crossover strategies:

  • LONGSHORT: Go long when both price and sentiment fast moving averages are above their slow counterparts; go short when both are below; otherwise, stay neutral.
  • ALWAYSLONG_OUTWHEN_NEGSENT: Always go long unless the fast sentiment MA is below the slow MA, in which case stay out.

Testing the LONGSHORT strategy with a fast window of 5 and slow window of 15 led to disappointing results-it missed the mid-2024 uptrend and lost money. Switching to ALWAYSLONG_OUTWHEN_NEGSENT with fast=1 and slow=5 performed much better, especially during periods of major market shocks like US tariff announcements, where the strategy stayed neutral and avoided losses, then capitalized on positive sentiment afterwards.

To see if this effect was consistent, I ran an optimization across 28 major tickers (AAPL, MSFT, NVDA, etc.), testing different fast and slow window combinations and both strategy types. For most tickers, the best strategy outperformed buy-and-hold, especially for assets that had negative buy-and-hold returns. Notably, all assets with negative buy-and-hold outcomes had at least positive results with the sentiment strategy.

Finally, I created a heatmap to compare all combinations of fast and slow moving averages across all stocks and strategies. The key takeaway: while optimizing parameters for each stock can yield impressive results, on average, the sentiment strategy underperformed buy-and-hold. However, using a fast window of 1 (yesterday’s sentiment) consistently gave better results than longer windows, and some stocks are clearly more sensitive to news than others.

Conclusion and Next Steps

  • Sentiment scores from news and social media can be quantified and used in trading strategies, showing a positive correlation with daily price changes.
  • Customizing moving average windows for each stock often beats buy-and-hold, especially for assets with negative returns.
  • Some stocks react more strongly to news than others; the best results came from strategies that quickly reacted to yesterday’s news.
  • Major market events (like US tariffs) were captured by the sentiment API, helping the strategy avoid big losses.

Ideas for further exploration:

  • Test how past sentiment affects returns over multiple days.
  • Analyze the relationship between sentiment volatility and trading volume.
  • Investigate if periods of “flat” sentiment correspond to range-bound markets.
  • Identify which assets are most sensitive to news-and why.