Advertisement
ahorn07

Economics assignment (International Finance)

Oct 10th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. # Historic data for selected currencies and interest rates
  2. # Kevin Kotze
  3.  
  4. # General cleanup ----
  5. rm(list = ls())
  6. graphics.off()
  7.  
  8. # System setup ----
  9. path <- 'F:/Economics/Honours/International Finance' # change the path to where you want to work and save files
  10. setwd(path)
  11.  
  12. system("C:/blp/DAPI/bbcomm.exe")
  13.  
  14. library(Rblpapi)
  15. con <- blpConnect()
  16.  
  17. # Set parameters ----
  18. begin <- as.Date("1990-01-01") # set first observation
  19. opt <- c("periodicitySelection" = "MONTHLY") # set data frequency
  20.  
  21. # Retrieve one month forward data for USDZAR ----
  22. forward <- bdh(securities = 'ZAR1M CURNCY',
  23. fields = 'PX_LAST',
  24. start.date = begin,
  25. options = opt)
  26.  
  27. # Retrieve one month exchange rate data for USDZAR ----
  28. exch <- bdh(securities = 'USDZAR CURNCY',
  29. fields = 'PX_LAST',
  30. start.date = begin,
  31. options = opt)
  32.  
  33. # Retrieve one month interest rate data for ZAR ----
  34. domint <- bdh(securities = 'SARPRT INDEX',
  35. fields = 'PX_LAST',
  36. start.date = begin,
  37. options = opt)
  38.  
  39. # Retrieve one month interest rate data for USD ----
  40. forint <- bdh(securities = 'FDFD INDEX',
  41. fields = 'PX_LAST',
  42. start.date = begin,
  43. options = opt)
  44.  
  45. # Get all the vectors to the same length
  46. maxobs <- max(c(
  47. dim(forward)[1],
  48. dim(exch)[1],
  49. dim(domint)[1],
  50. dim(forint)[1]))
  51.  
  52.  
  53. missing <- data.frame(rep(NA,maxobs), rep(NA,maxobs))
  54. colnames(missing) <- colnames(forward)
  55.  
  56. if(maxobs - dim(forward)[1] > 0){
  57. dat1 <- rbind(missing[1:(maxobs - dim(forward)[1]),], forward)
  58. } else{dat1 <- forward}
  59.  
  60. if(maxobs - dim(exch)[1] > 0){
  61. dat2 <- rbind(missing[1:(maxobs - dim(exch)[1]),], exch)
  62. } else{dat2 <- exch}
  63.  
  64. if(maxobs - dim(domint)[1] > 0){
  65. dat3 <- rbind(missing[1:(maxobs - dim(domint)[1]),], domint)
  66. } else{dat3 <- domint}
  67.  
  68. if(maxobs - dim(forint)[1] > 0){
  69. dat4 <- rbind(missing[1:(maxobs - dim(forint)[1]),], forint)
  70. } else{dat4 <- forint}
  71.  
  72. dat <- cbind(dat1, dat2, dat3, dat4)
  73. colnames(dat)[seq(2, 8, by=2)] <- c("Forward", "Exchange", "Dom_int", "For_int")
  74.  
  75. write.csv(dat, file = "zar.csv")
  76.  
  77. blpDisconnect(con)
  78.  
  79. # 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