• No results found

The impact of consumer sentiment on the stock market : an event-study on the effects of reddit comment volume and valence

N/A
N/A
Protected

Academic year: 2021

Share "The impact of consumer sentiment on the stock market : an event-study on the effects of reddit comment volume and valence"

Copied!
56
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

The Impact of Consumer

Sentiment on the Stock Market:

An Event-study on the Effects of

Reddit Comment Volume and

Valence

Author: Max van Rossem

Supervisor: Dr. R. Perez Ribas

Course of Studies: Business Economics & Strategy

6314M0264Y

Student ID: 10071059

Closing date: 15

th

August 2017

EC: 15

(2)

Abstract

Previous literature has been able to uncover a relationship between media sentiment and the value of shares on the stock market. The objective of this thesis is to determine if there is a statistically relevant reaction of the market to consumer sentiment. The widely used online platform ’Reddit’ is used as a proxy for representing consumer sentiment.

Using a word counting algorithm sentiment scores for three technology companies; Apple, Google and Netflix are constructed. An event study where events are defined by peaks in comment activity is used to test if sentiment valence can predict abnormal stock returns and/or trading volume. No significant relationship is found for either. The main reasons for the lack of findings is explained by confounding events, the lack of reliability of the valence measure and the robust nature of large companies in the face of short term changes in sentiment.

(3)

Statement

This document is written by Student Max van Rossem who declares to take full responsibility for the contents of this document. I declare that the text and the work presented in this document is original and that no sources other than those mentioned in the text and its references have been used in creating it. The Faculty of Economics and Business is responsible solely for the supervision of completion of the work, not for the contents. Wharton Research Data Services (WRDS) was used in preparing this thesis. This service and the data available thereon constitute valuable intellectual property and trade secrets of WRDS and/or its third-party suppliers.

(4)

Contents

1 Introduction 1

2 Literature and Theory 3

3 Data 8

3.1 Reddit as a source for sentiment . . . 8

3.2 Data adjustment . . . 10

3.3 Sentiment valance . . . 10

3.4 Financial data . . . 11

4 Methodology 12 4.1 Defining the Event Study . . . 12

4.2 Testing for Abnormal Returns . . . 16

4.3 Regression analysis: the impact of comment valence on Abnormal Returns and volume traded . . . 18

5 Evaluation 20

(5)

1

Introduction

On September 9th 2014 Apple unveiled the details of its latest Iphone to the market. As the unveiling of the Iphone 6(s) occurred the stock price propelled up. But as the day progressed the price fell, closing lower than where it had opened. On the same day an online social platform known as ’Reddit’ saw a large volume of conversation regarding the topic ’Apple’. As the 5thmost visited website in the United States, consumers of all kinds aggregated to voice their thoughts. The success of any product depends on the opinion of its consumers. For volatile markets such as that of the tech-industry, information about current consumer sentiment is arguably worth even more. The question posed in this thesis presents itself: if investors had known the sentiment expressed on Reddit on the day of the unveiling, could they have predicted how the market would respond? Papers written by authors such as [Tetlock, 2007] and [Oliveira et al., 2017] analyzed the content given by the Wall Street Journal column and micro-blogging data from Twitter. Tetlock was able to find that abnormal pessimism measures lead to increased trading volume. Oliveira et al. found that posting vol-ume on Twitter was relevant to forecasting returns for technology related companies. This thesis is the first such study that takes Reddit as a source. Contrary to previous findings the sentiment derived from Reddit does not show larger returns induced by spikes in comment activity. The valence of Reddit comments shows no significant capability for predicting the direction of abnormal returns during the defined events.

The three selected technology related firms used in this analysis are Apple, Google and Netflix. Oliviera el al. found the impact of sentiment on technology companies could be explained to be due to a greater degree of irrational investors. The effect of sentiment in tech-companies was amplified for smaller capitalization companies lacking track records (2017). Small firms are less known to the public. With limited comment activity the quality of sentiment data can become arbitrary making the analysis less robust.

(6)

In keeping with the findings of previous literature there are three pri-mary questions to which this thesis intends to contribute.

The first question posed is whether spikes in comment activity on Reddit signify abnormal returns for the relevant firm’s stock price. News items have varying levels of traction with the public. Platforms such as Reddit can give an approximation on how controversial a news item is in the eyes of the general population. For example the announcement of Netflix paying $90 million for a new Will Smith movie did not generate as much conversation as a travel ban to the United States that affected employees of Netflix. Here, an event study was used to analyze sets of isolated events for the three companies. Events were determined by peaks in comment activity on Reddit. Three threshold levels are used to define whether a given activity level is classified as an event. Results indicated that raising the activity threshold resulted in, no significant increase of abnormal re-turns during the event window relative to abnormal rere-turns during the estimation period.

The second question addressed whether meaning could be interpreted from the valence of Reddit sentiment. A rudimentary word counting algorithm tallied the number of positive or negative words used. This was used to calculate a ’valance’ (a relative measure of ‘positivity’ of comments) for a given day. Tetlock was able to show Twitter sentiment relevance in forecasting returns (2007). Similarly, we attempt to define if that values of valence predict changes in abnormal returns. The resulting coefficients for each regression was positive (implying a positive valence relating to positive cumulative abnormal returns), but none were significant.

The third question investigated the possibility to conclude a similar rela-tionship between valence and trade volume as found by Tetlock for Twitter. The volume traded on event days for each company was standardized and regressed with the valence (and activity) but no significant relationship

(7)

was found. Part of the reason for these results is thought to be due to the effectiveness of the sentiment algorithm. Companies more sensitive to changes in consumer sentiment may have delivered results corroborating with those of Tetlock.

This thesis is organized as follows. Section 2 summarizes literature and theory that is relevant to the purpose of this study. Empirical papers which have examined similar uses of sentiment are used as a benchmark for forming the methodology. Section 3 provides an overview of the relevant data and its sources. An overview of Reddit as a source and the method of data generation is given in order to provide a context for interpretation of the results. Section 4 sets out the empirical method based on the data available and methods used by relevant literature. In section 5 the results are discussed and potential limitations are addressed. Finally the conclu-sions in relation to the impact of consumer sentiment derived from Reddit are summarized in section 6.

2

Literature and Theory

Bollen et al. (2011) as well as Tetlock (2007) were able to give content to sentiment data in relation to the stock market movements using versatile sources of sentiment data; a forum for finance professionals and Twitter. Sentiment metrics are related with abnormal returns and volume traded by means of an event study. Events are determined by large volumes of consumer comment activity. The Efficient Market Hypothesis (EMH) and behavioral finance principles are discussed for their relevance in the explanation of results as well as providing the context for supporting a causal interpretation [Fama, 1970].

Bollen et al. and Tetlock used auto-regressive distributed lag models to relate the exogenous predictor of sentiment with response variable being either returns or volume traded. Bollen et al. showed evidence

(8)

