Download stock prices from yahoo finance
getSymbols.yahoo(Symbols = "MSFT",
env = globalenv(),
index.class = 'Date',
from = "1980-01-01",
to = "2019-12-31",
periodicity = "daily")
get the close price
close_price <- Cl(MSFT)
compute the periodical return
monthly_log_return <- periodReturn(MSFT,
period='monthly',
subset=NULL,
type='log')
plot the return
plot(weekly_log_return,
main = "Time Series Plot of MSFT's Weekly Log Returns")
slice a time series
traning_data <- window(weekly_log_return, start = '1986-03-13', end = '2017-12-31')