\section{Introduction}
Recent research has dampened the consensus about the unpredictability of market prices. 
As a result, predicting the stock market has garnered the attention of diverse fields and domains where different information channels have been explored, 
such as news~\cite{tetlock2007giving, tetlock2008more, Tobias:2013}, search engines~\cite{PreisCurme:2014,Preis5707, citeulike:12299800, JOFI:JOFI1679} 
and, more recently, social media~\cite{Bollen20111, citeulike:13108056, 1507.00784, 2016arXiv160104535S}.

Social media is of particular interest due to the high volume and velocity of activity of an ever-evolving network that is constantly providing and creating information. 
It offers real-time information that can be attributed to specific people, events, markets, and securities.
This is channeled through the use of so-called \textit{cashtags} (e.g., `\$AAPL') in messages, enabling the creation of feeds associated with particular stock symbols. 
The use of \textit{cashtags} has since been propagated onto Twitter, thus providing a means to direct social sentiment to the specific stock or 
securities of that it references. 
As a result, social media user sentiment can be harnessed as a source of information with respect to financial market activity.

Now, the opinions of traders, professional bloggers and analysts, along with laypeople's opinions, 
are aggregated in a dynamic social network that can possibly explain some of the variance in market behavior. 
Initial research~\cite{yahoo1} sought to quantify a relationship between social media analytics with financial market data such as daily returns. 
The observed results outperformed baseline trading strategies, providing evidence that the volume of tweets can reduce uncertainty about financial returns. 
However, volume-based methods disregard any possible predictive information from \textit{qualitative} aspects of the data (i.e., the actual content or content polarity). 
By applying sentiment analysis techniques \cite{1507.00955} to a corpus of tweets, 
a sentiment score or emotion classification can be derived to quantify this qualitative dimension~\cite{1507.00955}. 
The effectiveness of this semantic approach has been examined in~\cite{Bollen20111}, where collective moods analyzed from large 
collections of daily tweets were used to increase an existing financial predictor's performance to an accuracy of 87.6\%.

While a broad analysis across several financial securities might reveal that social signs are relevant for explaining financial dynamics to some extent~\cite{Bollen20111, citeulike:13108056},
little is known about confounding factors that distinguish assets with predictive social signs from assets with no extra information provided by social media.
Leveraged by a non-parametric analysis founded in information-theoretic measures, we demonstrate that social signs can be useful for most stocks from both NYSE and NASDAQ exchanges.
This alone is an interesting and very sound result, compared to current literature' however, we extend this analysis to provide, for the first time,
possible explanations of features that might be essential to distinguish predictive social signs from non-predictive ones. 

    
\subsection{Research Questions}

\begin{itemize}
    \item \textbf{RQ1. \textit{Which stocks from the NASDAQ and NYSE exchanges exhibit a significant information surplus when using social media as a leading indicator of the stocks' future volatility?}} \\ 
    For each stock, lead-lag mutual information analysis is performed between financial and social media data.
    
    
   
   
   
   
   
   


    \item \textbf{RQ2. \textit{Under what configuration of social media and financial variables are social media analytics informative of future financial movements?}} \\
    We aim to determine the feature profile (using financial and social media variables) of companies that are most indicative of a statistically significant 
    social media lead-time information.
\end{itemize}



\section{Methodology}

\subsection{Data}
The data correspond to the daily social media analytics and market quotes of NYSE and NASDAQ listed companies between 01-01-2012 and 01-01-2016.

Social media data were provided by PsychSignal \cite{PsychSignal}, which operates a customized 
Twitter and StockTwits collection framework tracking messages containing \textit{cashtags} (e.g., \$AAPL). 
State-of-the-art natural language processing algorithms were applied to relevant messages, 
labeling each with a sentiment disposition (i.e., bullish or bearish) and a measure of disposition intensity. 
A daily aggregate of these data was provided for each tracked stock. 
Furthermore, for each stock with available social media data, we also considered the historic records of daily stock quotes.
The following data sets were utilized:
\begin{itemize}
    \item \textbf{PsychSignal Social Media Database.} Sentiment daily aggregates containing the following stock quotes attributes:
\begin{itemize}
  \item \texttt{SYMBOL}: the stock symbol (ticker) to which the sentiment data refers to;
  \item \texttt{TIMESTAMP\_UTC}: the date and time of the analyzed data in UTC format;
  \item \texttt{BULLISH\_INTENSITY}: positive sentiment polarity;
  \item \texttt{BEARISH\_INTENSITY}: negative sentiment polarity;
  \item \texttt{BULL\_SCORED\_} \texttt{MESSAGES}: positive sentiment volume, number of messages;
  \item \texttt{BEAR\_SCORED\_} \texttt{MESSAGES}: negative sentiment volume, number of messages;
  \item \texttt{TOTAL\_SCANNED\_} \texttt{MESSAGES}: total number of scanned messages.
\end{itemize}
    \item \textbf{Google Finance.} Daily Market Quotes:
    \begin{itemize}
    \item \texttt{OPEN}: daily opening price;
    \item \texttt{HIGH}: daily high price;
    \item \texttt{LOW}: daily low price;
    \item \texttt{CLOSE}: daily closing price;
    \item \texttt{VOLUME}: financial volume, number of daily trades.
    \end{itemize}
\end{itemize}



\subsubsection{Variables Analyzed}
We used a value of Daily True Range (TR) (see Equation \ref{TRequation}) as a measure of financial volatility. 
A time series of volatility data for each stock was derived using financial quotes as follows:
\begin{equation}\label{TRequation}
    \begin{split}
        TR_{t} = \textup{max}[(\textup{High}_{t}-\textup{Low}_{t}), \\ (\textup{Low}_{t}-\textup{Close}_{t-1}),\\(\textup{High}_{t}-\textup{Close}_{t-1})]
    \end{split}
\end{equation}

We applied a principal component analysis (PCA) to a set of social media variables in order to obtain a time series that contains the majority of underlying information from the sentiment features considered.
\texttt{PCA\_SOCIAL\_CHANGE} is defined as the daily change in the time series obtained by applying the PCA and extracting 
the first principal component from the set of social media variables considered, as defined in Table \ref{sentvariables}.
Principal component analysis is a dimensionality reduction technique that we utilized for feature extraction. 
The PCA permits the reduction of numerous correlated, co-linear variables to a component (or feature set of components). 
Tables \ref{sentvariables} and \ref{finvariables} list the features utilized in this work. 
\input{Tables/sent_variables.txt}
\input{Tables/fin_variables.txt}







\subsection{Information Surplus}
Information surplus~\cite{citeulike:13108056} was derived from mutual information, a measure of the mutual dependence between two data sets. 
Let $S$ be the variable \texttt{PCA\_SOCIAL\_CHANGE}, which is the daily change in the time series obtained by applying the PCA 
and extracting the first principal component from the set of social media variables as defined in Table \ref{sentvariables} and 
let $F$ be \texttt{LOG\_TR\_DIFF}, which is the log of the daily difference in the Daily True Range (see Equation \ref{TRequation}).
If the addition of series $S$ provides information about the movements of series $F$, then it is said that 
a dependency or mutual information ($MI$) exists between $S$ and $F$. However, such a dependency is non-directional; 
in order to determine whether $S$ \textit{leads} $F$, $S$ must provide more information on a lagged series of $F$ than the baseline $MI$ (i.e. non-lagged). 
Determining whether a baseline dependency exists between the series of a social media feature $S_{l=0}$ and a 
financial feature $F_{l=0}$ on the same day is the first step in identifying if $S$ leads or is predictive of $F$. 
Mutual information tells us how much the information about $S$ reduces the uncertainty of $F$. 
Equation (\ref{MI}) shows the formal form, where we attempt to reduce uncertainty or 
increase information by taking the double integral over the log of the joint entropy for both series over each distribution. 

\begin{equation}\label{MI}
MI(S;F)=\int\int f(s,\textup{f})\log\frac{f(s,\textup{f})}{f_{s}(s)f_{\textup{f}}(\textup{f})}\,ds\,df 
\end{equation}

The data need to be grouped into bins to determine the mutual information between the two series. This is necessary 
to calculate entropy because the probability of observing an instance $i$ in each bin $s$ and $f$ constitutes the probability distributions. 
The number of bins is dependent on the size of the data; therefore, our bin sizes were typically identical 
per feature (i.e., there are roughly 365 daily instances of tweets and financial data per security per year). 
The bin size $k$ was calculated using Sturge's Rule (see Equation \ref{MI2}), which has been found to be more accurate than comparable methods when used to calculate entropy in the $MI$ algorithm~\cite{bin}.

\begin{equation}\label{MI2}
k = \textup{log}_{2}n + 1
\end{equation}

Mutual information was then computed at consecutive daily time lags. The information \textit{gain} at time lag $l=i$ is 
calculated by finding the difference between mutual information at $l=i$ and $l=0$, where $i$ is a certain day lag 
and $l=0$ corresponds to the baseline case. Information surplus is expressed as a percent of the $MI$ above what we would expect over the given time frame. 
Therefore, if we achieve a surplus above the average $MI$ from $l=i$ to $l=0$, then the social media time series $S$ is said to lead $F$.

\begin{equation}\label{IS}
\textup{Information Surplus}_{l} = \frac{MI(S;F)_{l=i}-MI(S;F)_{l=0}}{MI(S;F)_{l=0}} \times 100
\end{equation}

\subsection{Validating Significant Information Surplus}
To validate whether the information surplus is statistically significant, we verified whether information is more leading than trailing, and we compared the
obtained results with those obtained via a randomly permuted time-series.

We first filtered companies whose surplus is more \textit{trailing} than it is \textit{leading} 
by identifying stocks for which the daily changes in $S$ carry more information about the daily $F$ in hindsight ($l=-i$) 
rather than during the same ($l=0$) or a previous day ($l=i$). 
We calculated $MI$ on a forward shift (\textit{ex-post}) and on a backward shift (\textit{ex-ante}), 
eliminating stocks where the \textit{ex-post} $MI$ is greater than the \textit{ex-ante} $MI$. 
Where the $MI$ for a lag is less than the $MI$ for a retrospective advance of the series (i.e. $MI_{l=i}<MI_{l=-i}$), 
we can assert that $MI(S;F)$ trails more trailing than it leads, and it is thus insignificant.

A random permutation of the remaining symbols was then performed 100 times. With $\alpha = 0.05$, 
the stocks must outperform 95\% of the randomly permuted data to be considered to have a significant surplus. 

\subsection{Clustering}
To identify the conditions under which social signs may be predictive of financial volatility, 
we utilized a clustering method to determine the configuration of social media and financial variables that is 
indicative of a high information surplus. Each stock was represented as a vector of social media and financial variables. 
In addition, the respective scores of information surplus and the features that describe its nature 
(e.g., the size of the lag it was obtained at) were included. Stocks with similar configurations of social media and financial variables were
grouped together in clusters. 

Inspecting the feature profiles of the clusters (i.e., the average representation of constituent stocks' features) 
allows us to identify the social signs of financial dynamics that are indicative of a high information surplus. 
Clusters with a profile containing many significant lags and high overall information surplus will provide us insight into the 
configuration of variables that characterizes a stock with predictable volatility.

We used k-means clustering, which is an unsupervised learning algorithm that partitions instances into \textit{k} clusters by minimizing the within-cluster sum of square error (WCSS) between instances in each set $S$ using a distance metric (see Equation \ref{kmeans}). 

\begin{equation}\label{kmeans}
\textup{argmin}\, S\sum_{i=1}^{k}\sum_{x\in S_i}\left \| x - u_{i} \right \|^2
\end{equation}

\section{Descriptive Statistics}

The following descriptive statistics provide context for our results. 
Figure \ref{pies} presents the sector breakdown of the top 250 stocks by market cap for both the NASDAQ and NYSE (i.e. 500 stocks in total). 
In the context of this work, it is interesting to note that the NASDAQ is typically characterized as being more volatile than the NYSE exchange \cite{vol2}.

\begin{figure}[h]
    \centering
       \begin{subfigure}[t]{0.49\textwidth}
            \caption{\textbf{A) NASDAQ}}
     \includegraphics[width=\textwidth]{Figures/pie_nasdaq}
    \end{subfigure}
     \begin{subfigure}[t]{0.49\textwidth}
          \caption{\textbf{B) NYSE}}
     \includegraphics[width=\textwidth]{Figures/pie_nyse}
    \end{subfigure}
    \caption{\textbf{Sector breakdown of selected companies by exchange.} Percentage breakdown by sector highlights both that the majority of large cap stocks belong to technology and financial sectors and that the NYSE has a more balanced distribution.}
    \label{pies}
\end{figure}
\FloatBarrier

\begin{figure}[ht]
    \centering
     \begin{subfigure}[t]{0.49\textwidth}
     \caption{\textbf{A) NASDAQ}}
     \includegraphics[width=\textwidth]{Figures/tweet_vol_nasdaq}
    \end{subfigure}
     \begin{subfigure}[t]{0.49\textwidth}
     \caption{\textbf{B) NYSE}}
     \includegraphics[width=\textwidth]{Figures/tweet_vol_nyse}
    \end{subfigure}
    \caption{\textbf{Probability distribution of tweet volume.} There is a wide discrepancy between the NYSE and NASDAQ tweet volumes for the selected companies. 
    The NASDAQ contains several outliers (most notably, \$APPL) that skew the distribution towards the high end. 
    The NASDAQ contains a larger number and a more variable distribution of tweets, with a total of 324,239, and a standard deviation of 5,489, 
    in contrast to 212,368 and 1,241, respectively, for the NYSE.}
    \label{hist}
\end{figure}
\FloatBarrier

\begin{figure}[!h]
    \centering
     \begin{subfigure}[t]{0.49\textwidth}
     \caption{\textbf{A) NASDAQ}}
     \includegraphics[width=\textwidth]{Figures/mktcap_vol_nasdaq}
    \end{subfigure}
     \begin{subfigure}[t]{0.49\textwidth}
     \caption{\textbf{B) NYSE}}
     \includegraphics[width=\textwidth]{Figures/mktcap_vol_nyse}
    \end{subfigure}
    \caption{\textbf{Market cap and Tweet Volume Positive Relationship .} The NYSE and NASDAQ selected companies exhibit a 
    moderate positive correlation between market capitalization (x) and average monthly tweet volume (y).}
    \label{regression}
\end{figure}

Figures \ref{hist} and \ref{regression} compare the relationship between the volume of tweets regarding 
exchange-specific securities and the size of those securities. 
In summary, there is a strong right skew in tweet volume, which contributes to a moderately 
positive relationship between the size of a security and its interest to investors as quantified by tweet volume. 
In both exchanges, there are several notable outliers, such as \$AAPL that contains a disproportionate volume of tweets.


\begin{figure}
    \centering
    \includegraphics[width=.95\textwidth]{Figures/cor_mat_nasdaq}
    \caption{\textbf{NASDAQ correlation matrix.} Upper right (and low left) quadrant reveals weak to no correlation between social and financial features. The NYSE features exhibit comparable correlation.}
    \label{cor_plot}
\end{figure}


\begin{figure}[!h]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
    \centering
    \caption{\textbf{A)}}
     \includegraphics[width=\textwidth]{Figures/b_minus_b_PDF}
    \end{subfigure}
    ~
     \begin{subfigure}[t]{0.45\textwidth}
     \centering
     \caption{\textbf{B)}}
     \includegraphics[width=\textwidth]{Figures/log_tr_diff_PDF}
     \end{subfigure}
    \caption{\textbf{Probability Distribution Examples with Fitted Normal Curve.} The plots are exemplary of the non-normal distributions found in both our social media (A) and financial features (B) for the NASDAQ and NYSE. }
    \label{pdfplot}
\end{figure}



\iffalse
\begin{figure}[h]
    \centering
    \subfloat[]{
     \includegraphics[width=.23\textwidth]{Figures/PCA_sent_change_nowindow_ACPlot}
    }
    \subfloat[]{
     \includegraphics[width=.23\textwidth]{Figures/tr_ACPlot}
    }
    \caption{\textbf{Autocorrelation Plots.} Plots for the features used to calculate $MI$. $S_{PCA}$ (a) and $F_{TR}$ (b) in both the NASDAQ and NYSE exhibit no significant autocorrelation in these features as demonstrated by the example above for \$GE. Consequently, no rolling window is applied to the data.}
    \label{acfPlot}
\end{figure}
\fi

\iffalse
\begin{figure}[h]
    \centering
    \subfloat[NASDAQ]{
     \includegraphics[width=.23\textwidth]{Figures/regress_nasdaq}
    }
    \subfloat[NYSE]{
     \includegraphics[width=.23\textwidth]{Figures/regress_nyse}
    }
    \caption{\textbf{Primary Feature Relationship.} In both (a) and (b), a negative correlation is observed between $S_{PCA}$ (x) and $F_{TR}$ (y): the two feature series used to calculate $MI$.}
    \label{regress}
\end{figure}
\FloatBarrier
\fi


In Figures \ref{cor_plot} and \ref{pdfplot}, 
we present a range of plots related to the feature behavior of the data utilized for calculating the $MI$. 
The correlation plot between all features (see tables \ref{sentvariables} and \ref{finvariables}) in Fig. \ref{cor_plot} reinforces the use of 
PCA dimensionality reduction. As the features are correlated, it is useful to inject a compression of these variables into our MI calculation. 
A correlation was found among social media features pertaining to, for instance, sentiment polarity, the volume of messages as well as with daily financial features.

The majority of features is also characterized by non-normal distributions (see Fig. \ref{pdfplot}). 
For features that are highly dependent on market capitalization (e.g., mean average monthly message volume as (see Figure \ref{hist})), 
log-normal behavior exists. Furthermore, NASDAQ and NYSE stocks exchanges exhibit comparable results.

\section{Results}
We used the outlined information surplus method~\cite{citeulike:13108056} and data from 01/01/2012 to 01/01/2016 
to determine which stocks in the NYSE and NASDAQ exhibit, on average, a significant leading information surplus. 
We then built on this method by clustering stocks and examining which configuration of variables is indicative of a high information surplus.

\subsection{Reducing Uncertainty about Volatility}

Experiments on the NASDAQ and NYSE were carried out in tandem, and they produced comparable results. 
We found 101 stocks from the NASDAQ that exhibit a leading information surplus when using social media as an indicator of the daily change in True Range (our measure of volatility, see Equation \ref{TRequation}). 
Of the original 250 stocks examined, 149 did not have a significant surplus, meaning that the surplus in each time lag over a 10-day 
period did not exceed the expected surplus. Thus, for example, the periods in Fig. \ref{MI_sample} where the blue \textit{ex-ante} 
series is below the average ex-post for the 
10-day period do not contain a significant leading surplus. 
All 101 stocks with a significant leading surplus, however, passed through the second validation test by performing better than 95\% of the randomly permuted data. 

For the NYSE, 91 of the original 250 stocks exhibited a significant leading surplus. In addition, only one company did not pass the second validation test. 

The full list of significant stocks from the NASDAQ and NYSE can be found in Appendix \ref{appendix}.

\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{Figures/MI_sample}
    \caption{\textbf{Sample Information Surplus.} For each lag, the surplus is calculated as the amount of $MI$ above the base case, $MI_{t=0}$. 
    A significant \textit{ex-ante} surplus occurs where the surplus is greater than the average \textit{ex-post} surplus for the 10-day window.}
    \label{MI_sample}
\end{figure}

\subsection{Leading Surplus Indicators}

Stocks with a statistically significant information surplus were clustered using relevant numeric features studied (see Tables \ref{sentvariables} and \ref{finvariables}).  
The aim of the clustering is to identify the cluster feature profile of stocks with a surplus exhibited at many time lags (i.e. high \texttt{POS\_LAG\_COUNT} values) 
and the stocks with the highest surplus (i.e. high \texttt{MAX\_INF\_SURP\_PCT} values). 
The results were robust across different values of number of clusters \textit{k} tested. 
We found that moderate choices of \textit{k} all produced the noteworthy cluster profile presented in Fig. \ref{radar}, 
where a significant surplus is almost completely contained. 
The two cluster profiles presented in Fig. \ref{radar} correspond to the cluster centroid feature profiles of both the NASDAQ and NYSE which contained the highest information surplus values. 
\begin{figure}[!h]
    \centering
   \begin{subfigure}[t]{0.45\textwidth}
   \centering
     \includegraphics[width=\textwidth]{Figures/radar_nasdaq}
     \end{subfigure}
     ~
    \begin{subfigure}[t]{0.45\textwidth}
    \centering
     \includegraphics[width=\textwidth]{Figures/radar_nyse}
     \end{subfigure}
    \caption{\textbf{Radar Plot of Cluster Centroid Feature Profiles.} In both the NASDAQ and NYSE, we observe a cluster that contains the majority of leading surplus lags (\texttt{POS\_LAG\_COUNT}) and maximum surplus (\texttt{MAX\_INF\_SURP\_PCT}) for $k=\left \{ 2,3,4,5,6,7 \right \}$. The important relationship represented in this cluster is the high value of \texttt{BULL\_MINUS\_BEAR}.}
    \label{radar}
\end{figure}

Interestingly, \texttt{BULL\_MINUS\_BEAR} is maximized in the cluster, 
indicating that stocks with many leading surpluses during the 10-day period (\texttt{POS\_LAG\_COUNT}) 
and large significant surpluses (\texttt{MAX\_INF\_SURP\_PERC}) also have a particular ratio of bullish to bearing intensity. 
This suggests that in isolation, messages with a strong positive or negative sentiment are not as informative about future volatility; 
rather, the combination of features is important in the context of volatility or daily risk. 
Although we can speculate about the underlying factors contributing to this behavior, we note that this feature relationship seems to contradict the traditionally held assumption that \textit{negative} sentiment is more indicative of volatility. 
It may be expected that a volatile security is lead by historically negative or bearish tweets because volatility is associated with risk, 
and high risk is synonymous with negative sentiment; however, our clustering suggests otherwise: 
the polarity between all sentiment-loaded tweets is important in predicting volatility. 
Another noteworthy implication of the clustering is the absence of \texttt{VOLUME} (number of trades), 
\texttt{LOG\_RETURN}, and \texttt{TOTAL\_SCANNED\_MESSAGES} (volume of messages) in the cluster profile associated with significant leading surpluses. 
While those are features are commonly used in the literature, in this study they did not prove to be as relevant as the ratio of bullish to bearish messages.




\section{Conclusion}

Our results demonstrate that signals from social media can lead daily financial volatility in a large proportion of the 500 stocks 
examined from the NASDAQ and NYSE. A total of 101 (40\%) stocks from the NASDAQ and a further 91 stocks (36\%) from the NYSE exhibited a 
statistically significant information surplus. This was found by identifying an increase in the mutual information between social and financial time series. 

While our framework of analysis is closely aligned with earlier works~\cite{citeulike:13108056}, our results are novel. 
First, by identifying an information surplus in a large number of stocks, 
we found that social media has the capability to lead financial markets in a much larger segment of the market than in previous works, 
which only reported 12 stocks~\cite{citeulike:13108056} of significant lead-time information.

A key aim of this work was to go beyond the determination of the predictive capability of social media and attempt to determine the 
configuration of features with which this occurs.  
Our results revealed that stocks with the highest net sentiment polarity had the highest information surpluses. 
Interestingly, in contrast to other works,  stocks with a high information surplus did not require a high volume of messages and did not have a high average log-return. 
To identify this, we characterized each stock using an average representation of social and financial variables using PCA analysis, and we 
applied a clustering algorithm to inspect the group of stocks that exhibited the highest maximum information surplus.



In summary, we have challenged the notion of the efficient market hypothesis by examining the effect of the continuously 
evolving source of information embedded in social media and its effect in financial volatility. 
Using a method rooted in information theory, we have presented results that have identified a large set 
of stocks for which social media can be informative regarding financial volatility. 
By clustering stocks based on the joint feature sets of social and financial variables, our research has taken an important first step in 
characterizing the conditions under which this can be the case. 
The results indicate that social media is most informative about financial market volatility when the ratio of bullish to bearish sentiment 
is high, even when the number of messages is low. 
The reported results are reproducible via an open-source library, which allows the methodology outlined in this 
research paper to be re-used for sentiment analysis applied to finance. 

\section*{Acknowledgment}
This work was supported by PsychSignal for providing social media sentiment analytics data. We also thank Prof. Tomaso Aste for valuable comments provided.

\bibliographystyle{unsrt}

\section{Introduction}
Recent research has dampened the consensus about the unpredictability of market prices. 
As a result, predicting the stock market has garnered the attention of diverse fields and domains where different information channels have been explored, 
such as news~\cite{tetlock2007giving, tetlock2008more, Tobias:2013}, search engines~\cite{PreisCurme:2014,Preis5707, citeulike:12299800, JOFI:JOFI1679} 
and, more recently, social media~\cite{Bollen20111, citeulike:13108056, 1507.00784, 2016arXiv160104535S}.

Social media is of particular interest due to the high volume and velocity of activity of an ever-evolving network that is constantly providing and creating information. 
It offers real-time information that can be attributed to specific people, events, markets, and securities.
This is channeled through the use of so-called \textit{cashtags} (e.g., `\$AAPL') in messages, enabling the creation of feeds associated with particular stock symbols. 
The use of \textit{cashtags} has since been propagated onto Twitter, thus providing a means to direct social sentiment to the specific stock or 
securities of that it references. 
As a result, social media user sentiment can be harnessed as a source of information with respect to financial market activity.

Now, the opinions of traders, professional bloggers and analysts, along with laypeople's opinions, 
are aggregated in a dynamic social network that can possibly explain some of the variance in market behavior. 
Initial research~\cite{yahoo1} sought to quantify a relationship between social media analytics with financial market data such as daily returns. 
The observed results outperformed baseline trading strategies, providing evidence that the volume of tweets can reduce uncertainty about financial returns. 
However, volume-based methods disregard any possible predictive information from \textit{qualitative} aspects of the data (i.e., the actual content or content polarity). 
By applying sentiment analysis techniques \cite{1507.00955} to a corpus of tweets, 
a sentiment score or emotion classification can be derived to quantify this qualitative dimension~\cite{1507.00955}. 
The effectiveness of this semantic approach has been examined in~\cite{Bollen20111}, where collective moods analyzed from large 
collections of daily tweets were used to increase an existing financial predictor's performance to an accuracy of 87.6\%.

While a broad analysis across several financial securities might reveal that social signs are relevant for explaining financial dynamics to some extent~\cite{Bollen20111, citeulike:13108056},
little is known about confounding factors that distinguish assets with predictive social signs from assets with no extra information provided by social media.
Leveraged by a non-parametric analysis founded in information-theoretic measures, we demonstrate that social signs can be useful for most stocks from both NYSE and NASDAQ exchanges.
This alone is an interesting and very sound result, compared to current literature' however, we extend this analysis to provide, for the first time,
possible explanations of features that might be essential to distinguish predictive social signs from non-predictive ones. 

    
\subsection{Research Questions}

\begin{itemize}
    \item \textbf{RQ1. \textit{Which stocks from the NASDAQ and NYSE exchanges exhibit a significant information surplus when using social media as a leading indicator of the stocks' future volatility?}} \\ 
    For each stock, lead-lag mutual information analysis is performed between financial and social media data.
    
    
   
   
   
   
   
   


    \item \textbf{RQ2. \textit{Under what configuration of social media and financial variables are social media analytics informative of future financial movements?}} \\
    We aim to determine the feature profile (using financial and social media variables) of companies that are most indicative of a statistically significant 
    social media lead-time information.
\end{itemize}



\section{Methodology}

\subsection{Data}
The data correspond to the daily social media analytics and market quotes of NYSE and NASDAQ listed companies between 01-01-2012 and 01-01-2016.

Social media data were provided by PsychSignal \cite{PsychSignal}, which operates a customized 
Twitter and StockTwits collection framework tracking messages containing \textit{cashtags} (e.g., \$AAPL). 
State-of-the-art natural language processing algorithms were applied to relevant messages, 
labeling each with a sentiment disposition (i.e., bullish or bearish) and a measure of disposition intensity. 
A daily aggregate of these data was provided for each tracked stock. 
Furthermore, for each stock with available social media data, we also considered the historic records of daily stock quotes.
The following data sets were utilized:
\begin{itemize}
    \item \textbf{PsychSignal Social Media Database.} Sentiment daily aggregates containing the following stock quotes attributes:
\begin{itemize}
  \item \texttt{SYMBOL}: the stock symbol (ticker) to which the sentiment data refers to;
  \item \texttt{TIMESTAMP\_UTC}: the date and time of the analyzed data in UTC format;
  \item \texttt{BULLISH\_INTENSITY}: positive sentiment polarity;
  \item \texttt{BEARISH\_INTENSITY}: negative sentiment polarity;
  \item \texttt{BULL\_SCORED\_} \texttt{MESSAGES}: positive sentiment volume, number of messages;
  \item \texttt{BEAR\_SCORED\_} \texttt{MESSAGES}: negative sentiment volume, number of messages;
  \item \texttt{TOTAL\_SCANNED\_} \texttt{MESSAGES}: total number of scanned messages.
\end{itemize}
    \item \textbf{Google Finance.} Daily Market Quotes:
    \begin{itemize}
    \item \texttt{OPEN}: daily opening price;
    \item \texttt{HIGH}: daily high price;
    \item \texttt{LOW}: daily low price;
    \item \texttt{CLOSE}: daily closing price;
    \item \texttt{VOLUME}: financial volume, number of daily trades.
    \end{itemize}
\end{itemize}



\subsubsection{Variables Analyzed}
We used a value of Daily True Range (TR) (see Equation \ref{TRequation}) as a measure of financial volatility. 
A time series of volatility data for each stock was derived using financial quotes as follows:
\begin{equation}\label{TRequation}
    \begin{split}
        TR_{t} = \textup{max}[(\textup{High}_{t}-\textup{Low}_{t}), \\ (\textup{Low}_{t}-\textup{Close}_{t-1}),\\(\textup{High}_{t}-\textup{Close}_{t-1})]
    \end{split}
\end{equation}

We applied a principal component analysis (PCA) to a set of social media variables in order to obtain a time series that contains the majority of underlying information from the sentiment features considered.
\texttt{PCA\_SOCIAL\_CHANGE} is defined as the daily change in the time series obtained by applying the PCA and extracting 
the first principal component from the set of social media variables considered, as defined in Table \ref{sentvariables}.
Principal component analysis is a dimensionality reduction technique that we utilized for feature extraction. 
The PCA permits the reduction of numerous correlated, co-linear variables to a component (or feature set of components). 
Tables \ref{sentvariables} and \ref{finvariables} list the features utilized in this work. 
\input{Tables/sent_variables.txt}
\input{Tables/fin_variables.txt}







\subsection{Information Surplus}
Information surplus~\cite{citeulike:13108056} was derived from mutual information, a measure of the mutual dependence between two data sets. 
Let $S$ be the variable \texttt{PCA\_SOCIAL\_CHANGE}, which is the daily change in the time series obtained by applying the PCA 
and extracting the first principal component from the set of social media variables as defined in Table \ref{sentvariables} and 
let $F$ be \texttt{LOG\_TR\_DIFF}, which is the log of the daily difference in the Daily True Range (see Equation \ref{TRequation}).
If the addition of series $S$ provides information about the movements of series $F$, then it is said that 
a dependency or mutual information ($MI$) exists between $S$ and $F$. However, such a dependency is non-directional; 
in order to determine whether $S$ \textit{leads} $F$, $S$ must provide more information on a lagged series of $F$ than the baseline $MI$ (i.e. non-lagged). 
Determining whether a baseline dependency exists between the series of a social media feature $S_{l=0}$ and a 
financial feature $F_{l=0}$ on the same day is the first step in identifying if $S$ leads or is predictive of $F$. 
Mutual information tells us how much the information about $S$ reduces the uncertainty of $F$. 
Equation (\ref{MI}) shows the formal form, where we attempt to reduce uncertainty or 
increase information by taking the double integral over the log of the joint entropy for both series over each distribution. 

\begin{equation}\label{MI}
MI(S;F)=\int\int f(s,\textup{f})\log\frac{f(s,\textup{f})}{f_{s}(s)f_{\textup{f}}(\textup{f})}\,ds\,df 
\end{equation}

The data need to be grouped into bins to determine the mutual information between the two series. This is necessary 
to calculate entropy because the probability of observing an instance $i$ in each bin $s$ and $f$ constitutes the probability distributions. 
The number of bins is dependent on the size of the data; therefore, our bin sizes were typically identical 
per feature (i.e., there are roughly 365 daily instances of tweets and financial data per security per year). 
The bin size $k$ was calculated using Sturge's Rule (see Equation \ref{MI2}), which has been found to be more accurate than comparable methods when used to calculate entropy in the $MI$ algorithm~\cite{bin}.

\begin{equation}\label{MI2}
k = \textup{log}_{2}n + 1
\end{equation}

Mutual information was then computed at consecutive daily time lags. The information \textit{gain} at time lag $l=i$ is 
calculated by finding the difference between mutual information at $l=i$ and $l=0$, where $i$ is a certain day lag 
and $l=0$ corresponds to the baseline case. Information surplus is expressed as a percent of the $MI$ above what we would expect over the given time frame. 
Therefore, if we achieve a surplus above the average $MI$ from $l=i$ to $l=0$, then the social media time series $S$ is said to lead $F$.

\begin{equation}\label{IS}
\textup{Information Surplus}_{l} = \frac{MI(S;F)_{l=i}-MI(S;F)_{l=0}}{MI(S;F)_{l=0}} \times 100
\end{equation}

\subsection{Validating Significant Information Surplus}
To validate whether the information surplus is statistically significant, we verified whether information is more leading than trailing, and we compared the
obtained results with those obtained via a randomly permuted time-series.

We first filtered companies whose surplus is more \textit{trailing} than it is \textit{leading} 
by identifying stocks for which the daily changes in $S$ carry more information about the daily $F$ in hindsight ($l=-i$) 
rather than during the same ($l=0$) or a previous day ($l=i$). 
We calculated $MI$ on a forward shift (\textit{ex-post}) and on a backward shift (\textit{ex-ante}), 
eliminating stocks where the \textit{ex-post} $MI$ is greater than the \textit{ex-ante} $MI$. 
Where the $MI$ for a lag is less than the $MI$ for a retrospective advance of the series (i.e. $MI_{l=i}<MI_{l=-i}$), 
we can assert that $MI(S;F)$ trails more trailing than it leads, and it is thus insignificant.

A random permutation of the remaining symbols was then performed 100 times. With $\alpha = 0.05$, 
the stocks must outperform 95\% of the randomly permuted data to be considered to have a significant surplus. 

\subsection{Clustering}
To identify the conditions under which social signs may be predictive of financial volatility, 
we utilized a clustering method to determine the configuration of social media and financial variables that is 
indicative of a high information surplus. Each stock was represented as a vector of social media and financial variables. 
In addition, the respective scores of information surplus and the features that describe its nature 
(e.g., the size of the lag it was obtained at) were included. Stocks with similar configurations of social media and financial variables were
grouped together in clusters. 

Inspecting the feature profiles of the clusters (i.e., the average representation of constituent stocks' features) 
allows us to identify the social signs of financial dynamics that are indicative of a high information surplus. 
Clusters with a profile containing many significant lags and high overall information surplus will provide us insight into the 
configuration of variables that characterizes a stock with predictable volatility.

We used k-means clustering, which is an unsupervised learning algorithm that partitions instances into \textit{k} clusters by minimizing the within-cluster sum of square error (WCSS) between instances in each set $S$ using a distance metric (see Equation \ref{kmeans}). 

\begin{equation}\label{kmeans}
\textup{argmin}\, S\sum_{i=1}^{k}\sum_{x\in S_i}\left \| x - u_{i} \right \|^2
\end{equation}

\section{Descriptive Statistics}

The following descriptive statistics provide context for our results. 
Figure \ref{pies} presents the sector breakdown of the top 250 stocks by market cap for both the NASDAQ and NYSE (i.e. 500 stocks in total). 
In the context of this work, it is interesting to note that the NASDAQ is typically characterized as being more volatile than the NYSE exchange \cite{vol2}.

\begin{figure}[h]
    \centering
       \begin{subfigure}[t]{0.49\textwidth}
            \caption{\textbf{A) NASDAQ}}
     \includegraphics[width=\textwidth]{Figures/pie_nasdaq}
    \end{subfigure}
     \begin{subfigure}[t]{0.49\textwidth}
          \caption{\textbf{B) NYSE}}
     \includegraphics[width=\textwidth]{Figures/pie_nyse}
    \end{subfigure}
    \caption{\textbf{Sector breakdown of selected companies by exchange.} Percentage breakdown by sector highlights both that the majority of large cap stocks belong to technology and financial sectors and that the NYSE has a more balanced distribution.}
    \label{pies}
\end{figure}
\FloatBarrier

\begin{figure}[ht]
    \centering
     \begin{subfigure}[t]{0.49\textwidth}
     \caption{\textbf{A) NASDAQ}}
     \includegraphics[width=\textwidth]{Figures/tweet_vol_nasdaq}
    \end{subfigure}
     \begin{subfigure}[t]{0.49\textwidth}
     \caption{\textbf{B) NYSE}}
     \includegraphics[width=\textwidth]{Figures/tweet_vol_nyse}
    \end{subfigure}
    \caption{\textbf{Probability distribution of tweet volume.} There is a wide discrepancy between the NYSE and NASDAQ tweet volumes for the selected companies. 
    The NASDAQ contains several outliers (most notably, \$APPL) that skew the distribution towards the high end. 
    The NASDAQ contains a larger number and a more variable distribution of tweets, with a total of 324,239, and a standard deviation of 5,489, 
    in contrast to 212,368 and 1,241, respectively, for the NYSE.}
    \label{hist}
