B Datasets

This Chapter provides code for datasets produced for the book.

B.1 Log-Returns of International Stock Market Indices Prices

B.1.1 Dataset Location

./data/global_indices_returns.csv

B.1.2 Dataset Description

Log-returns of adjusted prices for the indices identified by the following tickers: ^GSPC, ^FTSE, ^GDAXI, ^N100 and ^BVSP.

B.1.3 Data Source

Alpha Vantage

B.1.4 Code

GetReturn <- function(tickers){
library(quantmod)

data.env <- new.env()
dataset<- xts() # Only run once


# Download prices from AlphaVantage and calculate log-returns
for(i in 1:length(tickers)) {
  tickers[i]-> symbol
  print(symbol)
  getSymbols(symbol, src="av",
             auto.assign=TRUE,
             output.size="full",
             adjusted=TRUE,
             api.key=config::get()$alpha.vantage.key)

    dataset <- merge(dataset, periodReturn(Ad(get(tickers[i])),period="daily", type='log'))
    rm(symbol)
}

names(dataset)<-tickers

return(dataset)
}
tickers<-c("^GSPC", "^FTSE", "^GDAXI", "^N100", "^BVSP")
dataset<-GetReturn(tickers)
tmp <- tempfile()
write.zoo(dataset,sep=",",file="./data/global_indices_returns.csv")

B.1.5 Dataset Scheme

library(xts)
dataset<-as.xts(read.zoo('./data/global_indices_returns.csv',
                  header=TRUE,
                  index.column=1, sep=","))
tail(dataset)
##                       X.GSPC   X.FTSE  X.GDAXI   X.N100   X.BVSP
## 2019-08-08 20:00:00 -0.00664 -0.00440 -0.01288 -0.01114 -0.00114
## 2019-08-11 20:00:00 -0.01239 -0.00376 -0.00121 -0.00342 -0.02021
## 2019-08-12 20:00:00  0.01502  0.00334  0.00601  0.00661  0.01349
## 2019-08-13 20:00:00 -0.02973 -0.01431 -0.02216 -0.01956 -0.02988
## 2019-08-14 20:00:00  0.00246 -0.01138 -0.00698 -0.00380 -0.01205
## 2019-08-15 20:00:00  0.01432  0.00708  0.01306  0.01340  0.00753

B.2 Log-Returns of FAANG Prices

B.2.1 Dataset Location

./data/FAANG.csv

B.2.2 Dataset Description

Log-returns of adjusted prices for the stocks identified by the following tickers: FB, AMZN, AAPL, NFLX and GOOG.

B.2.3 Data Source

Alpha Vantage

B.2.4 Code

tickers<-c("FB", "AMZN", "AAPL", "NFLX", "GOOGL")
dataset<-GetReturn(tickers)
tmp <- tempfile()
write.zoo(dataset,sep=",",file="./data/FAANG.csv")

B.2.5 Dataset Scheme

dataset<-as.xts(read.zoo('./data/FAANG.csv',
                  header=TRUE,
                  index.column=1, sep=","))
tail(dataset)
##                            FB     AMZN     AAPL     NFLX      GOOG
## 2019-08-22 20:00:00 -0.023848 -0.03097 -0.04732 -0.01866 -0.032675
## 2019-08-25 20:00:00  0.014577  0.01094  0.01882  0.01207  0.015172
## 2019-08-26 20:00:00  0.005198 -0.00399 -0.01135 -0.01348 -0.000899
## 2019-08-27 20:00:00  0.002534  0.00137  0.00669  0.00254  0.002719
## 2019-08-28 20:00:00  0.020745  0.01248  0.01679  0.01703  0.018470
## 2019-08-29 20:00:00  0.000539 -0.00568 -0.00129 -0.01026 -0.003990