Loading data
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.71606
## 2020-01-03 74.2875 75.1450 74.1250 74.3575 146322800 72.00912
## 2020-01-06 73.4475 74.9900 73.1875 74.9500 118387200 72.58292
## 2020-01-07 74.9600 75.2250 74.3700 74.5975 108872000 72.24155
## 2020-01-08 74.2900 76.1100 74.2900 75.7975 132079200 73.40365
## 2020-01-09 76.8100 77.6075 76.5500 77.4075 170108400 74.96279
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
min(AAPL$AAPL.Adjusted)
Largest element
What is the max 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
max(AAPL$AAPL.Adjusted)
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
median(AAPL$AAPL.Adjusted)
Mean
What is the mean 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)
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
quantile(AAPL$AAPL.Adjusted, probs = c(0.25, 0.80))
Sample variance and std deviation
What is the sample variance and std deviation 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
var(AAPL$AAPL.Adjusted); sd(AAPL$AAPL.Adjusted)
Interquartile Range
What is the IQR value of Apple's adjusted stock?
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
IQR(AAPL$AAPL.Adjusted)
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))