\end{figure}
\FloatBarrier

\begin{figure}[!h]
    \centering
     \begin{subfigure}[t]{0.49\textwidth}
     \caption{\textbf{A) NASDAQ}}
     \includegraphics[width=\textwidth]{Figures/mktcap_vol_nasdaq}
    \end{subfigure}
     \begin{subfigure}[t]{0.49\textwidth}
     \caption{\textbf{B) NYSE}}
     \includegraphics[width=\textwidth]{Figures/mktcap_vol_nyse}
    \end{subfigure}
    \caption{\textbf{Market cap and Tweet Volume Positive Relationship .} The NYSE and NASDAQ selected companies exhibit a 
    moderate positive correlation between market capitalization (x) and average monthly tweet volume (y).}
    \label{regression}
\end{figure}

Figures \ref{hist} and \ref{regression} compare the relationship between the volume of tweets regarding 
exchange-specific securities and the size of those securities. 
In summary, there is a strong right skew in tweet volume, which contributes to a moderately 
positive relationship between the size of a security and its interest to investors as quantified by tweet volume. 
In both exchanges, there are several notable outliers, such as \$AAPL that contains a disproportionate volume of tweets.


\begin{figure}
    \centering
    \includegraphics[width=.95\textwidth]{Figures/cor_mat_nasdaq}
    \caption{\textbf{NASDAQ correlation matrix.} Upper right (and low left) quadrant reveals weak to no correlation between social and financial features. The NYSE features exhibit comparable correlation.}
    \label{cor_plot}