of a lead-lag relationship between sentiment and index returns. Their study focused on collecting collective mood states derived from large-scale Twitter feeds. Using two different mood tracking tools that measured 6 dimensions of mood (Calm, Alert, Sure, Vital, Kind and Happy) they were able to show increased accuracy in predicting Dow Jones Industrial Average. They used continuous data over all week days when the stock market was open. They focused particularly on ’special’ sections of time to detect the public’s response to the presidential election and Thanksgiving day in 2008. In the case of this thesis not all sentiment data is used to attribute a relationship to market behavior. Rather, days on which there was a ’special’ spike in comment activity are isolated.

Tetlock’s 2007 study on the role of media in the stock market used sen-timent which was derived from the Wall Street Journal’s “Abreast of the Market” column. Frequented by over 320,000 finance professionals it has a strong reputation with investors. Tetlock presented three main findings. Firstly, he found high levels of pessimism predict downward pressure on market prices. The pessimism measurement employed a rudimentary measurement rule by counting the number of words in each day’s column that fell within a certain word category. An additional degree of richness exists in the Reddit data used, as comments are not only analyzed for their written content but also for the number of votes that users allocated to a certain comment.

Secondly Tetlock found that unusually high or low pessimism could fore-cast higher trading volumes. Finally he found low market returns lead to more pessimism, this may be expected given that Tetlock was looking at a column frequented by finance professionals. Similarly, [Joseph et al., 2011] also used abnormal returns and trading volume and found it could be forecasted by the search intensity of online ticker searches.

(9)

Research relating stock market to sentiment measures finds its theoretical basis in behavioral economic principles. Tetlock argued most theoretical models in this space needed to make two central assumptions. The first assumption is to acknowledge the existence of two types of traders; noise traders (who act more randomly and act on new information) and rational arbitrageurs (who hold Bayesian beliefs). The second assumption being that both noise traders and rational arbitrageurs are risk averse. This links to the efficient market hypothesis (EMH) in that noise traders who experi-ence a shock in their beliefs sell or buy stock to arbitrageurs accordingly. As the response of the market is expected to be fast, the event window is more suited to be short [Fama, 1998]. The focus of the event window has also been made relatively short at up to 5 days following the event. The EMH proposes that with a perceived change in the marketability of a company’s products, the price of the stock changes. Thus the EMH underpins the fact that new information (such as consumer sentiment) moves stock prices [Fama, 1970]. Fama gave three variations for the market efficiency form; weak, semi-strong and strong. In the weak form share prices should exhibit no serial dependencies, implying that price movements are determined entirely by information not contained in the price series. In the semi-strong form, share prices incorporate information that is publicly available rapidly and in an unbiased way. The strong form of the EMH reflects ’perfect information’ available to the public. The forms provide a context from which to interpret the results. If the sentiment measured on Reddit is a useful form of new information that investors use to value a company, the market efficiency form gives context for the time taken for the new information to be integrated into the stock price.

The way in which investors react has been shown to differ systematically depending on the type of event. Exposed to new information investors can both ‘under-’ as well as ‘over- react’ depending on the type of event that oc-curs. Evidence for the tendency of people to under-react during short-term return continuations (or momentum) and longer term reversals of stock

(10)

price was found by multiple researches [Jegadeesh and Titman, 1993] [Bondt and Thaler, 1985] [Lakonishok et al., 1994]. However during an event such as an initial public offering, a tendency for the market to ‘over-react’ was found [Ritter, 1991] [Loughran and Ritter, 1995]. Thus market participants have shown to react differently depending on the event type. In this thesis events are not limited to a particular type. Rather, events are ‘filtered’ through the Reddit community daily activity. Only events that

inspired large amounts of conversation meet the event criteria.

Even though the event types are non-specified, the large amount of ac-tivity from which the event was deduced indicates a degree of consumer attention during each event. Noise traders can be more susceptible to trade on emotional rationales such as consumer sentiment. Prices can be driven away from their associated intrinsic value by the unpredictable beliefs of public or noise-investor sentiment [Black, 1976]. For example the attention and related media sentiment generated by Jim Cramer, the host of a TV show ‘Mad Money’ was shown to yield average abnormal overnight return of over 3% [Barber and Odean, 2008]. In this case it was found that investors can be ‘net-buyers’ of attention grabbing stocks. In the same vein, spikes in comment activity on Reddit are assumed to represent public ‘attention’.

The Tversky and Kahneman paper on systematic human cognitive biases in the handling of risk can explain the ‘net-buying’ of attention grabbing stocks as being due to individuals tending to overweight recent informa-tion and underweight base rate data (1973). Judgment bias of conservatism has also been used to explain behavioral slow updating of models in the face of new evidence [Fama, 1998] [Tversky and Kahneman, 1973].

Most other research conducted in the data mining vein used general-ized sentiment measures and returns such as the Dow Jones Industrial Index or the S&P500. In this thesis a more narrow approach is taken. The companies Apple, Google and Netflix have specifically been selected for

(11)

their status as being both recognized brands as well as competing in the technology sector. The effect of company specific news announcements can be pointedly different across sectors [Patton and Verardo, 2012]. As the effect of events will be assessed in combination, it is relevant that these firms belong to the same sector. Three types of return residuals were tested by[Bondt and Thaler, 1985]; Market-adjusted excess returns, market model residuals and excess returns that are measured relative to the Sharpe-Linter version of the CAPM. They found that the choice of residual did not affect their main conclusions (1985).

Apple is a technology firm with a well established, almost ’cult-like’ following of consumers. It has a large market share of around 20 % in the USA in the phone and electronics market, but faces considerable compe-tition and pressure to innovate. Its products are marketed as a stylized goods making it susceptible to changes in brand. Google is a well known brand and known for its innovative culture. Expectations for innovation from Google have pushed up it’s price to earnings ratio above 25 for much of the time between 2014-2016. 1 Similarly for Netflix, a company that provides film and series streaming services, the price to earnings ratio has remained above 80. All three companies are American (Reddit is also predominantly used by Americans) and traded on the NYSE.

The research conducted in this thesis is unique in two primary aspects. The first being that the sentiment data used has been derived from the Reddit forum. Not only are the comments analysed for their word content in similar fashion to Tetlock’s word categorization, but the up/down vote functionality of Reddit has been incorporated into the score to weight comments according to the community’s preference. Secondly the form of the analysis differs from most past literature. The sentiment uses specific selected firms similar to the search intensity paper written by Joseph et al. (2011) but rather than conducting a time series analysis (as done by Tetlock and Bollen et al.(2011)), an event study is used to determine the relevance

(12)

of spikes in consumer comment activity. Underpinned by the EMH and the reactive nature of noise traders to new information, we investigate whether Reddit activity conforms to the notion of noise traders reacting to attention grabbing stocks.

3

Data

The data used for this event study can be generally split into two parts. Firstly, the firm specific sentiment data gathered on a daily basis. Secondly, the financial data consisting of the daily returns for each firm and daily S&P index price.

3.1

Reddit as a source for sentiment

Reddit.com is commonly referred to as ‘the front page of the internet’. It is a platform through which users interact with one and other by posting diverse types of content. As of 2017, the site gets more than 542 million monthly visitors. Over the year 2015 it had 82 billion page views. Reddit ranks as the 4th most visited website in the USA and is world-wide the 9th most visited website, close to 55 percent of these users are from the US [Alexa, 2017].

