Using the given code, answer the questions below.

library(tidyquant) 
library(tidyverse) 

stocks <- tq_get("AAPL", get = "stock.prices", from = "2016-01-05")
stocks
## # A tibble: 775 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2016-01-05 106.  106.  102.  103.  55791000     97.4
##  2 2016-01-06 101.  102.   99.9 101.  68457400     95.5
##  3 2016-01-07  98.7 100.   96.4  96.4 81094400     91.5
##  4 2016-01-08  98.6  99.1  96.8  97.0 70798000     92.0
##  5 2016-01-11  99.0  99.1  97.3  98.5 49739400     93.5
##  6 2016-01-12 101.  101.   98.8 100.0 49154200     94.8
##  7 2016-01-13 100.  101.   97.3  97.4 62439600     92.4
##  8 2016-01-14  98.0 100.   95.7  99.5 63170100     94.4
##  9 2016-01-15  96.2  97.7  95.4  97.1 79010000     92.1
## 10 2016-01-19  98.4  98.7  95.5  96.7 53087700     91.7
## # … with 765 more rows

stocks %>%
  ggplot(aes(x = date, y = close)) +
  geom_line()

Q1. How many columns (variables) are there?

There are seven columns.

Q2. What are the variables?

The variables are date, open, high, low, close, volume, and adjusted.

Q3. How many rows are there?

There are 776 rows.

Q4. What does the row represent?

THe row represents Apple stock prices on a given day.

Q5. Get Microsoft stock prices, instead of Apple.

stocks <- tq_get("MSFT", get = "stock.prices", from = "2016-01-01")
stocks
## # A tibble: 776 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2016-01-04  54.3  54.8  53.4  54.8 53778000     51.3
##  2 2016-01-05  54.9  55.4  54.5  55.0 34079700     51.5
##  3 2016-01-06  54.3  54.4  53.6  54.0 39518900     50.6
##  4 2016-01-07  52.7  53.5  52.1  52.2 56564900     48.8
##  5 2016-01-08  52.4  53.3  52.2  52.3 48754000     49.0
##  6 2016-01-11  52.5  52.8  51.5  52.3 36663600     48.9
##  7 2016-01-12  52.8  53.1  52.1  52.8 36095500     49.4
##  8 2016-01-13  53.8  54.1  51.3  51.6 66883600     48.3
##  9 2016-01-14  52    53.4  51.6  53.1 52381900     49.7
## 10 2016-01-15  51.3  52.0  50.3  51.0 71820700     47.7
## # … with 766 more rows

stocks %>%
  ggplot(aes(x = date, y = close)) +
  geom_line()

Q6. Get the stock prices from 2017-01-15 to 2018-12-15.

stocks <- tq_get("MSFT", get = "stock.prices", from = "2017-01-15", to = "2018-12-15")
stocks
## # A tibble: 483 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2017-01-17  62.7  62.7  62.0  62.5 20620400     60.1
##  2 2017-01-18  62.7  62.7  62.1  62.5 19670100     60.1
##  3 2017-01-19  62.2  63.0  62.2  62.3 18451700     59.9
##  4 2017-01-20  62.7  62.8  62.4  62.7 30213500     60.3
##  5 2017-01-23  62.7  63.1  62.6  63.0 23097600     60.5
##  6 2017-01-24  63.2  63.7  62.9  63.5 24672900     61.1
##  7 2017-01-25  64.0  64.1  63.5  63.7 23672700     61.2
##  8 2017-01-26  64.1  64.5  63.5  64.3 43554600     61.8
##  9 2017-01-27  65.4  65.9  64.9  65.8 44818000     63.2
## 10 2017-01-30  65.7  65.8  64.8  65.1 31651400     62.6
## # … with 473 more rows

Q7. Get economic data, the unemployment rate for the U.S., instead of stock prices.

stocks <- tq_get("UNRATE", get = "economic.data", from = "2016-01-01")
stocks
## # A tibble: 37 x 2
##    date       price
##    <date>     <dbl>
##  1 2016-01-01   4.9
##  2 2016-02-01   4.9
##  3 2016-03-01   5  
##  4 2016-04-01   5  
##  5 2016-05-01   4.8
##  6 2016-06-01   4.9
##  7 2016-07-01   4.8
##  8 2016-08-01   4.9
##  9 2016-09-01   5  
## 10 2016-10-01   4.9
## # … with 27 more rows

stocks %>%
  ggplot(aes(x = date, y = price)) +
  geom_line()

Q8. Get exchange rate between the U.S. dollar and the euro, instead of stock prices.

stocks <- tq_get("USD/EUR", get = "exchange.rates", from = "2016-01-01")
stocks
## # A tibble: 180 x 2
##    date       exchange.rate
##    <date>             <dbl>
##  1 2018-08-09         0.864
##  2 2018-08-10         0.873
##  3 2018-08-11         0.876
##  4 2018-08-12         0.877
##  5 2018-08-13         0.878
##  6 2018-08-14         0.879
##  7 2018-08-15         0.882
##  8 2018-08-16         0.879
##  9 2018-08-17         0.877
## 10 2018-08-18         0.874
## # … with 170 more rows

stocks %>%
  ggplot(aes(x = date, y = exchange.rate)) +
  geom_line()