\end{figure}


\begin{figure}[!h]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
    \centering
    \caption{\textbf{A)}}
     \includegraphics[width=\textwidth]{Figures/b_minus_b_PDF}
    \end{subfigure}
    ~
     \begin{subfigure}[t]{0.45\textwidth}
     \centering
     \caption{\textbf{B)}}
     \includegraphics[width=\textwidth]{Figures/log_tr_diff_PDF}
     \end{subfigure}
    \caption{\textbf{Probability Distribution Examples with Fitted Normal Curve.} The plots are exemplary of the non-normal distributions found in both our social media (A) and financial features (B) for the NASDAQ and NYSE. }
    \label{pdfplot}
\end{figure}



\iffalse
\begin{figure}[h]
    \centering
    \subfloat[]{
     \includegraphics[width=.23\textwidth]{Figures/PCA_sent_change_nowindow_ACPlot}
    }
    \subfloat[]{
     \includegraphics[width=.23\textwidth]{Figures/tr_ACPlot}
    }
    \caption{\textbf{Autocorrelation Plots.} Plots for the features used to calculate $MI$. $S_{PCA}$ (a) and $F_{TR}$ (b) in both the NASDAQ and NYSE exhibit no significant autocorrelation in these features as demonstrated by the example above for \$GE. Consequently, no rolling window is applied to the data.}
    \label{acfPlot}
