Seminar paper · NLP · Empirical finance

Can Twitter sentiment improve volatility forecasts?

I collected almost one million tweets on six US stocks, turned them into daily sentiment signals with Doc2Vec and VADER, and added these signals to the HAR model, a standard benchmark for forecasting realized volatility. For the two most-discussed stocks, the Doc2Vec signal cut forecast errors by 25–33%.

Solo project Seminar "Advances in Empirical Finance" Supervised by Prof. Dr. Roxana Halbleib

01 / Overview

Motivation

Stock market volatility is notoriously hard to predict. The HAR-RV model is a widely used benchmark: it forecasts tomorrow's realized volatility from the average volatility of the past day, week, and month.

Investor attention and opinion move markets, and much of that discussion happens on social media. This project asks whether a sentiment signal extracted from tweets, added as a fourth component, improves the one-day-ahead forecast.

AAPL · GOOG · NVDA MA · V · JNJ Dec 2020 – Mar 2021

02 / Approach

From tweet to forecast

A three-step pipeline bridges raw social media text and a structured time-series model. A dictionary-based VADER feature serves as a simple comparison.

1
Vectorize

Doc2Vec converts every tweet into a dense 10-dimensional vector; the vectors of a trading day are averaged into one daily vector.

2
Score

XGBoost maps the previous day's vector to a single sentiment score by predicting the next day's realized volatility.

3
Forecast

The score enters the HAR model as a fourth regressor. All models are re-estimated after each out-of-sample prediction.

03 / Data

Tweets

Using the Twitter API (tweepy), I collected all tweets mentioning each stock's cashtag (e.g. $AAPL) between December 2, 2020 and March 26, 2021. Each trading day covers the tweets from one closing time to the next.

  • Apple: 534k tweets · Alphabet: 273k · Nvidia: 78k
  • Johnson & Johnson: 39k · Mastercard: 20k · Visa: 19k
  • Numbers, special characters, and stopwords removed

Target variable

Realized volatility

Daily realized volatility is computed from intraday prices at 15-minute intervals: the square root of the sum of the 26 squared log returns of a trading day.

Tweet volume varies by a factor of almost 30 between stocks. As the results show, this gap largely determines whether the text signal helps.

04 / Sentiment Features

Two ways to read tweets

A fixed sentiment dictionary versus embeddings learned from the tweets themselves.

Dictionary approach

VADER

VADER assigns each tweet a compound sentiment score between −1 and 1, based on a fixed lexicon that also accounts for emojis, punctuation, and capitalization.

A daily average would be misleading: both very positive and very negative days can signal high volatility. The feature is therefore the variance of the compound scores within a trading day, a measure of disagreement.

Limitation: the fixed lexicon cannot adapt to financial jargon or new slang.

Learned embeddings

Doc2Vec: PV-DM and PV-DBOW

Doc2Vec extends Word2Vec with a document vector, learning a dense representation of each tweet from the corpus itself. Two variants were compared:

  • PV-DM (Distributed Memory): predicts a word from its context plus the document vector, preserving word order.
  • PV-DBOW (Distributed Bag of Words): trains the document vector to predict the words of the tweet, similar to Skip-Gram.
  • Vector size 10, window 2, negative sampling

05 / Forecasting Model

Sentiment-HAR

The HAR model regresses tomorrow's realized volatility on its daily, weekly (5-day), and monthly (22-day) averages. The Sentiment-HAR adds yesterday's sentiment score F:

RVn = c + βdRVn−1 + βwRVwn−1 + βmRVmn−1 + βsFn−1 + εn

F is either the VADER variance or the XGBoost score from the PV-DM or PV-DBOW vectors. For XGBoost, the true value is added to the training set after every prediction, so the model is continuously re-fitted.

Evaluation

Five models per stock

Each sentiment model is compared to the plain HAR model and to a HAR model with trading volume. Accuracy is measured with the root mean squared and mean absolute forecast errors (RMSFE, MAFE).

  • Diebold-Mariano test: is the error reduction statistically significant?
  • Sign test: does the model improve consistently, not just on a few days?
HAR Volume-HAR VADER-HAR PV-DBOW-HAR PV-DM-HAR

06 / Results

Forecast comparison

PV-DBOW delivers the largest improvements for the two most-tweeted stocks. For Apple, RMSFE drops by 25.5% and MAFE by 27.9%. For Alphabet, RMSFE drops by 30% and MAFE by 33.2%.

VADER and trading volume bring marginal gains at best. For stocks with fewer than 40k tweets, no text-based model improves significantly on the benchmark.

  • PV-DBOW, Diebold-Mariano p-values: 0.090 (Alphabet), 0.193 (Apple)
  • Sign test significant at 10% for Alphabet and Apple (PV-DM)
With only 82 trading days, the results should be read with caution. A multi-year sample would be needed for robust conclusions.

RMSFE by model

Stock HAR VADER PV-DBOW PV-DM Tweets
Apple0.008860.008660.006600.00747534k
Alphabet0.007370.007610.005130.00586273k
Nvidia0.016340.016550.017510.0170478k
J&J0.004090.004580.003980.0039539k
Mastercard0.006900.006680.007210.0070120k
Visa0.006520.006550.007900.0098419k

Highlighted: lowest RMSFE per stock. Lower is better.

07 / Conclusion

Text helps, if there is enough of it

Twitter sentiment can improve realized volatility forecasts, but only when enough tweets are available for Doc2Vec to learn meaningful embeddings.

  • Learned embeddings (PV-DBOW) outperform the VADER dictionary and trading volume
  • The VADER variance feature is not significant for any stock
  • Small corpora (under 40k tweets) are too small for useful embeddings

Limitations and next steps

What I would do differently

  • Longer sample: 82 trading days limit reliable estimation; multi-year data would help.
  • Pretrained language models: transformer models such as FinBERT could improve the text representation.
  • News data: financial news headlines could complement or replace tweets.
  • Lag structure: a two-day lag or a 5-day sentiment average may better capture delayed reactions.
  • Sampling frequency: a signature plot could determine the optimal intraday interval instead of fixed 15 minutes.