Use the given code below to answer the questions.
## Load package
library(tidyverse) # for cleaning, plotting, etc
library(tidyquant) # for financial analysis
## Import data
stocks <- tq_get("AAPL", get = "stock.prices", from = "2016-01-01")
stocks
## # A tibble: 922 x 7
## date open high low close volume adjusted
## <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2016-01-04 103. 105. 102 105. 67649400 98.7
## 2 2016-01-05 106. 106. 102. 103. 55791000 96.3
## 3 2016-01-06 101. 102. 99.9 101. 68457400 94.4
## 4 2016-01-07 98.7 100. 96.4 96.4 81094400 90.4
## 5 2016-01-08 98.6 99.1 96.8 97.0 70798000 90.9
## 6 2016-01-11 99.0 99.1 97.3 98.5 49739400 92.4
## 7 2016-01-12 101. 101. 98.8 100.0 49154200 93.7
## 8 2016-01-13 100. 101. 97.3 97.4 62439600 91.3
## 9 2016-01-14 98.0 100. 95.7 99.5 63170100 93.3
## 10 2016-01-15 96.2 97.7 95.4 97.1 79833900 91.0
## # … with 912 more rows
## Examine data
glimpse(stocks)
## Observations: 922
## Variables: 7
## $ date <date> 2016-01-04, 2016-01-05, 2016-01-06, 2016-01-07, 2016-0…
## $ open <dbl> 102.61, 105.75, 100.56, 98.68, 98.55, 98.97, 100.55, 10…
## $ high <dbl> 105.37, 105.85, 102.37, 100.13, 99.11, 99.06, 100.69, 1…
## $ low <dbl> 102.00, 102.41, 99.87, 96.43, 96.76, 97.34, 98.84, 97.3…
## $ close <dbl> 105.35, 102.71, 100.70, 96.45, 96.96, 98.53, 99.96, 97.…
## $ volume <dbl> 67649400, 55791000, 68457400, 81094400, 70798000, 49739…
## $ adjusted <dbl> 98.74225, 96.26781, 94.38389, 90.40047, 90.87848, 92.35…
## Visualize
stocks %>%
ggplot(aes(x = date, y = close)) +
geom_line()
Hint: Insert a new code chunk below and type in the code, using the tq_get() function above. Replace the ticker symbol for Microsoft. 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("MFST", get = "stock.prices", from = "2016-01-01")
stocks
## # A tibble: 922 x 7
## date open high low close volume adjusted
## <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2016-01-04 7.3 7.3 7.3 7.3 1 7.3
## 2 2016-01-05 6 6 6 6 40 6
## 3 2016-01-06 6 6 6 6 0 6
## 4 2016-01-07 6 6 6 6 1 6
## 5 2016-01-08 6.8 6.8 6.8 6.8 35 6.8
## 6 2016-01-11 6.8 9.5 6.3 8.86 84 8.86
## 7 2016-01-12 7 7 7 7 46 7
## 8 2016-01-13 7 7 7 7 0 7
## 9 2016-01-14 9.2 9.2 7 7 2 7
## 10 2016-01-15 7 8.8 6.1 6.1 73 6.1
## # … with 912 more rows
Hint: Insert a new code chunk below and type in the code, using the glimpse() function above.
## Examine data
glimpse(stocks)
## Observations: 922
## Variables: 7
## $ date <date> 2016-01-04, 2016-01-05, 2016-01-06, 2016-01-07, 2016-0…
## $ open <dbl> 7.3, 6.0, 6.0, 6.0, 6.8, 6.8, 7.0, 7.0, 9.2, 7.0, 6.1, …
## $ high <dbl> 7.3, 6.0, 6.0, 6.0, 6.8, 9.5, 7.0, 7.0, 9.2, 8.8, 6.1, …
## $ low <dbl> 7.3, 6.0, 6.0, 6.0, 6.8, 6.3, 7.0, 7.0, 7.0, 6.1, 6.1, …
## $ close <dbl> 7.30, 6.00, 6.00, 6.00, 6.80, 8.86, 7.00, 7.00, 7.00, 6…
## $ volume <dbl> 1, 40, 0, 1, 35, 84, 46, 0, 2, 73, 0, 1021, 224, 213, 1…
## $ adjusted <dbl> 7.30, 6.00, 6.00, 6.00, 6.80, 8.86, 7.00, 7.00, 7.00, 6…
open high low close volume adjusted
Hint: Watch the video, “Basic Data Types”, in DataCamp: Introduction to R for Finance: Ch1 The Basics. numeric logical and charachter
922
daily information on stock prices
Hint: Insert a new code chunk below and type in the code, using the ggplot() function above. For more information on the ggplot() function, refer to Ch2 Introduction to ggplot2 in one of our e-textbooks, Data Visualization with R.
## Visualize
stocks %>%
ggplot(aes(x = date, y = close)) +
geom_line()
```
Hint: Change message, warning, collapse, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.