Problem Statement:

To Analyze the voltality of Stock.

Using Technical Indicators, analyze the stock prices of Facebook, Twitter and Pinterest

To know more about Facebook, visit https://en.wikipedia.org/wiki/Facebook

To know more about Twitter, visit https://en.wikipedia.org/wiki/Twitter

To know more about Pinterest, visit https://en.wikipedia.org/wiki/Pinterest

library(quantmod)
library(TTR)
library(PerformanceAnalytics)

Downloading Facebook, Twitter and Pinterest Stocks

getSymbols("FB",src="yahoo", from="2018-07-01",to="2019-07-05")
## [1] "FB"
getSymbols("TWTR",src="yahoo", from="2018-07-01",to="2019-07-05")
## [1] "TWTR"
getSymbols("PINS",src="yahoo", from="2018-07-01",to="2019-07-05")
## [1] "PINS"

Descriptive Data Analysis

head(FB,n=6)
##            FB.Open FB.High FB.Low FB.Close FB.Volume FB.Adjusted
## 2018-07-02  193.37  197.45 192.22   197.36  13961600      197.36
## 2018-07-03  194.55  195.40 192.52   192.73  13489500      192.73
## 2018-07-05  194.74  198.65 194.03   198.45  19684200      198.45
## 2018-07-06  198.45  203.64 197.70   203.23  19740100      203.23
## 2018-07-09  204.93  205.80 202.12   204.74  18149400      204.74
## 2018-07-10  204.50  204.91 202.26   203.54  13190100      203.54
head(TWTR,n=6)
##            TWTR.Open TWTR.High TWTR.Low TWTR.Close TWTR.Volume
## 2018-07-02     43.06     45.00    42.75      44.98    16703600
## 2018-07-03     45.36     45.48    43.80      43.89    14237500
## 2018-07-05     44.07     45.11    43.55      45.06    16172000
## 2018-07-06     44.91     46.75    44.61      46.65    23740700
## 2018-07-09     46.74     46.90    42.08      44.14   107582400
## 2018-07-10     44.20     45.26    43.63      43.75    38467400
##            TWTR.Adjusted
## 2018-07-02         44.98
## 2018-07-03         43.89
## 2018-07-05         45.06
## 2018-07-06         46.65
## 2018-07-09         44.14
## 2018-07-10         43.75
head(PINS,n=6)
##            PINS.Open PINS.High PINS.Low PINS.Close PINS.Volume
## 2019-04-18     23.75     25.18   23.050      24.40    87109500
## 2019-04-22     24.62     25.68   23.570      24.99    19746800
## 2019-04-23     25.38     27.75   25.230      25.85    19245400
## 2019-04-24     26.50     27.03   25.933      26.80     9477200
## 2019-04-25     27.45     29.40   26.670      28.80    16648300
## 2019-04-26     29.84     30.68   28.370      29.85    16825600
##            PINS.Adjusted
## 2019-04-18         24.40
## 2019-04-22         24.99
## 2019-04-23         25.85
## 2019-04-24         26.80
## 2019-04-25         28.80
## 2019-04-26         29.85

Let’s summarize the data

