Analyzing Correlations Between #BTC Tweets & Bitcoin Trading Using Natural Language Processing

Swede White—Wolfram Research

@swedewhite 			#WolframTechConf

ABSTRACT

Since their inception, social media websites and apps have become an increasingly valuable resource for taking the pulse of societal discourse and rhetoric.

In particular, Twitter has become a centralized source for real-time news aggregation as traditional media publications have achieved digital transformation into 24/7 news cycle mediums.

Running in parallel to changes in media distribution and consumption is the rise of cryptocurrencies such as Bitcoin and associated trading markets.

In this talk, we will use natural language processing and time series analysis to examine correlations between sentiment of tweets containing the hashtag #BTC and Bitcoin trading activity.

INTRODUCTION

Legitimizing Social Media Research

Research using data from social media has become more mainstream in the social sciences, though has been a common data source for marketing, advertising, and PR for quite some time now.

Criticisms of social media research mostly center around sampling issues—samples are not random or representative of the population at hand.

Further criticisms expand criticisms of representation by pointing out that many do not have access to the internet to begin with.

Due to this, Caution should be used when generalizing findings from social media data to a larger population.

INTRODUCTION

Cryptocurrencies

Since the anonymous figure Satoshi Nakamoto released a white paper outlining blockchain technology and the cryptocurrency Bitcoin, interest has grown in how decentralized currency and transaction ledgers could be used to disrupt everything from banking to the internet itself.

Several cryptocurrencies and tokens have proliferated, especially in recent years.

Some claim so-called whales who hold large amounts of cryptocurrency engage in market manipulation and speculation in pump and dump schemes.

INTRODUCTION

NATURAL LANGUAGE PROCESSING

Textual data can be messy, as it is unstructured and difficult to wrangle, as opposed to something like tabular data in a spreadsheet.

Wolfram Language has many  built-in functions for natural language processing, some new in Version 12, that make the task of cleaning, sorting, and analyzing text less arduous than other languages and platforms.

This should be of no surprise given the success of Wolfram|Alpha and its ability to parse natural language queries and return computed results.

INTRODUCTION

RAPID PROTOTYPING

For our purposes today, we will explore how Wolfram Language can be used for rapid prototyping with quick data import, text processing, sentiment classification, and visualization to test hypotheses and/or confirm existing research looking at cryptocurrency prices and tweet sentiment.

Wolfram Language is also well-suite for rapidly prototyping and deploying all sorts of software solutions beyond hypothesis testing and modeling.

All claims in this presentation are purely for demonstration purposes and are not to be taken as trading advice.

DATA COLLECTION

Twitter

#BTC tweets

To keep things simple in this exploration, we choose a common hashtag used in Bitcoin tweets as they relate to price.

Twitter API using ServiceConnect[]

Due to limitations of calls to Twitter’s API

Twitter API firehose

“Entry level data sets include up to 1 million Tweets over a 40 day period and start at $1,250.  Pricing is inelastic until either threshold is exceeded.  Price is impacted by both the time frame and Tweet payload size.” —Twitter Rep

DATA COLLECTION

wolfram data drop

DATA COLLECTION

ifttt

Tweets that contain “#BTC” have been collected in a databin since June 8, 2018. Retweet and like data are unavailable due to the nature of collection, and we are collecting only a sample of tweets containing our hashtag. For the purposes of this analysis, we are most interested in tweet text and timestamp.

DATA PROCESSING—tweets

Import from databin

btcBin=Databin["vdObVe5w"]

create a dataset & INSPECT

btcTweets=btcBin[All,"tweet"]//Dataset

define text & time

time=btcTweets[All,"Timestamp"]//Normal;

text=btcTweets[All,"tweet"]//Normal;

data processing—bitcoin price

WOLFRAM|ALPHA

Wolfram|Alpha has data on Bitcoin, currency conversions, etc. with more data available in Wolfram Language.

WolframAlpha["bitcoin price",{{"History",1},"Content"}]

We’ve gathered data at a more granular level from a third-party with hourly data.

dataH=Import["/Users/swedew/Dropbox (Wolfram)/WTC/2018/BTC Talk/FinalPrez/BTCPricesVolume101718.csv"];

dataH//Dimensions

define time, price & VOLUME

dateH=dataH[[All,1]];

priceH=dataH[[All,2]];

volumeH=dataH[[All,3]];

text processing

Wolfram Language has several options for breaking up chunks of text to various levels, e.g. paragraph, sentence, word, letter, etc. Since we are interested in the sentiment of each tweet, we will first run sentiment analysis across the entirety of the tweets and compare cleaned up text later.

clean up text

FilterTweets[tweets_]:=StringDelete[tweets,
{"https://",
"http://",
"rt:",
"RT"
}];

cleanText=FilterTweets[DeleteStopwords@text];

sentiment ANALYSIS

Wolfram Language by default returns values of “Positive,” “Negative,” and “Neutral” (or Indeterminate) when using the built-in sentiment classifier. We will have our data return our sentiment polarity as numerical values {-1, 0, 1}.

built-in sentiment classifier

sentiment=ReplaceAll[
Classify[
"Sentiment",
text],
{
"Positive"->1,
"Negative"->-1,
"Neutral"|Indeterminate->0
}];

quickly visualize the data

tallied=Transpose@Tally@sentiment;
BarChart[tallied[[2]],
ChartLabels->Placed[{
"Negative",
"Positive",
"Neutral"},
Above]]

time series of #BTC tweet sentiment

We create a time series object out of sentiment scores and time values.

ts=TimeSeries[sentiment,{time}]

plotting

We first define a style we’ll be using for our charts.

style={PlotRange->All,
Filling->Axis,
Joined->False,
Frame->False,
PlotStyle->96,
Background->GrayLevel[.3]};

We apply MeanFilter to smooth out the time series and identify a trend. We here use 1 day and 1 hour intervals to compare.

sentPlot1=DateListPlot[{
MeanFilter[ts,(Quantity[1, "h", hours, "Hours"])],
MeanFilter[ts,(Quantity[1, "day", days, "Days"])]},
ImageSize->Large]

time series of BITCOIN PRICE

We first define time series for price and volume before plotting.

tsP=TimeSeries[priceH,{dateH}];

tsV=TimeSeries[volumeH,{dateH}];

tsPPlot1=DateListPlot[tsP,
ImageSize->Large]

rescale sentiment and combine plots

sentimentScaled=ReplaceAll[
Classify[
"Sentiment",
text
],
{
"Positive"->10000,
"Negative"->2000,
"Neutral"|Indeterminate->6000
}
];

tsScaled=TimeSeries[sentimentScaled,{time}];

filtered=MeanFilter[tsScaled,(Quantity[1, "day", days, "Days"])];

DateListPlot[
{filtered,tsP,tsV},
DataRange->{2000,10000},
PlotRange->All,
Frame->False,
PlotLegends->
{"Scaled Sentiment Score","Bitcoin Price","Bitcoin Volume"},
PlotLabel->"#BTC Twitter Sentiment and Bitcoin Value",
DateTicksFormat->
{"MonthShort","/","Day"},
Joined->{True,True,False},
Filling->{3->Axis},
PlotStyle->96,
ImageSize->Large]

conclusion

We’ve been able to quickly prototype a time series with natrual language processing to see if there’s something worth exploring further.

We could take things further by gathering complete Twitter data with more search terms.

We can also identify influential accounts on Twitter with search terms and network analysis.

We could also create time series models to examine exact correlation values between our sentiment and bitcoin price.

questions?

Connect

@swedewhite
linkedin.com/my/swedewhite
swedew@wolfram.com