Question 1

data(cars)
median(cars$speed)
## [1] 15

Question 2

Used Max function to find highest closing time

#install.packages("jsonlite")
library(jsonlite)
bitcoin_data <- fromJSON("https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=10")
bitcoin_data
## $Response
## [1] "Success"
## 
## $Message
## [1] ""
## 
## $HasWarning
## [1] FALSE
## 
## $Type
## [1] 100
## 
## $RateLimit
## named list()
## 
## $Data
## $Data$Aggregated
## [1] FALSE
## 
## $Data$TimeFrom
## [1] 1771545600
## 
## $Data$TimeTo
## [1] 1772409600
## 
## $Data$Data
##          time     high      low     open volumefrom   volumeto    close
## 1  1771545600 68297.95 66442.67 66983.75   38044.13 2565992687 67997.02
## 2  1771632000 68686.92 67528.59 67997.02   11686.08  796953224 67965.05
## 3  1771718400 68233.91 67170.64 67965.05   11615.92  786667937 67626.88
## 4  1771804800 67663.82 63879.72 67626.88   42373.83 2766008869 64642.48
## 5  1771891200 64996.35 62551.85 64642.48   45607.54 2906212703 64069.84
## 6  1771977600 70005.48 63922.45 64069.84   55809.16 3753044531 67998.99
## 7  1772064000 68867.59 66508.93 67998.99   44886.39 3038274772 67498.16
## 8  1772150400 68227.68 64948.18 67498.16   41323.20 2743694517 65870.53
## 9  1772236800 67756.22 63030.34 65870.53   39423.24 2566186201 66985.30
## 10 1772323200 68190.48 65043.22 66985.30   31940.58 2126537311 65774.35
## 11 1772409600 70116.05 65261.45 65774.35   50628.05 3433380619 69301.10
##    conversionType conversionSymbol
## 1          direct                 
## 2          direct                 
## 3          direct                 
## 4          direct                 
## 5          direct                 
## 6          direct                 
## 7          direct                 
## 8          direct                 
## 9          direct                 
## 10         direct                 
## 11         direct
btc_df <- bitcoin_data$Data$Data
max_close <- max(btc_df$close, na.rm= TRUE)
max_close
## [1] 69301.1

Question 3

Title- S&P 500 Research Project

## Goal Questions-
### Question 1- What are the best and worst daily returns in the sample. This will be good to look at what was going on in the world during these times
### Question 2- How often does the market experience a 5%-20% drawdown in a short period of time, what causes this.
### Question 3- what times in history have there been high volatility. Good to see what causes the volatility

# Data selection- 
## Used Yahoo Finance Data
#install.packages("tidyquant")
library(tidyquant)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Warning: package 'zoo' was built under R version 4.4.3
## ── Attaching core tidyquant packages ─────────────────────── tidyquant 1.0.11 ──
## ✔ PerformanceAnalytics 2.0.8      ✔ TTR                  0.24.4
## ✔ quantmod             0.4.28     ✔ xts                  0.14.1
## ── Conflicts ────────────────────────────────────────── tidyquant_conflicts() ──
## ✖ zoo::as.Date()                 masks base::as.Date()
## ✖ zoo::as.Date.numeric()         masks base::as.Date.numeric()
## ✖ PerformanceAnalytics::legend() masks graphics::legend()
## ✖ quantmod::summary()            masks base::summary()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:xts':
## 
##     first, last
## 
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
spx <- tq_get("^GSPC", from = "2000-01-01", to = Sys.Date())
head(spx)
## # A tibble: 6 × 8
##   symbol date        open  high   low close     volume adjusted
##   <chr>  <date>     <dbl> <dbl> <dbl> <dbl>      <dbl>    <dbl>
## 1 ^GSPC  2000-01-03 1469. 1478  1438. 1455.  931800000    1455.
## 2 ^GSPC  2000-01-04 1455. 1455. 1397. 1399. 1009000000    1399.
## 3 ^GSPC  2000-01-05 1399. 1413. 1378. 1402. 1085500000    1402.
## 4 ^GSPC  2000-01-06 1402. 1412. 1392. 1403. 1092300000    1403.
## 5 ^GSPC  2000-01-07 1403. 1441. 1401. 1441. 1225200000    1441.
## 6 ^GSPC  2000-01-10 1441. 1464. 1441. 1458. 1064800000    1458.
# Clean Data
## Organizing by date and ensuring no nas
colSums(is.na(spx))
##   symbol     date     open     high      low    close   volume adjusted 
##        0        0        0        0        0        0        0        0
spx_arranged <- spx %>%
  arrange(date)
spx_arranged
## # A tibble: 6,578 × 8
##    symbol date        open  high   low close     volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>      <dbl>    <dbl>
##  1 ^GSPC  2000-01-03 1469. 1478  1438. 1455.  931800000    1455.
##  2 ^GSPC  2000-01-04 1455. 1455. 1397. 1399. 1009000000    1399.
##  3 ^GSPC  2000-01-05 1399. 1413. 1378. 1402. 1085500000    1402.
##  4 ^GSPC  2000-01-06 1402. 1412. 1392. 1403. 1092300000    1403.
##  5 ^GSPC  2000-01-07 1403. 1441. 1401. 1441. 1225200000    1441.
##  6 ^GSPC  2000-01-10 1441. 1464. 1441. 1458. 1064800000    1458.
##  7 ^GSPC  2000-01-11 1458. 1459. 1434. 1439. 1014000000    1439.
##  8 ^GSPC  2000-01-12 1439. 1443. 1427. 1432.  974600000    1432.
##  9 ^GSPC  2000-01-13 1432. 1454. 1432. 1450. 1030400000    1450.
## 10 ^GSPC  2000-01-14 1450. 1473  1450. 1465. 1085900000    1465.
## # ℹ 6,568 more rows