On the 2nd of Jan 2019 Apple issued its first profit warning in 16 years. Under estimating the magnitude of the economic slow down in China was the reason for lower iphone sales and the subsequent profit warning.
In this analysis I text mine the minutes of the Reserve Bank of Australia's monetary meetings to see if there was a change in sentiment about international economic conditions before the announcement from Apple
Generative AI on Enterprise Cloud with NiFi and Milvus
Sentiment Analysis - Reserve Bank Monetary Policy Meetings
1. Sentiment Analysis
Johann Krugell
9 January 2019
Overview
On the 2nd of Jan 2019 Apple issued its first profit warning in 16 years. Underestimating the magnitude of
the economic slowdown in China was the reason for lower iphone sales and the subsequent profit warning.
There is often a lag in the availability of Economic data which means that the sentiment and underlying
financials does not correspond. In Apple’s case the sentiment may have been that sales growth was on track
and the economic conditions was supportive but the reality was that economic conditions were changing.
I wonder if there was earlier signs of a possible change in sentiment?
The Reserve Bank of Australia (RBA) publishes the minutes of its monetary policy meetings online I want to
analyse the Reserve Bank’s sentiment during 2018, ,to determine if there was an earlier change in sentiment
regarding international economic conditions (https://www.rba.gov.au/monetary-policy/rba-board-minutes/
2018/).
Sentiment analysis
Sentiment analysis is the process of grouping and analysing pieces of text to determine the writers sentiment.
Positive or negative sentiment for example. The process can also be referred to as text mining.
Sentiment analysis in R
The basic process to do sentiment analysis in R is as follows:
• data - you need text data to analyse, in this case RBA meeting minutes
• tidy - tidy the text to have a list of words, single column each word separately
• sentiment lexicon - join the list of words with a sentiment lexicon that would identify the sentiment
of each word
• visualize - visualize the result
Data
I copied the section of text related to international economic conditions into Notepad and imported it into R
using the readtsv function.
int_econ_cond_apr = read_tsv("int_econ_cond_apr.txt",col_names = FALSE)
I want to analyse the sentiment changes over time so at the time of importing I add the date of the meeting
int_econ_cond_apr <- mutate(int_econ_cond_apr, speech_date = as.Date("2018-04-03"))
The resulting data is a tibble with 4 rows and 2 columns
## Classes 'tbl_df', 'tbl' and 'data.frame': 4 obs. of 2 variables:
## $ X1 : chr "As a backdrop to their discussion on international economic conditions, members
## $ speech_date: Date, format: "2018-04-03" "2018-04-03" ...
1
2. I repeat the import process for all months and then combine the data sets into one tibble that I can use
together with the sentiment lexicon. The result is a tibble with 46 rows and two columns
## Classes 'tbl_df', 'tbl' and 'data.frame': 60 obs. of 2 variables:
## $ X1 : chr "Members commenced their discussion of the global economy by noting that GDP gro
## $ speech_date: Date, format: "2018-10-02" "2018-10-02" ...
Tidy
Once all the data has been collected it needs to be tidy. Each row of text in the data it should be split into
one row for each word. You want to see two columns with one row for each word
You can move each word in the row to its own row using the unnest function.
sentiment <- unnest_tokens(int_econ_cond_combined, word, X1)
The result is a data frame with two columns, word and speech date, a total of 6,958 observations
## Classes 'tbl_df', 'tbl' and 'data.frame': 6958 obs. of 2 variables:
## $ speech_date: Date, format: "2018-10-02" "2018-10-02" ...
## $ word : chr "members" "commenced" "their" "discussion" ...
Sentiment Lexicon
The next step is to join your data frame with a sentiment lexicon. A lexicon is a set of meaningful units in a
language. We will be using the nrc lexicon.
I can join this lexicon to my data frame using the innerjoin function
inner_join(sentiment, get_sentiments("nrc"), by = "word")
## # A tibble: 1,497 x 3
## speech_date word sentiment
## <date> <chr> <chr>
## 1 2018-10-02 discussion positive
## 2 2018-10-02 economy trust
## 3 2018-10-02 growth positive
## 4 2018-10-02 trend positive
## 5 2018-10-02 timely positive
## 6 2018-10-02 growth positive
## 7 2018-10-02 expected anticipation
## 8 2018-10-02 solid positive
## 9 2018-10-02 noted positive
## 10 2018-10-02 trade trust
## # ... with 1,487 more rows
Now you will see for each word in the speech and the corresponding sentiment of that word in a separate
column.
I add some additional columns to count the number of occurrences of a positive or negative sentiment. My
data frame now looks as follows
## # A tibble: 859 x 7
## # Groups: sentiment, speech_date [107]
## word sentiment speech_date n total percent date
## <chr> <chr> <date> <int> <int> <dbl> <date>
## 1 absorbed positive 2018-09-04 2 86 0.0233 2018-09-01
## 2 advanced positive 2018-09-04 2 86 0.0233 2018-09-01
## 3 agreement positive 2018-09-04 1 86 0.0116 2018-09-01
## 4 content positive 2018-09-04 1 86 0.0116 2018-09-01
2
3. ## 5 contribute positive 2018-09-04 1 86 0.0116 2018-09-01
## 6 core positive 2018-09-04 2 86 0.0233 2018-09-01
## 7 discussion positive 2018-09-04 1 86 0.0116 2018-09-01
## 8 encouragement positive 2018-09-04 1 86 0.0116 2018-09-01
## 9 growth positive 2018-09-04 21 86 0.244 2018-09-01
## 10 including positive 2018-09-04 3 86 0.0349 2018-09-01
## # ... with 849 more rows
Visualize
The last step is to visualize the result. I can see that overall the sentiment has be significantly more positive
than negative. However from Sep onwards there is a change in positive sentiment.
25
50
75
Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Meeting month
TotalObservations
sentiment negative positive
RBA monetary meetings sentiment − positive/negative
The decrease in positive sentiment has not been accompanied by and increase in negative sentiment. If I plot
positive sentiment together with surprise sentiment, this change in sentiment seems to be accompanied by an
increase in words with a sentiment of surprise.
3
4. 0.0
0.5
1.0
1.5
2.0
Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Meeting month
Countofsentiment
sentiment positive surprise
RBA monetary meetings sentiment − positive/surprise
4