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: 1,025 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.4
## 2 2016-01-05 106. 106. 102. 103. 55791000 96.0
## 3 2016-01-06 101. 102. 99.9 101. 68457400 94.1
## 4 2016-01-07 98.7 100. 96.4 96.4 81094400 90.1
## 5 2016-01-08 98.6 99.1 96.8 97.0 70798000 90.6
## 6 2016-01-11 99.0 99.1 97.3 98.5 49739400 92.1
## 7 2016-01-12 101. 101. 98.8 100. 49154200 93.4
## 8 2016-01-13 100. 101. 97.3 97.4 62439600 91.0
## 9 2016-01-14 98.0 100. 95.7 99.5 63170100 93.0
## 10 2016-01-15 96.2 97.7 95.4 97.1 79833900 90.8
## # … with 1,015 more rows
## Examine data
glimpse(stocks)
## Observations: 1,025
## Variables: 7
## $ date <date> 2016-01-04, 2016-01-05, 2016-01-06, 2016-01-07, 2016-01-08,…
## $ open <dbl> 102.61, 105.75, 100.56, 98.68, 98.55, 98.97, 100.55, 100.32,…
## $ high <dbl> 105.37, 105.85, 102.37, 100.13, 99.11, 99.06, 100.69, 101.19…
## $ low <dbl> 102.00, 102.41, 99.87, 96.43, 96.76, 97.34, 98.84, 97.30, 95…
## $ close <dbl> 105.35, 102.71, 100.70, 96.45, 96.96, 98.53, 99.96, 97.39, 9…
## $ volume <dbl> 67649400, 55791000, 68457400, 81094400, 70798000, 49739400, …
## $ adjusted <dbl> 98.44666, 95.97968, 94.10139, 90.12987, 90.60644, 92.07356, …
## 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
stocks <- tq_get("AMZN", 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 656. 658. 628. 637. 9314500 637.
## 2 2016-01-05 647. 647. 628. 634. 5822600 634.
## 3 2016-01-06 622 640. 620. 633. 5329200 633.
## 4 2016-01-07 622. 630 605. 608. 7074900 608.
## 5 2016-01-08 620. 624. 606 607. 5512900 607.
## 6 2016-01-11 612. 620. 599. 618. 4891600 618.
## 7 2016-01-12 625. 626. 612. 618. 4724100 618.
## 8 2016-01-13 621. 621. 579. 582. 7655200 582.
## 9 2016-01-14 580. 602. 570. 593 7238000 593
## 10 2016-01-15 572. 585. 565. 570. 7784500 570.
## # … with 1,015 more rows
glimpse(stocks)
## Observations: 1,025
## Variables: 7
## $ date <date> 2016-01-04, 2016-01-05, 2016-01-06, 2016-01-07, 2016-01-08,…
## $ open <dbl> 656.29, 646.86, 622.00, 621.80, 619.66, 612.48, 625.25, 620.…
## $ high <dbl> 657.72, 646.91, 639.79, 630.00, 624.14, 619.85, 625.99, 620.…
## $ low <dbl> 627.51, 627.65, 620.31, 605.21, 606.00, 598.57, 612.24, 579.…
## $ close <dbl> 636.99, 633.79, 632.65, 607.94, 607.05, 617.74, 617.89, 581.…
## $ volume <dbl> 9314500, 5822600, 5329200, 7074900, 5512900, 4891600, 472410…
## $ adjusted <dbl> 636.99, 633.79, 632.65, 607.94, 607.05, 617.74, 617.89, 581.…
Date, Open, High, Low, Close, Volume, Adjusted
Hint: Watch the video, “Basic Data Types”, in DataCamp: Introduction to R for Finance: Ch1 The Basics.
There are 7 rows
The rows represent each of the variables
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.