summary(FB)
##      Index               FB.Open         FB.High          FB.Low     
##  Min.   :2018-07-02   Min.   :123.1   Min.   :129.7   Min.   :123.0  
##  1st Qu.:2018-10-01   1st Qu.:151.5   1st Qu.:154.1   1st Qu.:149.0  
##  Median :2019-01-02   Median :167.2   Median :168.9   Median :164.8  
##  Mean   :2018-12-31   Mean   :167.2   Mean   :169.4   Mean   :165.3  
##  3rd Qu.:2019-04-03   3rd Qu.:180.4   3rd Qu.:182.0   3rd Qu.:178.4  
##  Max.   :2019-07-03   Max.   :215.7   Max.   :218.6   Max.   :214.3  
##     FB.Close       FB.Volume          FB.Adjusted   
##  Min.   :124.1   Min.   :  7297400   Min.   :124.1  
##  1st Qu.:151.4   1st Qu.: 14843300   1st Qu.:151.4  
##  Median :166.9   Median : 19641300   Median :166.9  
##  Mean   :167.3   Mean   : 22696363   Mean   :167.3  
##  3rd Qu.:180.7   3rd Qu.: 25469700   3rd Qu.:180.7  
##  Max.   :217.5   Max.   :169803700   Max.   :217.5
summary(TWTR)
##      Index              TWTR.Open       TWTR.High        TWTR.Low    
##  Min.   :2018-07-02   Min.   :26.35   Min.   :27.27   Min.   :26.19  
##  1st Qu.:2018-10-01   1st Qu.:31.15   1st Qu.:31.55   1st Qu.:30.60  
##  Median :2019-01-02   Median :33.00   Median :33.69   Median :32.45  
##  Mean   :2018-12-31   Mean   :33.85   Mean   :34.46   Mean   :33.24  
##  3rd Qu.:2019-04-03   3rd Qu.:35.98   3rd Qu.:36.49   3rd Qu.:35.05  
##  Max.   :2019-07-03   Max.   :46.74   Max.   :46.90   Max.   :44.61  
##    TWTR.Close     TWTR.Volume        TWTR.Adjusted  
##  Min.   :26.45   Min.   :  5372600   Min.   :26.45  
##  1st Qu.:31.06   1st Qu.: 13548200   1st Qu.:31.06  
##  Median :32.98   Median : 17714400   Median :32.98  
##  Mean   :33.83   Mean   : 21297572   Mean   :33.83  
##  3rd Qu.:35.89   3rd Qu.: 23994800   3rd Qu.:35.89  
##  Max.   :46.65   Max.   :122752800   Max.   :46.65
summary(PINS)
##      Index              PINS.Open       PINS.High        PINS.Low    
##  Min.   :2019-04-18   Min.   :23.75   Min.   :24.33   Min.   :23.05  
##  1st Qu.:2019-05-08   1st Qu.:25.65   1st Qu.:26.55   1st Qu.:25.30  
##  Median :2019-05-28   Median :27.29   Median :27.96   Median :26.44  
##  Mean   :2019-05-26   Mean   :27.31   Mean   :28.13   Mean   :26.47  
##  3rd Qu.:2019-06-14   3rd Qu.:28.84   3rd Qu.:29.26   3rd Qu.:27.56  
##  Max.   :2019-07-03   Max.   :35.20   Max.   :35.29   Max.   :30.53  
##    PINS.Close     PINS.Volume       PINS.Adjusted  
##  Min.   :23.80   Min.   : 1629500   Min.   :23.80  
##  1st Qu.:25.81   1st Qu.: 3242900   1st Qu.:25.81  
##  Median :27.05   Median : 5709000   Median :27.05  
##  Mean   :27.30   Mean   : 9424802   Mean   :27.30  
##  3rd Qu.:28.69   3rd Qu.: 9477200   3rd Qu.:28.69  
##  Max.   :34.26   Max.   :87109500   Max.   :34.26

Exploratory Data Analysis

plot(FB)

This plot shows the line chart of Facebook. There was a spike in Aug’2018. Gradually, it maintains it momentum and stabilize.

plot(TWTR)

Twitter line chart shows huge potential as in every other quarter, stock price increases for a period.

plot(PINS)

Pinterest line chart shows gradual decreases in stock price with time.

Technical Analysis Chart

lineChart(FB,theme = chartTheme("black"))

barChart(FB,theme = chartTheme("black"))

candleChart(FB,theme = chartTheme("black"))

chartSeries(FB,theme = "black")

Above charts are line chart, bar chart, candle chart and chart series respectively. A bar chart shows the collection of price bars over time. A candle chart signifies the price ovement for each day.

lineChart(TWTR,theme = chartTheme("black"))

barChart(TWTR,theme = chartTheme("black"))

candleChart(TWTR,theme = chartTheme("black"))

chartSeries(TWTR,theme = "black")

lineChart(PINS,theme = chartTheme("black"))

barChart(PINS,theme = chartTheme("black"))

candleChart(PINS,theme = chartTheme("black"))

chartSeries(PINS,theme = "black")

#Stock Technical Indicators

1. Lagging Stock technical indicators

Moving Averages, Simple Moving Average(5,21) days , Exponential Moving Average

Simple Moving Average

barChart(FB,theme=chartTheme("white"))

addSMA(n=5,col="darkblue")