The website works on the principle that interesting or agreeable posts are voted up by its users. The more up votes a post has the more visible it becomes for other users. In 2015, Reddit saw 726 million comments, and 6.89 billion upvotes from its users [Redditblog, 2015]. Interests are divided into different subjects, known as ‘sub-Reddits’. There is wide array of over a half a million sub-Reddits. One such ’sub-Reddit’ know as ’WallStreetBets’ has been described as ’the beating heart of millennial day traders’ [French and Langlois, 2016] and encapsulates the notion of noise trading.

(13)

Sentiment data was retrieved by using a data download program that ’scrapes’ the selected sub-Reddits. The collected sentiment data

com-mences on the 17th of August 2014 and runs until the 31st of March 2017. This adds up to just over 950 days of which there were 762 usable senti-ment days. 2 The raw data collected with the scraper program amounted to 340 million Reddit comments from which the sentiment was derived. Three separate sentiment scores have been generated for each day, the activity, positive sentiment, and negative sentiment. The sentiment data was calculated using a rudimentary word counting algorithm. The algo-rithm performs a search for comments that contain the specified strings: “Apple”, “Google” or “Netflix”. It then uses a positive and negative word bank 3 as reference for segregating the positive and negative sentiment score of a comment. The algorithm incorporates both the voting score users allocated to a comment as well as the sentiment of language used. 4 The summary statistics of sentiment scores are displayed in table 2. It is clear to see there is high volatility in daily sentiment scores. For example on the 6th of October 2015, an activity score of 27,698 (see appendix data extract figure 2) was registered for Apple, while two days prior on the 4th it was measured to be 1,492. It can be traced back that on the 6th of October, Apple’s competitor Microsoft announced the unveiling of a ’new chapter’ with the release of new Lumia phones, tablets and Windows 10 details. October 6th2015 was registered as an event day for the analysis as is explained further in the empirical method.

2Data scraping issues resulted in two periods of missing data. The first data break is

from the 3rdof April 2015, until the 21st of June 2015. The second data outage lasted 4 days from 15thto 18thOctober 2015.

3The word bank being the Princeton wordNet. "WordNet superficially resembles a

thesaurus, in that it groups words together based on their meanings. However, there are some important distinctions. First, WordNet interlinks not just word forms strings of letters but specific senses of words." [Miller, 1995]

(14)

3.2

Data adjustment

An adjustment is made to the sentiment scores as the stock market is not open during the weekend. Weekend sentiment is still relevant in that the Monday stock prices can reflect new information or sentiment accrued over the weekend. The sentiment scores of Saturday and Sunday are averaged together with the Monday score. The sentiment score for Monday is replaced by this average. 5 Comments posted after market closing will influence sentiment score to some degree. The event window used for the study extends both forward and backward to be able to capture preceding or latent changes in returns.

3.3

Sentiment valance

The sentiment algorithm outputs both a positive and negative sentiment. The sentiment scores are correlated to one another as given in table 1. Compared to Apple and Netflix, the negative and positive sentiment scores for Google are less correlated to the activity score. It is assumed to be due to the fact that the term ‘Google’ is more often used in a general context. To avoid multicollinearity problems the positive and negative sentiment scores are used to calculate a new measure of ’valance’ for each daily company sentiment. Thus the activity score gives a magnitude measure, while valance measures only the ‘direction’ of sentiment. The valance is calculated in two steps:

1. A fraction is made to represent the degree of positive comments (where t represents a specific day):

FracPost = PosSentt

PosSentt+NegSentt (1)

5Note that when averaging the scores there can be cases where a peak in activity is

(15)

2. Valance score is defined as the fraction of positive comments less the mean of all fractions:

Valancet = FracPost− N ∑ t=1 FracPost N (2)

Valance thus represents a scaled positive measure of the daily sentiment. It is assumed that the valence and activity measures harvested from Reddit reflect public attention and sentiment. The widespread use of Reddit and large volume of harvested comments offer support for the use of the sentiment measurements as proxy. A full inspection of the ability of the rudimentary algorithm to interpret complex comments and a framework for testing the robustness of the valence and activity measurements lies beyond the scope of this thesis. It should be noted however that a conscious decision was made when selecting which ‘sub-Reddit’ to use to extract comment data. Fig 3 lists the selected sub-Reddits used. The relevance of the selection is evident as sub-Reddits are dominated by certain topics. The selection of sub-Reddits represents a large amount of users as well as being related to the tech industry or the companies Apple, Google or Netflix. A limited number of sub-Reddits was included due to limits in time and processing power

3.4

Financial data

The time series daily stock price data of APPL, GOOGL and NFLX used, commences on 1st of January 2013 and stops on the 31st of March 2017. This data was retrieved from the Center for Research in Security Prices (CRSP). Of note was a stock split of 1998/1000 for Google’s alphabet (GOOGL) on the 3rd of April 2014. 6 Index price information for S&P 500 over the same period was retrieved from Yahoo finance.

6GOOGL stock prices were adjusted for the split by adding the price of the pre-stock

split closing price divided by the split ratio 1.998: (1135.10 / 1.998) = 568.12. This amount is added to stock prices of GOOGL from 3rdof April 2014 until March 31 2017.

(16)

4

Methodology

For the methodology definition, three primary questions have been posed. First, whether the days, surrounding events that are defined by sentiment activity spikes, occur during periods of abnormal returns. Second, whether the comment activity and valance are indicative of the magnitude and direction of the abnormal returns. Lastly we are interested in whether the valence of events is indicative of the volume traded. An event study which isolates days where there is significant public discourse regarding a firm is used. First we define what constitutes an event, next the related returns and the event window.

4.1

Defining the Event Study

An event is defined by a relative ’spike’ of comment activity on Reddit. The spike in activity signifies a day on which there is an abnormally large amount of comments containing mentions of either Apple, Google or Net-flix. Event days are assumed to reflect increased attention of the general American public for a certain company. A common problem among event studies is the uncertainty related to the exact event date. An event can be announced on news outlets, but there may be prior leakage of information [Keown and Pinkerton, 1981]. The timing of an event is determined by peaks of interest in a news story rather than a publication date. In this context there is less uncertainty when defining the event date. What the date signifies in relation to returns and volume traded will be tested. The activity score increases with community voting and commenting. The daily activity values that cross the threshold level are classified as an event. The log of each daily activity score is used to calculate the mean, standard deviation and then the standardized activity ( zact 7). Table 2

summarizes activity score data by company over the entire period

senti-7For each company the daily standardized activity score is calculated using the log of

the activity score (l Act) as followed: zt= (l Actt)−(∑

N

t=1l Actt)/N

(17)

ment data was gathered. Companies differ notably in mean activity levels, Apple has the largest mean activity (7,084) followed by Google (4,474) and Netflix (1,521). The ‘sub-Reddits’ (Fig 3) from which the comments are scraped are a likely cause of differences in mean activity level. These differences are assumed to be systematic for each company, thus the stan-dardized activity score per company is used.

