Guest User

Untitled

a guest
Dec 10th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #You can just run the code in your console
  2. library(quantmod)
  3. library(vars)
  4.  
  5.  
  6. #Download the two stock symbols in question VNQ and SPY
  7. tickers = c("SPY", "VNQ")
  8. getSymbols(tickers)
  9.  
  10. #Convert data to a stationairy process
  11. spy_station = diff(SPY$SPY.Close)
  12. vnq_station = diff(VNQ$VNQ.Close)
  13.  
  14. #merge the data together
  15. data = merge(spy_station, vnq_station)
  16. data = na.omit(data)
  17.  
  18. #Now we see which lag is optimal
  19. VARselect(data, type = "both")
  20. 1 2 3 4 5 6 7 8
  21. 9 10
  22. AIC(n) 0.4611156 0.4602640 0.4605474 0.4611319 0.4614260 0.4630208
  23. 0.4637955 0.4607941 0.4623594 0.4616697
  24. #It looks like p = 2 is the best.
  25.  
  26. #Create our VAR model
  27. vmodel = VAR(data, p = 2, type = "both")
  28. summary(vmodel)
Add Comment
Please, Sign In to add comment