\end{figure}
\fi

\iffalse
\begin{figure}[h]
    \centering
    \subfloat[NASDAQ]{
     \includegraphics[width=.23\textwidth]{Figures/regress_nasdaq}
    }
    \subfloat[NYSE]{
     \includegraphics[width=.23\textwidth]{Figures/regress_nyse}
    }
    \caption{\textbf{Primary Feature Relationship.} In both (a) and (b), a negative correlation is observed between $S_{PCA}$ (x) and $F_{TR}$ (y): the two feature series used to calculate $MI$.}
    \label{regress}
\end{figure}
\FloatBarrier
\fi


In Figures \ref{cor_plot} and \ref{pdfplot}, 
we present a range of plots related to the feature behavior of the data utilized for calculating the $MI$. 
The correlation plot between all features (see tables \ref{sentvariables} and \ref{finvariables}) in Fig. \ref{cor_plot} reinforces the use of 
PCA dimensionality reduction. As the features are correlated, it is useful to inject a compression of these variables into our MI calculation. 
A correlation was found among social media features pertaining to, for instance, sentiment polarity, the volume of messages as well as with daily financial features.

The majority of features is also characterized by non-normal distributions (see Fig. \ref{pdfplot}). 
For features that are highly dependent on market capitalization (e.g., mean average monthly message volume as (see Figure \ref{hist})), 
log-normal behavior exists. Furthermore, NASDAQ and NYSE stocks exchanges exhibit comparable results.