Three thresh-hold levels have been used to determine an event. The zt of a given day t must be above the threshold level (Z) of either 1.5, 2.0

or 2.2 in order to register as an event. A higher threshold requires larger spikes in comment activity and thus consumer attention. However a high threshold limits the number of observations available for the estimation of the relative effect of activity and valance. Using three threshold levels provides a greater degree of reliability and context to the results. With a threshold of Z=1.5, the condition zt >Z would be expected to hold 7% of

the time for a normally distributed sample. For zt >2.0 and zt >2.2 this

would be 2.3 % and 1.4% respectively.

Figure 7 in the appendix shows the standardised activity scores over time. The graphs illustrate that events are occasionally clustered together. The response to an event can be drawn out over multiple days. An an-nouncement of a new iPhone model release on a Monday can result in large discussions volumes on Apple on both Monday and Tuesday. Adja-cent days are not interpreted to be two separate events, the first day where the threshold is crossed is used to mark the event date (Monday in our example). Events are required to be a minimum of 5 (business) days apart from one and other to uphold event independence. The number of events for each threshold and company (N) can be found in tables 4, 5 and 6. As we are interested in stock price movements that are less related to the market and more to do with the changes in perceptions related to the company, we control for the market movements using the S&P 500 index. Abnormal returns are calculated using a similar method; the OLS single

(18)

factor market model.

Returns for companies and indexes are calculated on a daily basis. The return for a company i at time t are calculated as followed;

Ri,t =

Pi,t−Pi,t−1

Pi,t−1

(3) where P is the closing price (adjusted for dividends). The returns are used in the single factor model to estimate the parameters α and β.

Ri,t =αi+βiRm,t+ei,t (4)

Rm,t is the return for the market at time t, ei,t denotes the random error

term 8. Note that α and β are estimated for each event of each company. The estimated parameters are in turn used to calculate the abnormal returns:

ARi,t = Ri,t− (αi+βiRm,t) (5)

The Cumulative Abnormal Return (CAR) for a firm, of a particular event, is a total of the abnormal returns during the event window. m : p represents the length of the event window. m=1, represents the day before the event (minus 1), and p=1 represents the day after (plus 1). Thus for the window m1:p1, the event window length is 3 days.

CARi,j =

p

t=m

ARi,t (6)

A number of event windows are used during the analysis, starting a day before the event and ranging to up to 5 days after the event date. The event window is the period where the effect of an activity spike is expected to manifest itself. Event date uncertainty is limited as spikes in activity pinpoint to a single day, the event window thus only incorporates

8For the error term we assume the conditions E[e

(19)

one day prior to the event date. Less certain is the time taken or extent to which news and changes in sentiment are incorporated into the stock price. A takeover bid for a company would need an event window that is longer than a sudden unexpected CEO death, as information dispersion of these events are different [Thompson, 1985]. Based on the literature and theory it is expected changes in sentiment (or concentrations of attention) should take effect within a short time horizon as noise traders react. Five event lengths have been used to be able to give insight into differing degrees of information dispersion and thus timing of AR.

The length of the estimation period is an important determinant of the results. MacKinlay (1997) showed that the variance of the abnormal re-turns are conditional on two parts. 9 Namely the disturbance variance

σe2 and the additional variance due to the sampling error in αi and βi. To

minimize the sampling error, the length of the estimation window (L1)

is advised to be large [MacKinlay, 1997]. Estimation periods of 252 days were used, ending 6 days before the event and starting 257 days before. A trade off is present in having to choose between a longer data sample (larger L1), but may include periods when parameters of the market model

were different (larger sampling error in αi and βi). Similar estimation

period and event window used in this thesis was used by Brown and Warner (1985) in assessing the use of event studies. The event study time frames for a single event are defined as followed:

Event day: T0

Estimation period: T−257:−6

Event windows is given as: Tm:p

9Two parts of the abnormal return variance are described as follows

σ2(ARi,t) =σe2,t+L1 1 h 1+(Rm,t− ˆµm)2 ˆσ2 m i

where ARi,t=Ri,t−αˆi−βˆiRm,tand L1the length

(20)

Where m denotes the start of the window and p the end of the win-dow, being either 1,2,3,4 or 5 days post event. Thus window length ranges from 3-7 days.

The estimation period is adjusted for the inclusion of other events. For example an event on the 7th of January would have an estimation period that ends 6 days prior; on the 1st of January and started an additional 252 (working) days before that. Without accounting for alternative events occurring during the estimation window, the estimation of the normal model parameters αt and βt would be influenced. This would influence

the normal return measure [MacKinlay, 1997]. An inherent assumption is made that the impact of an event is measured by the abnormal returns (AR). If the parameters (αt and βt) are estimated using data during which

events take place then both normal returns as well as abnormal returns would capture the event impact [MacKinlay, 1997]. Thus the parameters αi

and βi are not estimated using stock price data surrounding other events

as determined by Reddit activity. Specifically at the time of the event (T0),

stock price data is not used for one day prior until two days after (Tm1:p2).

4.2

Testing for Abnormal Returns

The first question posed is whether the events determined through online sentiment activity are related to abnormal stock price behavior. The test is repeated over event windows Tm1:p1, Tm1:p2, Tm1:p3, Tm1:p4and Tm1:p5 as well as for the three threshold levels zt >Z where Z is either 1.5, 2.0 or 2.2.

The test being whether Cumulative Average Abnormal Returns (CAAR) are significantly different from zero:

H0: CAART,Z =0

H1 : CAART,Z 6=0

There is no predetermined expected direction for the CAR of each event. The activity events are expected to induce buying or selling behavior. The

(21)

first question is not about direction of stock price change, as we are initially interested whether there are absolute abnormal returns differing from zero. The absolute CAR is used to determine the CAAR. Events determined by spikes in comment activity are interspersed with both positive and negative stock price effects. By converting the CAR into an absolute value we mitigate the problem of positive and negative events cancelling each other out when calculating the CAAR. The single factor model is not capable of controlling for all outside price movements, thus we are likely to reject this hypothesis regardless of the day chosen. However, the test will be performed on the varying threshold levels and event windows. The comparative context provided across windows and threshold levels will indicate what meaning can be given to the statistic.

To simplify the notation, the CAAR of a single event window length and threshold level is defined. Subscript i represents one of the three com-panies, and j an indicator for individual events of a fixed event window. The cross sectional t-test is defined as followed10:

|CARi,j| = p

t=m ARi,j (7) CAAR = ∑ 3 i=1∑ Ni j=1|CARi,j| ∑3 i=1(Ni) (8) The test statistic to determine the outcome of the test is calculated:

tCAAR = v u u t 3

i=1 NiCAAR SCAAR (9)

Where∑3i=1Ni represents the total number of events across all three

companies.

(22)

SCAAR denotes the standard deviation of the cumulative average

ab-normal returns for the sample:

S2CAAR = 1 (∑3i=1Ni) −1 3

i=1 Ni

j=1

(CARi,j−CAAR)2. (10)

The test has limited power as shown by Brown and Warner (1985) who found this test can be affected by event-induced volatility. Given the limited power of the cross-sectional t-test, the Wilcoxon rank sum test is additionally provided. It tests whether|ARt|for values in the event period

(t=m1 : p5), stochastically differ from the of the estimation periods ARτ =m257 : m6).

H0 : |ARt,i| 6= |ARτ,i|

The abnormal returns during both the event windows and estimation periods are ranked. The Wilcoxon test statistic is the sum of the ranks for the event window AR. 11

4.3

Regression analysis: the impact of comment valence

on Abnormal Returns and volume traded

To determine what type of economic content can be distilled from Reddit comments, we estimate abnormal returns using the Reddit sentiment data. Event days of high activity arguably contain more relevant sentiment in determining how noise traders invest. For example, the announcement of a new series to be released on Netflix would likely dominate a certain day’s discussion. Arbitrary topics concerning Netflix that may not be as indicative to Netflix company value are less likely to dominate. By this reasoning valence on event days would be more relevant. An additional point of theoretical support for using only the specified event days lies in the interpretation of the abnormal returns. On low comment activity days the stock performance of a company is less relatable to changes in

11STATA uses methodology for the conducting the test as described in Wilcoxon’s

(23)

consumer sentiment through the argument of consumer attention.

The regression made to compare valence to CAR and the volume traded is similar to that of Joseph et al. (2011). The main difference stems from the fact that this analysis uses a smaller number of firms. The controls 12 used by Joseph et al. accommodated the use of portfolios. Instead, what is used is a dummy for each firm (except for Apple, thereby avoiding the Dummy Variable Trap) to control for company characteristics. Joseph et al. found close to a monotonic relationship between search intensity and abnormal returns. They concluded search intensity could predict buying pressure. Emulating their research model, the following two regressions are used to interpret the relevance of Reddit sentiment valence:

CARi,j =α+β1Valencei,j+D.Googlei,j+D.Net f lixi,j+ei,j (11)

Secondly it is estimated whether the defined events indicate days of increased trading volume. Given sentiment may indicate an increase in the volume traded [Campbell et al., 1993], [Bradford DeLong et al., 1990]. The following model is used to test whether the events were related to an increase in trading volume :

zlVoli,j =α+β1Valencei,j+β2Activityi,j+ei,j (12)

The log of volume traded on the event day has been standardized so as to make the volumes comparable across companies.

zlVoli,j = lVoli,j− (∑

Ni j=1lVoli,j)/∑ Ni j=1 SlVoli (13) Both models are estimated using OLS with statistical software ’STATA’.

12Three controls used by Joseph et al. (2011) were: 1. Return difference between

portfolios of small and big stocks 2. Return difference between portfolios of high and low book to market stocks and 3. The return difference between a portfolio of stocks with high returns in the past year and a portfolio of stocks with low returns in the past year

(24)

5

Evaluation

The first question is whether spikes in comment activity measured on Reddit are linked to AR. Establishing that there are significant abnormal returns during the event window extends credibility to the regressions that follow; I) Testing for a relationship between the AR and the valence. II) Whether the valence of sentiment is significant in predicting volume traded during events. The results show no conclusive evidence for the significance of Reddit sentiment in explaining changes in perceptions of company value.

Three pieces of evidence are used to determine the validity of comment induced abnormal returns. 1. A graphical representation of changes in cumulative absolute returns; 2. the CAAR significance test and 3. the rank sum test comparing AR during estimation period with the AR during the event window.

The absolute Cumulative Abnormal Return (|CAR|) (Fig 1) gives a mea-sure of how the absolute CAR changed over increasing event window length. The |CAR| average of the three companies levels off as it moves away from the event date. The shape of the graphs are what one would expect from a meaningful event, however if abnormal returns are ran-domly distributed we would expect a similar shape. The error bars show substantial deviation from the mean. Increasing the threshold comment activity is possibly linked to a slight narrowing of the error bars indicating less uncertainty, but the difference is small.

Table 7 show all t-statistics for CAAR different from zero are signifi-cant. This was expected as a single factor model using the S&P500 index does not control perfectly exogenous changes in price unrelated to the Reddit sentiment. The absolute values for the CAR at any time would thus likely give a value greater than zero. It is only the relative changes in the cross sectional t-statistic of CAAR that is of interest. For events with higher

(25)

amounts of comment activity to induce more abnormal returns, we would expect to see an increase in the t-statistic as the threshold rises. However there is a slight decrease in the t-statistic. There is no clear discernible pattern in the changes due to increasing length of the event window. The results presented in table 7 imply that the CAAR is significantly different from zero, however the comparative changes do not support the proposi-tion that larger comment spikes on Reddit result in a visible increase in the magnitude of absolute abnormal returns. Additionally, as noted by past research the power of the test is not strong, as events cause increases in variance, the null hypothesis of zero average abnormal returns can be un-justly rejected [Boehmer et al., 1991] and [Seiler, 2000].

The rank sum test results in table 8 compare the sample of AR on days during the event window (m1:p5) against the population of AR during the estimation period (m257:m6)). Increasing threshold level shows that the two distributions become significantly different from one and other when the threshold is zact > 2.2. The Harrell’s c-index is also given in

table 8. It shows the probability that a randomly-chosen absolute Abnor-mal Retrun (|ARt|) of group ’event’ has a higher outcome value than a

randomly-chosen |ARτ| of group ’no-event’. For zact >2.2, a event|ARt| is only expected to be larger than a non-event |ARτ| 46.6% of the time. The probability at each threshold is slightly less than 50%. The results do not conclude that noise traders push the price away from fundamentals by reacting to a large amount of ’attention’ represented by comment activity on Reddit.

The first part of the results do not imply sentiment activity induced larger |AR|. The direction of the AR that did manifest during the event window may still have been predicted by the valence . Focusing on relative changes over increasing threshold levels and increasing window length. The results are given in table 9. None of the regressions find a significant relationship between valence and CAR. A weak argument for the rele-vance of valence may be found in the fact that all coefficients are positive.

(26)

Positive valence logically should result in a positive AR (and thus positve CAR). The significance of the constants at threshold Z=2.2 infers a positive CAR bias in the sample of 37 events (when valence is close to zero). The significance increases by lengthening the event window to m1p2 and then subsides moving toward m1p5. In the context of the EMH this could be explained by informational content present in sentiment needing time to be interpreted, which would be a supporting argument for the weak form of the EMH. This is weakly supported in column (12) of table 10 when including dummy variables for companies Google and Netflix in. The event dummies (and constant) are representative of the data, with varying combinations of window length and threshold levels, finding significance such as this may be due to randomly chance.

Finally the third question asked whether Reddit sentiment is capable of predicting volume traded. The results are given in table 11. Unlike Tet-lock we find there is no difference in volume traded that can be explained with the use of the valence measurement.

We are not able to draw the same conclusions out of the comments col-lected from Reddit as previous research was able to do from sources such as Twitter and the Wall-street journal. Fama, when discussing validity of the EMH noted that the apparent overreaction to information is about as common as under-reaction (1998). The event window used extends no longer than 5 days post event. The window only accommodates the measurement of more immediate market responses (ie. ’over-reaction’). Events are ’filtered’ based on the interests of the Reddit community. What types of events may resonate with the community has not been further researched but would be relevant for providing additional context to the results. The single factor model specification only controls for market wide movements represented in the S&P index. It is possible that there are multiple events that overlap in the defined event window which confound the results.

