[关闭]
@fanxy 2016-10-28T18:38:45.000000Z 字数 2390 阅读 1661

第七讲 货币金融:理论框架与政策应用

樊潇彦 复旦大学经济学院 中级宏观


  1. library(readxl) # 读取excel数据
  2. library(stringr) # 字符串处理
  3. library(corrplot)
  4. library(igraph)
  5. library(forecast)
  6. library(stats) # 基础包,不用安装直接调用
  7. library(dplyr)
  8. library(tidyr)
  9. library(data.table)
  10. library(foreign)
  11. library(readstata13)
  12. library(haven)
  13. library(ggplot2)
  14. library(ggrepel)
  15. library(dygraphs)
  16. library(plotrix)
  17. library(lubridate)
  18. library(zoo)
  19. library(mFilter)
  20. setwd("D:\\") # 设定工作目录

1. 美国货币供给的弗里德曼规则

  1. m_us=read_excel("Ch07_Data.xls",sheet="m_us",skip=2)
  2. colnames(m_us)=c("year","g_gdp","pi","m1","m2")
  3. m_us=m_us%>%filter(!is.na(`g_gdp`))%>%
  4. mutate(year=as.numeric(year(year)))%>%
  5. mutate(g_m1=m1/lag(m1)*100-100)%>%
  6. mutate(g_m2=m2/lag(m2)*100-100)%>%
  7. mutate(diff1=g_m1-pi-g_gdp)%>%
  8. mutate(diff2=g_m2-pi-g_gdp)%>%
  9. gather(var,value,-year)%>%
  10. filter(!is.na(value) & !var%in%c("m1","m2"))%>%
  11. mutate(label=ifelse(year==1986,var,""))
  12. sd(m_us$value[m_us$var=="diff2"]) # 3.62
  13. mean(m_us$value[m_us$var=="diff2"]) # -0.03
  14. ggplot(m_us[m_us$var=="diff2",],
  15. aes(year,value))+geom_line(size=1)+geom_smooth()+
  16. scale_x_continuous(breaks = seq(1960,2015,5))+
  17. geom_vline(xintercept =c(1983,1994,2007), ,linetype = "dotdash",col="red")+
  18. labs(title="美国货币供给的弗里德曼规则",x="",y="")+
  19. guides(color=guide_legend(title=NULL))+theme_bw()+ theme(legend.position="non")

2. 存贷款基准利率与存款准备金率

  1. basic_i=read_excel("Ch07_Data.xls",sheet="basic_i",skip=2)
  2. basic_i=basic_i%>%
  3. mutate(time=as.yearmon(`指标名称`))%>%
  4. select(-`指标名称`)%>%
  5. gather(var,value,-time)%>%
  6. mutate(var=sub("[(]月[)]","",var))%>%
  7. mutate(label=ifelse(time==as.yearmon("2015-01"),var,""))
  8. ggplot(basic_i,aes(time,value,color=var))+geom_line(size=1)+
  9. labs(title="存款准备金率与存贷款基准利率",x="",y="")+
  10. scale_x_continuous(breaks = year(seq(as.Date("1985/1/1"),as.Date("2016/4/1"),"3 years")))+
  11. geom_text(aes(label=label,hjust =1))+
  12. guides(color=guide_legend(title=NULL))+theme_bw()+theme(legend.position="non")

3. SHIBOR和银行间质押式回购加权利率

  1. mm_i=read_excel("Ch07_Data.xls",sheet="mm_i",skip=2)
  2. mm_i=mm_i%>%
  3. rename(time=`指标名称`)%>%
  4. gather(market,value,-time)%>%
  5. filter(!is.na(value))%>%
  6. mutate(period=sub(".*:","",market))%>%
  7. mutate(market=sub(":.*","",market))%>%
  8. mutate(period=sub("7天","1周",period))%>%
  9. mutate(period=sub("1年","一年",period))%>%
  10. filter(period %in% c("1周","3个月","一年"))
  11. ggplot(mm_i,aes(time,value,color=period))+geom_line(size=0.8)+facet_wrap(~market)+
  12. labs(title="SHIBOR和银行间质押式回购加权利率",x="",y="")+
  13. guides(color=guide_legend(title=NULL))+theme_bw()+theme(legend.position="bottom")
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注