\section{Results}
We used the outlined information surplus method~\cite{citeulike:13108056} and data from 01/01/2012 to 01/01/2016 
to determine which stocks in the NYSE and NASDAQ exhibit, on average, a significant leading information surplus. 
We then built on this method by clustering stocks and examining which configuration of variables is indicative of a high information surplus.

\subsection{Reducing Uncertainty about Volatility}

Experiments on the NASDAQ and NYSE were carried out in tandem, and they produced comparable results. 
We found 101 stocks from the NASDAQ that exhibit a leading information surplus when using social media as an indicator of the daily change in True Range (our measure of volatility, see Equation \ref{TRequation}). 
Of the original 250 stocks examined, 149 did not have a significant surplus, meaning that the surplus in each time lag over a 10-day 
period did not exceed the expected surplus. Thus, for example, the periods in Fig. \ref{MI_sample} where the blue \textit{ex-ante} 
series is below the average ex-post for the 
10-day period do not contain a significant leading surplus. 
All 101 stocks with a significant leading surplus, however, passed through the second validation test by performing better than 95\% of the randomly permuted data. 

For the NYSE, 91 of the original 250 stocks exhibited a significant leading surplus. In addition, only one company did not pass the second validation test. 

The full list of significant stocks from the NASDAQ and NYSE can be found in Appendix \ref{appendix}.