addSMA(n=21,col="darkred")
legend("bottomright",col=c("darkblue","darkred"),lty=1,legend = c("SMA(5)","SMA(21)"),cex=0.6)

SMA defines the price trends w.r.t 5 days average and 21 days average. There seems facebook price movements close to 5 days trends.

barChart(TWTR,theme=chartTheme("white"))

addSMA(n=5,col="darkblue")

addSMA(n=21,col="darkred")
legend("bottomright",col=c("darkblue","darkred"),lty=1,legend = c("SMA(5)","SMA(21)"),cex=0.6)

There seems twitter price movements are also close to 5 days trends.

barChart(PINS,theme=chartTheme("white"))

addSMA(n=5,col="darkblue")

addSMA(n=21,col="darkred")
legend("bottomright",col=c("darkblue","darkred"),lty=1,legend = c("SMA(5)","SMA(21)"),cex=0.6)

Here, also Pinterest trend similar to other two social media companies. Quiet close to 5 days price movements.

Exponential Moving Average

barChart(FB,theme=chartTheme("white"))

addEMA(n=5,col="darkblue")

addEMA(n=21,col="darkred")
legend("bottomright",col=c("darkblue","darkred"),lty=1,legend = c("EMA(5)","EMA(21)"),cex=0.6)

Exponential MA is much better in representing trend then Simple MA. When it comes to facebook trends.

barChart(TWTR,theme=chartTheme("white"))

addEMA(n=5,col="darkblue")

addEMA(n=21,col="darkred")
legend("bottomright",col=c("darkblue","darkred"),lty=1,legend = c("EMA(5)","EMA(21)"),cex=0.6)

It seems Twitter price movement clearly explains by SMA instead of EMA. As, EMA shows a drift and not clear movements.

barChart(PINS,theme=chartTheme("white"))

addEMA(n=5,col="darkblue")

addEMA(n=21,col="darkred")
legend("bottomright",col=c("darkblue","darkred"),lty=1,legend = c("EMA(5)","EMA(21)"),cex=0.6)

Here, EMA shows price movements in much better way than SMA. [EMA 5 days]

Bollinger Bands BB(20 days,stdev = 2)

barChart(FB, theme=chartTheme("white"))

addBBands(n=20,sd=2)

barChart(TWTR, theme=chartTheme("white"))

addBBands(n=20,sd=2)

barChart(PINS, theme=chartTheme("white"))

addBBands(n=20,sd=2)

Bollinger Bands defines statiscal price movements i.e within 20 days and 2 standard deviation.

On comparing Facebook, Twitter and Pinterest Charts then facebook stock price will gradually go down which shows the positive time for buying stocks.While, twitter and Pinterest shows potential in rise in stock price. Facebook Price Range between 190- 150$ Twitter Price Range between 35-42$ Pinterest Price Range between 23-29$

Parabolic Stop and Reverse SAR(increments of 0.02,max acceleration is 0.2)

barChart(FB, theme=chartTheme("white"))

addSAR(accel = c(0.02,0.2))

barChart(TWTR, theme=chartTheme("white"))

addSAR(accel = c(0.02,0.2))

barChart(PINS, theme=chartTheme("white"))

addSAR(accel = c(0.02,0.2))

The reverse stock price trends in facebook shows upward trend. Twitter shows it downside. While that of Pinterest in much of stability.

2. Leading Stock technical indicators

Average Directional Movement Index(ADX)(14 days)

barChart(FB, theme=chartTheme("white"))

addADX(n=14)
legend("right",col=c("blue","green","red"),lty=1,legend = c("ADX(14)","DI(14)+","DI(14)-"),cex=0.6)

barChart(TWTR, theme=chartTheme("white"))

addADX(n=14)
legend("right",col=c("blue","green","red"),lty=1,legend = c("ADX(14)","DI(14)+","DI(14)-"),cex=0.6)

barChart(PINS, theme=chartTheme("white"))

addADX(n=14)
legend("right",col=c("blue","green","red"),lty=1,legend = c("ADX(14)","DI(14)+","DI(14)-"),cex=0.6)

This index shows the strength and movement of trend. Facebook currently shows its upward trend but it at its peak. There is a high changes to its movement. Twitter shows downward trend. This will continue for while or as per past history, it will maintain this momentum till July’2019 end. Pinterest maintain its momentum. And shows stability but this will not last for long. After 15 days, there will be change in movement.