(27)

Tech firms that we have selected for this paper are house-hold brands with large market capitalization. Sophisticated investors invest in these companies. When there are more institutional investors who hold the stock relative to noise traders the impact of noise also becomes smaller as a result [De-Long et al., 1990]. The lack of results may stem from this ‘size effect’ that company value can have on risk-adjusted returns, as they can be inversely related [Kohers et al., 1997]. Including smaller firms into the analysis even though the comment volume would be systematically lower (thus introducing additional difficulty in sentiment extraction) would have enriched the analysis. However due to limited time and resources, the algorithm was not able to run through the 340 million collected comments for more than three companies.

Finally we must be critical of the algorithm that has been used to de-termine the sentiment values (listing 1). The rudimentary word counting process and identification of defined strings ‘Apple’, ‘Google’ and ‘Netflix’ will undoubtedly pick up a large amount of conversation that are unre-lated to perceptions of company worth. For example the term ’Google’ is also a modern day substitution for the phrase ‘search online’, such that the context of its use is broad 13. The complexity that exists in calculating a representative measure of valence from text can not be understated. Although past research has been able to establish a relationship between extreme pessimism and increased trading, the source and format of data are important factors [Tetlock, 2007].

6

Conclusion

This thesis explored the capability of consumer sentiment derived from Reddit to predict changes in stock market activity. Three distinct questions are posed to give content to the calculated sentiment. Firstly, whether increases in comment activity result in increases in abnormal stock returns.

13Relative to Apple and Netflix it was noted that the positive and negative sentiment

(28)

Secondly, whether the direction of stock returns can be predicted by com-ment valence and thirdly, if the senticom-ment valence is indicative of volume traded.

The relevance of sentiment valence is analyzed through an event study that isolates days on which there are spikes in comment activity. Abnor-mal Returns are found to be significantly different from zero during the event window. However, establishing confidence in whether these results are due to the activity measures is less certain. No significant relation-ship was discerned between the comment valence and the CAR of Apple, Google and Netflix. Based on the findings of Tetlock, the lack of results are inferred to be partially due to the selected companies being robust to changes in short term sentiment. Additionally the scores provided by the rudimentary sentiment algorithm were possibly unrepresentative of true valence. Testing whether event day trading volume was linked to the valence gave no statistically significant result.

Even with the rudimentary sentiment algorithm used, it would still be of interest for Reddit sentiment to be tested with a focus on a larger portfolio of companies over a range of market capitalization. Given the changing re-sults driven by increasing the standardized activity threshold a repetition of a similar analysis would be of particular interests over a much larger time period of gathered sentiment data.

(29)
(30)

Table 1: Correlations of sentiment scores for Apple Google and Netflix

Correlations between sentiment scores of all 762 days of sentiment data calculated.

Table 2: Summary statistics for all sentiment days

Sentiment summary statistics shown for all 762 days from 17th of August 2014 until the 31st of March 2017.

(31)

Table 3: Financial summary statistics for all incorporated financial data

(32)

Table 4: Summary sentiment statistics of event dates (threshold Z=1.5)

This Table provides the summary statistics for the event dates only. The threshold that the standardised daily sentiment activity score must cross to be defined as an event date is z>1.5.

(33)

Table 5: Summary sentiment statistics of event dates (threshold Z=2.0)

This Table provides the summary statistics for the event dates only. The threshold that the standardised daily sentiment activity score must cross to be defined as an event date is z>2.0.

(34)

Table 6: Summary sentiment statistics of event dates (threshold Z=2.2)

This Table provides the summary statistics for the event dates only. The threshold that the standardised daily sentiment activity score must cross to be defined as an event date is z>2.2.

(35)

Table 7: Results for t-test - CAAR for Abnormal Return and absolute Abnormal Return.

This table shows the t-test for whether CAAR is significantly different from zero given the event thresholds z>1,5, z>2.0 and z>2.5 for absolute CAR. For a given event window and threshold level the t-statistic calculated: tCAAR=

q ∑3

i=1NiCAARSCAAR.

(36)

Table 8: Results for Wilcoxon rank sum test - Difference of absolute AR during the event window and estimation window

Wilcoxon rank sum test repeated for the three threshold levels. The event window absolute|ARt|(m1 to p5) for all companies and

events are collected, shown by dummy event=1. Similarly for each event the|ARτ|of the estimation periods (m257:m6) have been collected, shown by dummy event=0. Number of event days|ARt|of threshold Z=2.2 is 37 (events) * 7 (m1:p5) = 259.

(37)

Table 9: Apple, Google and Netflix Regression results - Regressing valence and event dummies on the Cumulative Abnormal Returns (of increasing window length)

Regression using OLS of model: CARi,j=α+β1Valencei,j+ei,jover the events averaged for all three companies. Tm:pcorresponds to

the length of the event window, signifying number of days included past the event day; +1,+2,+3,+4 and 5 (p1, p2, p3, p4 and p5), and starting at event day -1 (m1).

(38)

Table 10: Apple, Google and Netflix Regression results - Regressing valence and event dummies on the Cumulative Abnormal Returns (of increasing window length)

Regression using OLS of model: CARi,j =α+β1Valencei,j+D.Googlei,j+D.Net f lixi,j+ei,jover the events averaged for all three

companies. Tm:pcorresponds to the length of the event window, signifying number of days included past the event day; +1,+2,+3,+4

and 5 (p1, p2, p3, p4 and p5), and starting at event day m1.

(39)

Table 11: Results for the use of valence to predict Event day trade volume

Estimated regression using OLS: ZvolT0=α+β1ValenceT0+β2ActivityT0+ei,j. ZvolT0

(40)

Figure 1: Absolute Cumulative Abnormal Returns for each threshold level for all three companies combined

Z=1.5

Z=2.0

Z=2.2

Bar chart for each threshold level Z displaying the absolute CAR for a defined event window length. The absCAR per event window of each company (i) has been averaged (for example absCART0:p1 =∑3i CARi,T0:p1.) Labels signify window length relative to the

(41)

References

[CRS, 2017] (2017). Center for Research in Security Prices. The University of Chicago Booth School of Business.

[Alexa, 2017] Alexa (2017). Reddit.com Traffic Statistics.

[Alpha, 2017] Alpha, W. (2017). Wolfram Knowledgebase. https://www.wolfram.com.

[Barber and Odean, 2008] Barber, B. M. and Odean, T. (2008). All That Glitters: The Effect of Attention and News on the Buying Behavior of Individual and Institutional Investors. The Review of Financial Studies, Vol. 21, No. 2:785–818.

[BerkFF, 1995] BerkFF, J. B. (1995). A Critique of Size-Related Anomalies. The Review of Financial Studies, Vol. 8, No. 2:275–286.

[Black, 1976] Black, F. (1976). Studies of Stock Price Volatility Changes. Proceedings of the Business and Economic Statistics, pages 177–181.