\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{Figures/MI_sample}
    \caption{\textbf{Sample Information Surplus.} For each lag, the surplus is calculated as the amount of $MI$ above the base case, $MI_{t=0}$. 
    A significant \textit{ex-ante} surplus occurs where the surplus is greater than the average \textit{ex-post} surplus for the 10-day window.}
    \label{MI_sample}
\end{figure}

\subsection{Leading Surplus Indicators}

Stocks with a statistically significant information surplus were clustered using relevant numeric features studied (see Tables \ref{sentvariables} and \ref{finvariables}).  
The aim of the clustering is to identify the cluster feature profile of stocks with a surplus exhibited at many time lags (i.e. high \texttt{POS\_LAG\_COUNT} values) 
and the stocks with the highest surplus (i.e. high \texttt{MAX\_INF\_SURP\_PCT} values). 
The results were robust across different values of number of clusters \textit{k} tested. 
We found that moderate choices of \textit{k} all produced the noteworthy cluster profile presented in Fig. \ref{radar}, 
where a significant surplus is almost completely contained. 
The two cluster profiles presented in Fig. \ref{radar} correspond to the cluster centroid feature profiles of both the NASDAQ and NYSE which contained the highest information surplus values. 
\begin{figure}[!h]
    \centering
   \begin{subfigure}[t]{0.45\textwidth}
   \centering
     \includegraphics[width=\textwidth]{Figures/radar_nasdaq}
     \end{subfigure}
     ~
    \begin{subfigure}[t]{0.45\textwidth}
    \centering
     \includegraphics[width=\textwidth]{Figures/radar_nyse}
     \end{subfigure}
    \caption{\textbf{Radar Plot of Cluster Centroid Feature Profiles.} In both the NASDAQ and NYSE, we observe a cluster that contains the majority of leading surplus lags (\texttt{POS\_LAG\_COUNT}) and maximum surplus (\texttt{MAX\_INF\_SURP\_PCT}) for $k=\left \{ 2,3,4,5,6,7 \right \}$. The important relationship represented in this cluster is the high value of \texttt{BULL\_MINUS\_BEAR}.}
    \label{radar}
