This assignment requires a web page presentation with a plot created with Plotly. The outcome report should be hosted on either Github Pages, RPubs, or NeoCities. The page should contain the data used to created the document and also a plot. Moreover, the report should fit the following review criteria:
There are two main stock market indices in USA, the Dow Jones Industrial Average Index and the NASDAQ Composite Index. They have deep influence on not only the domestic financial market and also the global market. Starting from 2006, both of them have experienced several waves of fluctuation due to various financial events. Here I presents the trends of these two indices.
The data is downloaded from the Thomas Routers Datastream database. The time horizon of these two datasets are 02/01/2006 to 07/01/2020, while the time frequency is daily. In the following section, a plot of indices price will be provided for the presentation of the indices trends.
In this section, I shall present the plot processing procedure.
First, it comes to the data pre-processing. The code is as follows.
library(readxl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
DJI <- read_excel("Price History.xlsx",
col_types = c("date","numeric","numeric","numeric"
,"numeric","numeric","numeric","numeric"))
NAS <- read_excel("Price History_20200713_1152.xlsx",
col_types = c("date","numeric","numeric","numeric"
,"numeric","numeric","numeric","numeric"))
price_index_DJI <- DJI%>%select(`Exchange Date`,Close)
price_index_NAS <- NAS%>%select(`Exchange Date`,Close)
price_index <- merge(price_index_DJI,price_index_NAS,by="Exchange Date")
price_index <- price_index%>%rename(Nasdaq=Close.x,DJI=Close.y)
head(price_index)
## Exchange Date Nasdaq DJI
## 1 2006-02-01 10953.95 2310.56
## 2 2006-02-02 10851.98 2281.57
## 3 2006-02-03 10793.62 2262.58
## 4 2006-02-06 10798.27 2258.80
## 5 2006-02-07 10749.76 2244.96
## 6 2006-02-08 10858.62 2266.98
change_index <- merge(DJI%>%select(`Exchange Date`,`%Chg`),
NAS%>%select(`Exchange Date`,`%Chg`),by="Exchange Date")
change_index <- change_index%>%rename(Nasdaq=`%Chg.x`,DJI=`%Chg.y`)
head(change_index)
## Exchange Date Nasdaq DJI
## 1 2006-02-01 NA NA
## 2 2006-02-02 -0.0093089707 -0.012546742
## 3 2006-02-03 -0.0053778205 -0.008323216
## 4 2006-02-06 0.0004308101 -0.001670659
## 5 2006-02-07 -0.0044923863 -0.006127147
## 6 2006-02-08 0.0101267377 0.009808638
With the upper codes,the data is processed into the proper format. Then, it goes to the plotting procedure.
plot_1 <- plot_ly(price_index,x=~price_index$`Exchange Date`,y=~price_index$Nasdaq,
type = 'scatter',mode='lines',name = 'Nasdaq Index')
plot_1 <- plot_1%>%add_trace(y=~price_index$DJI,name='Dow Jones Index',mode='lines+markers')
plot_1 <- plot_1%>%layout(title="The trends of two stock indices",
yaxis=list(title="Index Price"),
xaxis=list(title="Date"))
plot_1
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
plot_2 <- plot_ly(change_index,x=~change_index$`Exchange Date`,
y=~change_index$Nasdaq,type = 'scatter',mode='lines',
name = 'Nasdaq volatility')
plot_2 <- plot_2%>%add_trace(y=~change_index$DJI,name='Dow Jones volatility',mode='lines+markers')
plot_2 <- plot_2%>%layout(title="The volatility of two stock indices",
yaxis=list(title="Volatility Rate"),
xaxis=list(title="Date"))
plot_2