[Boehmer et al., 1991] Boehmer, E., Musumeci, J., and Poulsen, A. B. (1991). Event-study Methodology under Conditions of Event-induced Variance. Journal of Financial Economics, Vol. 31, No. 2:254–272.

[Bollen et al., 2011] Bollen, J., Mao, H., and Zeng, X. (2011). Twitter Mood Predicts the Stock Market. Journal of Computationsal Science, 2:1–8. [Bondt and Thaler, 1985] Bondt, F. and Thaler, R. (1985). Does the Stock

Market Overreact? The Journal of Finance, Vol. 40, No. 3:793–805.

[Bradford DeLong et al., 1990] Bradford DeLong, J., Shleifer, L., Summers, L. H., and Waldmann, R. (1990). Positive Feedback Investment Strategies and Destabilizing Rational Speculation. The Journal of Finance, Vol. 45 No. 2:374–1032.

(42)

[Brown and Warner, 1985] Brown, S. J. and Warner, J. (1985). Using Daily Stock Returns the Case of Event Studies. Journal of Financial Economics, Vol. 14:3–31.

[Campbell et al., 1993] Campbell, J. Y., Grossmann, S. J., and Wang, J. (1993). Trading Volume and Serial Correlation in Stock Returns. Quar-terly Journal of Economics, Vol. 108, No.4:905–939.

[De-Long et al., 1990] De-Long, J., Shleifer, A., Summers, L., and Wald-mann, R. (1990). Noise Trader Risk in Financial Markets. Journal of Political Economy, 98:703–738.

[Fama, 1970] Fama, E. F. (1970). Efficient Capital Markets: A Review of Theory and Empirical Work. The Journal of Finance, Vol. 25, No. 2:383–417.

[Fama, 1998] Fama, E. F. (1998). Market Efficiency, Long-term Returns and Behavioural Finance. Journal of Financial Economics, Vol. 49, No. 3:283–306.

[French and Langlois, 2016] French, S. and Langlois, S. (2016). Theres a loud corner of reddit where millennials look to get rich or die tryin. http://www.marketwatch.com/.

[Jegadeesh and Titman, 1993] Jegadeesh, N. and Titman, S. (1993). Re-turns to Buying Winners and Selling Losers: Implications for Stock Market Efficiency. The Journal of Finance, Vol. 48, No. 1:65–91.

[Joseph et al., 2011] Joseph, K., Wintoki, M., and Zhang, Z. (2011). Fore-casting Abnormal Stock Returns and Trading Volume using Investor Sentiment: Evidence from Online Research. International Journal of Forecasting, Vol. 27, No. 4:1116–1127.

[Keown and Pinkerton, 1981] Keown, A. J. and Pinkerton, J. M. (1981). Merger Announcements and Insider Trading Activity: An Empirical Investigation. The Journal of Finance, Vol. 36 No. 4:855–869.

(43)

[Kohers et al., 1997] Kohers, T., Pandey, V., and Kohers, G. (1997). Using Nonlinear Dynamics to Test for Market Efficiency Among the Major U.S. Stock Exchanges. The Quarterly Review of Economics and Finance, Vol. 37 No. 2:523–545.

[Kumar and Lee, 2006] Kumar, A. and Lee, C. (2006). Retail Investor Sentiment and Return Comovements. The Journal of Finance, Vol. 61 No. 5:2451–2486.

[Lakonishok et al., 1994] Lakonishok, J., Shleifer, A., and Vishny, R. (1994). Contrarian Investment, Extrapolation, and Risk. The Journal of Finance, Vol. 49, No. 5:1541–1578.

[Loughran and Ritter, 1995] Loughran, T. and Ritter, J. R. (1995). The New Issues Puzzle. The Journal of Finance, Vol. 50 No. 1:23–51.

[MacKinlay, 1997] MacKinlay, A. (1997). Event Studies in Economics and Finance. Journal of Economic Literature, 35, No 1:13–39.

[Miller, 1995] Miller, G. A. (1995). Wordnet: A Lexical Database for En-glish. Communications of the ACM, Vol. 38, No. 11:39–41.

[Muller, 2015] Muller, S. (2015). Significance Tests for Event Studies. https://www.eventstudytools.com.

[Oliveira et al., 2017] Oliveira, N., Cortez, P., and Nelson, A. (2017). The Impact of Microblogging Data for Stock Market Prediction:Using Twitter to Predict Returns, Volatility, Trading Volume and Survey Sentiment Indices. Expert Systems With Applications, 73:125–144.

[Patton and Verardo, 2012] Patton, A. and Verardo, M. (2012). Firm-Specific Information Flows and Learning about Profitability. Wiley Finance. [Redditblog, 2015] Redditblog (2015). Reddit in 2015.

https://redditblog.com.

[Ritter, 1991] Ritter, J. R. (1991). The Long Run Performance of Initial Public Offerings. Journal of Finance, Vol. 46, No. 1:3–27.

(44)

[Seiler, 2000] Seiler, J. (2000). The Efficacy of Event-study Methodologies: Measuring Ereit Abnormal Performance under Conditions of Induced Variance. Journal of Financial and Strategic Decisions, 13:101–112.

[Tetlock, 2007] Tetlock, P. (2007). Giving Content to Investor Sentiment: The Role of Media in the Stock Market. The Journal of Finance, Vol. 62, No. 3:1139–1168.

[Thompson, 1985] Thompson, R. (1985). Conditioning the Return-Generating Process on Firm-Specific Events: A Discussion of Event Study Methods. The Journal of Financial and Quanitative Analysis, 20:151– 168.

[Tversky and Kahneman, 1973] Tversky, A. and Kahneman, D. (1973). Judgement Under Uncertainty: Heuristics and Biases. Oregon research institute - Research Bulletin, 13:1–33.

[Wharton, 2017] Wharton, R. D. S. (2017). Wharton research data services. https://wrds-web.wharton.upenn.edu/wrds/.

[Wilcoxon, 1945] Wilcoxon, F. (1945). Individual Comparisons by Ranking Methods. Biometrics Bulletin, Vol. 1 No. 6:80–83.

(45)
(46)

Figure 2: Partial Data Capture of sentiment values derived from Reddit

Extract of the Reddit data that has been used to conduct the analysis. For each company three measures are used, positive negative and activity.

Figure 3: List of sub-Reddits used for sentiment data gathering

The sub-sections that exist on Reddit are known as ‘sub-Reddits’, there are overhalf a million such ‘sub Reddits’. Those selected above represent some of the most popular and relevant to the research

(47)

Figure 4: Price to earnings ratio of Apple, Google and Netflix. Apple

Google

Netflix

Graphs displaying the price to earnings ratio over time of Apple, Google and Netflix. Retrieved from Wolfram Alpha, 2017.

(48)

Figure 5: Comment activity during weekdays of the sample

Apple Google

Netflix

Graphs display the comment activity score for Apple, Google and Netflix over the cumulative weekdays. Activity measurements start

(49)

Figure 6: Negative and Positive sentiment over weekdays

Apple

Google

Netflix