\end{figure}

Interestingly, \texttt{BULL\_MINUS\_BEAR} is maximized in the cluster, 
indicating that stocks with many leading surpluses during the 10-day period (\texttt{POS\_LAG\_COUNT}) 
and large significant surpluses (\texttt{MAX\_INF\_SURP\_PERC}) also have a particular ratio of bullish to bearing intensity. 
This suggests that in isolation, messages with a strong positive or negative sentiment are not as informative about future volatility; 
rather, the combination of features is important in the context of volatility or daily risk. 
Although we can speculate about the underlying factors contributing to this behavior, we note that this feature relationship seems to contradict the traditionally held assumption that \textit{negative} sentiment is more indicative of volatility. 
It may be expected that a volatile security is lead by historically negative or bearish tweets because volatility is associated with risk, 
and high risk is synonymous with negative sentiment; however, our clustering suggests otherwise: 
the polarity between all sentiment-loaded tweets is important in predicting volatility. 
Another noteworthy implication of the clustering is the absence of \texttt{VOLUME} (number of trades), 
\texttt{LOG\_RETURN}, and \texttt{TOTAL\_SCANNED\_MESSAGES} (volume of messages) in the cluster profile associated with significant leading surpluses. 
While those are features are commonly used in the literature, in this study they did not prove to be as relevant as the ratio of bullish to bearish messages.




