Let's start by getting data to play with! You will use the mathematical functions on these data.

# Loading the quantmod package
library(quantmod)

# Access financial information on Apple stock
getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31") 
## [1] "AAPL"
head(AAPL)
##            AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
## 2020-01-02   74.0600   75.1500  73.7975    75.0875   135480400      72.96047
## 2020-01-03   74.2875   75.1450  74.1250    74.3575   146322800      72.25114
## 2020-01-06   73.4475   74.9900  73.1875    74.9500   118387200      72.82684
## 2020-01-07   74.9600   75.2250  74.3700    74.5975   108872000      72.48434
## 2020-01-08   74.2900   76.1100  74.2900    75.7975   132079200      73.65034
## 2020-01-09   76.8100   77.6075  76.5500    77.4075   170108400      75.21474

## Smallest element

What is the min of Apple's adjusted stock value? Complete the following code.

quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below
quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below

## Median

What is the median of Apple's adjusted stock value?

quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below
quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below

## Trimmed mean

What is the trimmed mean at 5% of Apple's adjusted stock value?

quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below
quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below
mean(AAPL$AAPL.Adjusted, trim = 0.05) ## Sample quantile What is the third quartile (75%) of Apple's adjusted stock value? quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31") # Insert the missing code below quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31") # Insert the missing code below quantile(AAPL$AAPL.Adjusted, probs = 0.75)

What is the first quartile (25%) and 80% of Apple's adjusted stock value?

quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below
quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below

## Sample Skewness

$$\vert g_{1} \vert$$ = Apple adjusted stock. Is $$\vert g_{1} \vert > 2\sqrt{6/n}$$?

quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below
quantmod::getSymbols("AAPL", src="yahoo", from="2020-01-01", to="2020-12-31")

# Insert the missing code below
library(e1071)
skewness(AAPL$AAPL.Adjusted) 2*sqrt(6/length(AAPL$AAPL.Adjusted))

Quiz