Importing Text File in R
Importing Text File in R
"Date","AMZN.Open","AMZN.High","AMZN.Low","AMZN.Close","AMZN.Volume","AMZN.Adjusted"
2002-01-02,11.13,11.01,10.46,10.87,6674703,10.87
2002-01-03,11.26,12.25,10.76,11.99,11441553,11.99
2002-01-04,12.46,12.62,11.71,12.1,12619402,12.1
> head(AMZN, 3)
AMZN.Open AMZN.High AMZN.Low AMZN.Close AMZN.Volume AMZN.Adjusted
2002-01-02 11.13 11.01 10.46 10.87 6674703 10.87
2002-01-03 11.26 12.25 10.76 11.99 11441553 11.99
2002-01-04 12.46 12.62 11.71 12.10 12619402 12.10
Importing and Managing Financial Data in R
read.zoo()
! AMZN.csv
"Date","AMZN.Open","AMZN.High","AMZN.Low","AMZN.Close","AMZN.Volume","AMZN.Adjusted"
2002-01-02,11.13,11.01,10.46,10.87,6674703,10.87
2002-01-03,11.26,12.25,10.76,11.99,11441553,11.99
2002-01-04,12.46,12.62,11.71,12.1,12619402,12.1
> head(amzn_xts, n = 3)
AMZN.Open AMZN.High AMZN.Low AMZN.Close AMZN.Volume AMZN.Adjusted
2002-01-02 11.13 11.01 10.46 10.87 6674703 10.87
2002-01-03 11.26 12.25 10.76 11.99 11441553 11.99
2002-01-04 12.46 12.62 11.71 12.10 12619402 12.10
Importing and Managing Financial Data in R
"Date","Time","Open","High","Low","Close"
2016-11-08,09:05:00,80.9,81,80.87,81
2016-11-08,09:10:00,80.92,80.93,80.89,80.89
2016-11-08,09:15:00,80.93,80.94,80.92,80.93
> head(foo_zoo, n = 3)
Open High Low Close
2016-11-08 09:05:00 80.90 81.00 80.87 81.00
2016-11-08 09:10:00 80.92 80.93 80.89 80.89
2016-11-08 09:15:00 80.93 80.94 80.92 80.93
Importing and Managing Financial Data in R
Date,Symbol,Type,Price
2016-01-01 10:43:01,A,Bid,58.23
2016-01-01 10:43:01,A,Ask,58.24
2016-01-01 10:43:01,B,Bid,28.96
2016-01-01 10:43:01,B,Ask,28.98
> bar_zoo
A.Ask B.Ask A.Bid B.Bid
2016-01-01 10:43:01 58.24 28.98 58.23 28.96
2016-01-01 10:43:02 58.25 28.99 58.24 28.97
IMPORTING AND MANAGING FINANCIAL DATA IN R
Let’s practice!
IMPORTING AND MANAGING FINANCIAL DATA IN R
Checking for
weirdness
Importing and Managing Financial Data in R
Visualize Data
> getSymbols("DGS10", src = "FRED")
[1] "DGS10"
> treasury_10 <- DGS10["1982-02"]
> plot(treasury_10, main = "10-Year Constant Maturity Treasury Rate")
Importing and Managing Financial Data in R
Visualize data
> getSymbols("MSFT", from = "2004-07-01", to = "2004-12-31", src = "google")
[1] "MSFT"
> plot(Cl(MSFT), main = "Microsoft (Google Finance)")
Importing and Managing Financial Data in R
Cross-reference sources
> getSymbols("MSFT", from = "2004-07-01", to = "2004-12-31")
[1] "MSFT"
> plot(Cl(MSFT), main = "Microsoft (Yahoo Finance)")
Importing and Managing Financial Data in R
Pre-split Post-split
Pre-dividend Post-dividend
Cash $0 $300
Let’s practice!
IMPORTING AND MANAGING FINANCIAL DATA IN R
adjRatios()
● Back-adjust any series for splits, dividends, or both
● has 3 arguments
● splits
● dividends
● close
● returns xts-object with 2 columns: Split and Div
Importing and Managing Financial Data in R
Let’s practice!
IMPORTING AND MANAGING FINANCIAL DATA IN R
Congratulations!