Graph displaying the comment positive and negative sentiment score for Apple. Notably negative sentiment is systematically higher than positive score. Cumulative weekdays start circa 400 to accommodate stock price data buffer. Data scraping issues resulted in two periods of missing data: 1) 3rdof April 2015 until the 21st of June 2015. 2) 15thto

(50)

Figure 7: Standardized activity of Apple, Google and Netflix on weekdays

Apple

Google

Netflix

Graph displaying the standardised activity score of each company over the cumulative weekdays. Data scraping issues resulted in two periods of missing data: 1) 3rdof April 2015 until the 21st of June 2015. 2) 15thto 18thOctober 2015

(51)

Listing 1: Sentiment algorithm #! /usr/bin/env python # coding: utf-8 -*-import time import numpy as np import logging import multiprocessing as mp

from contextlib import closing

import traceback

# --- Lexicon Search

---lexicon_data =

np.genfromtxt(’../Data/Lexicons/inquirerbasic2.csv’,delimiter=’,’, dtype = str)

all_words = np.array([ x.lower() for x in lexicon_data[1:,0]],

dtype=str) #Extracts all the words from the lexicon

sentiment_search =[’Positiv’, ’Negativ’]

sent_specific_words_list = [] #List of lexicon words for each

word in sentiment_search

for sentiment_search_word in sentiment_search:

col_index_sent = np.where(lexicon_data[0,:] == sentiment_search_word)[0] sent_words = np.where(lexicon_data[1:,col_index_sent] != ’’)[0] sent_specific_words_list.append(all_words[sent_words]) info = mp.get_logger().info critical = mp.get_logger().critical

(52)

logger = mp.log_to_stderr() logger.setLevel(logging.INFO)

def main(all_comments, all_ratings, all_topics):

"""

Start up multiprocessing. """

nproc = mp.cpu_count() - 1 nproc = max(1, nproc)

all_comments_lowered = [x.lower() for x in all_comments]

all_topics_lowered = [x.lower() for x in all_topics]

del all_comments

del all_topics

ntasks = nproc * 1 #

Increase granularity of work

num_com = len(all_comments_lowered)

if num_com == 0: all_comments_lowered = [’’]*ntasks all_ratings = np.zeros(ntasks) slices_start_end = [] len_coms = [] cum_len_coms = [] cum_len_com = 0

for com in all_comments_lowered:

len_coms.append(len(com)) cum_len_com += len(com)

(53)

cum_len_coms = np.array(cum_len_coms)

step = np.ceil(cum_len_com / float(ntasks))

starts = []

for i in xrange(ntasks):

est_sta = step * i

sta = np.where(abs(cum_len_coms - est_sta) == min(abs(cum_len_coms - est_sta)))[0][0] starts.append(sta)

slices = []

for i in xrange(ntasks-1):

slices.append(slice(starts[i], starts[i+1], 1)) slices.append(slice(starts[-1], num_com, 1))

ntasks = len(slices)

split_comments = [all_comments_lowered[child_slice] for

child_slice in slices]

split_scores = [all_ratings[child_slice] for

child_slice in slices]

inputs = [(split_comments[i], split_scores[i],

all_topics_lowered, sent_specific_words_list) for i in

xrange(ntasks)]

in_q = mp.Queue()

out_q = mp.Queue()

procs = [ mp.Process(target=worker, args=(in_q, out_q)) for

i in xrange(nproc)]

for i in xrange(ntasks):

(54)

for i in xrange(nproc): in_q.put(’STOP’)

for p in procs: p.start()

activity = np.zeros((len(all_topics_lowered),), dtype=int)

num_comments = np.zeros((len(all_topics_lowered),), dtype=int)

simple_sent = np.zeros((len(sent_specific_words_list),

len(all_topics_lowered)), dtype=int)

len_comments = []

while ntasks > 0:

result = out_q.get()

activity += result[’partial_activity’]

simple_sent += result[’partial_simple_sent’]

num_comments += result[’partial_num_comments’]

len_comments.append(result[’partial_len_comments’]) ntasks -= 1

for p in procs: p.join()

main_out_dict = { ’simple_sentiment_score’:simple_sent,

’activity_score’:activity, ’len_comments’:len_comments, ’num_comments’:num_comments}

return main_out_dict

def worker(in_q, out_q):

"""

(55)

in_q is the input Queue, out_q is the output Queue. """ while True: try: tmp = in_q.get() if tmp == ’STOP’: break

child_comments, child_score, topics, sent_specific_words_list = tmp out_dict = {}

out_dict = acti_simplesent(child_comments, child_score, topics, sent_specific_words_list, out_dict)

out_q.put(out_dict)

except Exception as exception:

info(str(traceback.format_exc())) return

return

def acti_simplesent(child_comments, child_score, topics,

sent_specific_words_list, out_dict):

partial_activity = np.zeros((len(topics),), dtype=int)

partial_simple_sent = np.zeros((len(sent_specific_words_list),

len(topics)), dtype=int) partial_len_comments = 0

partial_num_comments = np.zeros((len(topics),), dtype=int)

for i in xrange(len(child_comments)): #For each comment

comment = child_comments[i]

score = child_score[i]

partial_len_comments += len(comment)

(56)

for j in xrange(len(sent_specific_words_list)): #For each type of sentiment word

sent_specific_words = sent_specific_words_list[j]

for k in xrange(len(topics)): #For each topic

topic = topics[k]

if topic in comment:

partial_activity[k] += abs(score) partial_num_comments[k] += 1

for l in xrange(len(sent_specific_words)): #For

each word in type of sentiment word sent_word = sent_specific_words[l]

if sent_word in comment:

partial_simple_sent[j,k] += score

out_dict = {’partial_activity’:partial_activity, ’partial_simple_sent’:partial_simple_sent, ’partial_len_comments’:partial_len_comments, ’partial_num_comments’:partial_num_comments}

return out_dict

---keenalytics.com, 2017 All rights reserved.

Referenties

GERELATEERDE DOCUMENTEN

In this research, the main investigated relationship is the possible impact the two different predictors (ESG pillar scores and ESG Twitter sentiment) have on the

Where the turnover ratio is measured as the absolute trading (numerator) volume divided by the number of total outstanding shares (denominator) Following Table

The influence of international soccer results on market indices for southern European Countries This table reports the estimated coefficients and the corresponding p-values of

It is, to my knowledge, the first study in this strand of research that used a second-stage dual- moderated mediation model to analyse the effects of the underlying motives

45 Nu het EHRM in deze zaak geen schending van artikel 6 lid 1 EVRM aanneemt, terwijl de nationale rechter zich niet over de evenredigheid van de sanctie had kunnen uitlaten, kan

Attack step parameters Attacker parameters Attacker skill (β) Attack step difficulty (δ) Attacker speed (τ ) Attack step labor intensity (θ) Outcome / Result Execution time..

cognitive screening instrument with a strong theoretical foundation, tested in a relatively large population of ALS patients, healthy control participants, ALS-FTD - and FTD

Verhandeling voorgele ter gedeelte1ike voldoening aan die vereistes vir die graad MAGISTER EDUCATIONIS in die Fakulteit Opvoedkunde aan die Potchefstroomse