01/05/2017

How to collect economic data from FRED in R

How to collect economic data from FRED

At least you should have a basic understanding of analytical tools, R and Python.

Also, it is assumed that R and quantmod(package) have been already installed.

First of all, Have a look at a indicator you want to find
1) if you succeed to access the website, FRED, you can see the following screen.
2)  just type US Recession Probabilities






There are two search results,
of which Smoothed U.S Recession Probabilities is the economic index I want.

Do you see the code RECPROUSM156N next to the indicator name?
Please keep it in mind.



Next stage is to download the data from R

And we are going to use getSymbols in guantmod.

codes are following:

install.packages("quantmod")
library(quantmod)
getSymbols("RECPROUSM156N", src='FRED')
plot(RECPROUSM156N)

Tada~Here we are, that's it.



A variation of the code is to use several index at the same time.
Let's find out relation between Kospi index and the recession probabilities.


require(quantmod)

rec<-getsymbols auto.assign="FALSE)<br" src="FRED">kospi<-getsymbols auto.assign="FALSE)</span" src="yahoo">


# to data.frame
dfrec <- as.data.frame="" br="" rec="">dfkospi <- as.data.frame="" kospi="" lose="" span="">
mrec<- cbind="" eval_d="row.names(dfrec)," rec="dfrec)<br">mkospi<- cbind="" eval_d="row.names(dfkospi)," kospi="dfkospi)</span">
merged_rec_kospi<-merge br="" by="eval_d" mkospi="" mrec="">plot(merged_rec_kospi[,2], type='l', col='red')
par(new=TRUE)
plot(merged_rec_kospi[,3], type='l', col='blue')





it can be found that when the recession probabilities increased rapidly,
there is a high chance that the kospi index would slumped.

-reference-
http://blog.naver.com/htk1019/220891514114

Share this

Tag :

0 Comment to "How to collect economic data from FRED in R"

Post a Comment