\section{Conclusion}

Our results demonstrate that signals from social media can lead daily financial volatility in a large proportion of the 500 stocks 
examined from the NASDAQ and NYSE. A total of 101 (40\%) stocks from the NASDAQ and a further 91 stocks (36\%) from the NYSE exhibited a 
statistically significant information surplus. This was found by identifying an increase in the mutual information between social and financial time series. 

While our framework of analysis is closely aligned with earlier works~\cite{citeulike:13108056}, our results are novel. 
First, by identifying an information surplus in a large number of stocks, 
we found that social media has the capability to lead financial markets in a much larger segment of the market than in previous works, 
which only reported 12 stocks~\cite{citeulike:13108056} of significant lead-time information.

A key aim of this work was to go beyond the determination of the predictive capability of social media and attempt to determine the 
configuration of features with which this occurs.  
Our results revealed that stocks with the highest net sentiment polarity had the highest information surpluses. 
Interestingly, in contrast to other works,  stocks with a high information surplus did not require a high volume of messages and did not have a high average log-return. 
To identify this, we characterized each stock using an average representation of social and financial variables using PCA analysis, and we 
applied a clustering algorithm to inspect the group of stocks that exhibited the highest maximum information surplus.



In summary, we have challenged the notion of the efficient market hypothesis by examining the effect of the continuously 
evolving source of information embedded in social media and its effect in financial volatility. 
Using a method rooted in information theory, we have presented results that have identified a large set 
of stocks for which social media can be informative regarding financial volatility. 
By clustering stocks based on the joint feature sets of social and financial variables, our research has taken an important first step in 
characterizing the conditions under which this can be the case. 
The results indicate that social media is most informative about financial market volatility when the ratio of bullish to bearish sentiment 
is high, even when the number of messages is low. 
The reported results are reproducible via an open-source library, which allows the methodology outlined in this 
research paper to be re-used for sentiment analysis applied to finance. 

\section*{Acknowledgment}
This work was supported by PsychSignal for providing social media sentiment analytics data. We also thank Prof. Tomaso Aste for valuable comments provided.

\bibliographystyle{unsrt}
