Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Historic data for selected currencies and interest rates
- # Kevin Kotze
- # General cleanup ----
- rm(list = ls())
- graphics.off()
- # System setup ----
- path <- 'F:/Economics/Honours/International Finance' # change the path to where you want to work and save files
- setwd(path)
- system("C:/blp/DAPI/bbcomm.exe")
- library(Rblpapi)
- con <- blpConnect()
- # Set parameters ----
- begin <- as.Date("1990-01-01") # set first observation
- opt <- c("periodicitySelection" = "MONTHLY") # set data frequency
- # Retrieve one month forward data for USDZAR ----
- forward <- bdh(securities = 'ZAR1M CURNCY',
- fields = 'PX_LAST',
- start.date = begin,
- options = opt)
- # Retrieve one month exchange rate data for USDZAR ----
- exch <- bdh(securities = 'USDZAR CURNCY',
- fields = 'PX_LAST',
- start.date = begin,
- options = opt)
- # Retrieve one month interest rate data for ZAR ----
- domint <- bdh(securities = 'SARPRT INDEX',
- fields = 'PX_LAST',
- start.date = begin,
- options = opt)
- # Retrieve one month interest rate data for USD ----
- forint <- bdh(securities = 'FDFD INDEX',
- fields = 'PX_LAST',
- start.date = begin,
- options = opt)
- # Get all the vectors to the same length
- maxobs <- max(c(
- dim(forward)[1],
- dim(exch)[1],
- dim(domint)[1],
- dim(forint)[1]))
- missing <- data.frame(rep(NA,maxobs), rep(NA,maxobs))
- colnames(missing) <- colnames(forward)
- if(maxobs - dim(forward)[1] > 0){
- dat1 <- rbind(missing[1:(maxobs - dim(forward)[1]),], forward)
- } else{dat1 <- forward}
- if(maxobs - dim(exch)[1] > 0){
- dat2 <- rbind(missing[1:(maxobs - dim(exch)[1]),], exch)
- } else{dat2 <- exch}
- if(maxobs - dim(domint)[1] > 0){
- dat3 <- rbind(missing[1:(maxobs - dim(domint)[1]),], domint)
- } else{dat3 <- domint}
- if(maxobs - dim(forint)[1] > 0){
- dat4 <- rbind(missing[1:(maxobs - dim(forint)[1]),], forint)
- } else{dat4 <- forint}
- dat <- cbind(dat1, dat2, dat3, dat4)
- colnames(dat)[seq(2, 8, by=2)] <- c("Forward", "Exchange", "Dom_int", "For_int")
- write.csv(dat, file = "zar.csv")
- blpDisconnect(con)
- # Note that forward points are the number of basis points added to or subtracted from the current spot rate of a currency pair to determine the forward rate for delivery on a specific value date
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement