Use the given code below to answer the questions.
Hint: Insert a new code chunk below and type in the code, using the tq_get() function above. Replace the ticker symbol for Walmart. You may find the ticker symbol for Microsoft from Yahoo Finance.
## Load package
library(tidyverse) # for cleaning, plotting, etc
library(tidyquant) # for financial analysis
## Import data
stocks <- tq_get("WMT.MX", get = "stock.prices", from = "2016-01-01")
stocks
## # A tibble: 1,025 x 7
## date open high low close volume adjusted
## <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2016-01-04 1054. 1054. 1053 1053 126 1048.
## 2 2016-01-05 1065. 1092. 1065. 1091 1081 1085.
## 3 2016-01-06 1108. 1109. 1108. 1109. 1023 1104.
## 4 2016-01-07 1118. 1153. 1118. 1153. 7220 1147.
## 5 2016-01-08 1170 1172 1165 1165 573 1159.
## 6 2016-01-11 1165 1172 1147 1147 1104 1141.
## 7 2016-01-12 1143 1150 1142 1150 6405 1144.
## 8 2016-01-13 1130 1130 1130. 1130. 564 1124.
## 9 2016-01-14 1130 1130 1130 1130 30 1124.
## 10 2016-01-15 1121. 1121. 1121. 1121. 2460 1115.
## # … with 1,015 more rows
7 columns
The stock keeps going up from 01/04/16 to 01/15/16 67 times to be exact.
Hint: Watch the video, “Basic Data Types”, in DataCamp: Introduction to R for Finance: Ch1 The Basics.
Walmart has numeric data and the other kinds include logical and character.
Hint: Insert a new code chunk below and type in the code, using the ggplot() function above. Revise the code so that it maps adjusted to the y-axis, instead of close.
## Visualize
stocks %>%
ggplot(aes(x = date, y = adjusted)) +
geom_line()
For more information on the ggplot() function, refer to Ch2 Introduction to ggplot2 in one of our e-textbooks, Data Visualization with R.
Walmarts stock has been going up with a few drops here and there in their stock but they are mostly going in a upward slope.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.
Hint: Use eval in the chunk option. Refer to the RMarkdown Reference Guide.