Commodity Channel Index(20 days, constant parameter 0.015)

barChart(FB, theme=chartTheme("white"))

addCCI(n=20,c=0.015)

barChart(TWTR, theme=chartTheme("white"))

addCCI(n=20,c=0.015)

barChart(PINS, theme=chartTheme("white"))

addCCI(n=20,c=0.015)

This index signifies the stock price variation. Here, Facebook shows in past 1 year, overall performance is low. After Feb’2019, it took the momentum but that didn’t last more than 3 months. Again, it starts degrading its performance. Twitter showed positive momentum in past 1 year. Now, its playing safely since 2 months. Pinterest 2 quarters data donot define much about it potential. But definitely showing positive result so far. But, now it will gradually decreases with time.

Moving Averages Convergence/Divergence(12 days short term smoothing, 26 days long term smoothing, 9 days for signals)

barChart(FB, theme=chartTheme("white"))

addMACD(fast = 12, slow = 26,signal = 9)

barChart(TWTR, theme=chartTheme("white"))

addMACD(fast = 12, slow = 26,signal = 9)

barChart(PINS, theme=chartTheme("white"))

addMACD(fast = 12, slow = 26,signal = 9)

This index defines stock price momentum and trends. Facebook trends shows positive momentum as per past history. Twitter shows downward trend strongly. While that of Pinterest also shows down trend.

Rate of Change ROC(21 days per month)

barChart(FB, theme=chartTheme("white"))

addROC(n=21)
legend("right",col="red",lty=1,legend = "ROC(21)",cex=0.6)

barChart(TWTR, theme=chartTheme("white"))

addROC(n=21)
legend("right",col="red",lty=1,legend = "ROC(21)",cex=0.6)

barChart(PINS, theme=chartTheme("white"))

addROC(n=21)
legend("right",col="red",lty=1,legend = "ROC(21)",cex=0.6)

This index reflects the speed of change in price movement. Facebook shows change in price speed positive in terms of up trend and that of negative trend as well. This means change is little slow. Twitter shows down trend much fast then up trend. Pinterest shows uptrend in much fatser speed then downtrend.

Relative Strength Index RSI(14)

barChart(FB, theme=chartTheme("white"))

addRSI(n=14)

barChart(TWTR, theme=chartTheme("white"))

addRSI(n=14)

barChart(PINS, theme=chartTheme("white"))

addRSI(n=14)

This index shows trend strength or waekness. Facebook trend is strong to approx. 70% Twitter trend strength is approx 50%. This will not last for long. Pinterest trend strength is approx 54%.

Stochastic momentum index SMI(13,2,25,9)

barChart(FB, theme=chartTheme("white"))

addSMI(n=13,fast = 2,slow = 25,signal = 9)

barChart(TWTR, theme=chartTheme("white"))

addSMI(n=13,fast = 2,slow = 25,signal = 9)

barChart(PINS, theme=chartTheme("white"))

addSMI(n=13,fast = 2,slow = 25,signal = 9)

This index compares with past 13 days momentum. Facebook trend shows present trend depends on almost 40% of momentum over past history. Twitter trend shows present trend does not deflect the past history. Pinterest trends reflects the same.

Williams %R(14)

barChart(FB, theme=chartTheme("white"))

addWPR(n=14)

barChart(TWTR, theme=chartTheme("white"))

addWPR(n=14)

barChart(PINS, theme=chartTheme("white"))

addWPR(n=14)

This index compares the trend to its maximum high in last 14 days momentum. Facebook trends shows hardly 8% of trend w.r.t the max high trend. Twitter shows approx 46% of trend w.r.t to its high trend. Pinterest shows approx 59% of trend w.r.t to its high trend.

** These above are the technical indicators used to analyze stocks and its volatality.

Conclusion

  1. For this technical indicators, it seems Facebook stock price will go down in upcoming weeks by 10-12$.
  2. Twitter stock price will increase within next 15 days.
  3. Pinterest stock price will maintain its momentum but in next 15 days, stock prices will move down.

Facebook performance in stock market will leverage in Q4’2019. Twitter depends on some other factors, stock market performance will not last long. But will be at steady pace. Pinterest stock market shows high potential in upcoming quarter for investment based on past history.