GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — MX_CapFlow/3_Fig_Yields.R at master · sebinbn/MX_CapFlow Expand file tree/ Copy path3_Fig_Yields.RMore file actions 130 lines (109 loc) · 7.05 KB / Copy path3_Fig_Yields.RFile metadata and controls130 lines (109 loc) · 7.05 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 #This code creates few figures of which 1 is used in the paper: # 1. Plotting the 1mo and 10yr yield over time from weekly data. (used in paper) # 2. Plotting the 1mo and 10yr yield over time from daily data. # 3. Plotting various short term yields over time from weekly data for comparison. # Fig 1 - TIIE,1mo and 30yr from weekly data ----------------------------------- Mex_long <- melt(Mex_w[Mex_w$Date <=as.Date("2023-12-31")& Mex_w$Date >=as.Date("2008-03-31"), c("Date","TIIE","MPTBA","GMXN30Y")], id.vars = "Date") Yield_plot = ggplot(Mex_long, aes(x = Date, y = value, color = variable)) + geom_line(linewidth = 1.25) + labs(y = "Yield on Mexican govt bonds (in %)", x = element_blank()) + scale_x_date(date_breaks = "2 year", date_labels = "%Y", expand = c(0,0)) + scale_color_discrete(labels = c( "Overnight rate", "1 month yield", "30 year yield")) + theme_minimal()+ theme(legend.position = c(0.8, 0.9),legend.title = element_blank(), legend.text = element_text(size = 14), legend.background = element_rect(linetype="solid",colour ="darkblue"), axis.text = element_text(size = 14), axis.title = element_text(size = 15)) Yield_plot # Fig 2 - 1mo and 10yr from weekly data ----------------------------------- Mex_long <- melt(Mex_w[,c("Date","MPTBA","GMXN10Y")], id.vars = "Date") Yield_plot = ggplot(Mex_long, aes(x = Date, y = value, color = variable)) + geom_line(linewidth = 1.25) + labs(y = "Yield on Mexican govt bonds (in %)", x = element_blank()) + scale_x_date(date_breaks = "2 year", date_labels = "%Y") + scale_color_discrete(labels = c( "1 month yield", "10 year yield")) + geom_rect(aes(xmin=as.Date("2010-01-01"), xmax=as.Date("2011-12-31"),ymin=-Inf,ymax=Inf), fill = NA, alpha= 0.01, color ='red', linewidth = 1.2)+ geom_rect(aes(xmin=as.Date("2014-01-01"), xmax=as.Date("2015-12-31"),ymin=-Inf,ymax=Inf), fill = NA, alpha= 0.01, color = 'red', linewidth = 1.2)+ theme_minimal()+ theme(legend.position = c(0.7, 0.9),legend.title = element_blank(), legend.text = element_text(size = 14), legend.background = element_rect(linetype="solid",colour ="darkblue"), axis.text = element_text(size = 14), axis.title = element_text(size = 15)) # Fig 2 - 1mo and 10yr from daily data ------------------------------------ Mex_long <- melt(Mex_d[,c("Date","MPTBA","GMXN10Y")], id.vars = "Date") ggplot(Mex_long, aes(x = Date, y = value, color = variable)) + geom_line(linewidth = 1.25) + labs(y = "Yield on Mexican govt bonds (in %)", x = element_blank()) + scale_x_date(date_breaks = "2 year", date_labels = "%Y") + scale_color_discrete(labels = c("1 month yield", "10 year yield")) + #scale_color_discrete(labels = c("Overnight yield", "10 year yield")) + geom_rect(aes(xmin=as.Date("2006-09-01"), xmax=as.Date("2008-07-31"),ymin=-Inf,ymax=Inf), fill = NA, alpha= 0.01, color ='red', linewidth = 1.2)+ annotate("text", x = as.Date("2007-07-31"), y = 11, label = expression(rho - 0.081), size = 5 )+ geom_rect(aes(xmin=as.Date("2014-01-01"), xmax=as.Date("2015-12-31"),ymin=-Inf,ymax=Inf), fill = NA, alpha= 0.01, color = 'red', linewidth = 1.2)+ annotate("text", x = as.Date("2014-12-31"), y = 11, label = expression(rho - 0.169), size = 5)+ theme_minimal()+ theme(legend.position = c(0.7, 0.9),legend.title = element_blank(), legend.text = element_text(size = 14), legend.background = element_rect(linetype="solid",colour ="darkblue"), axis.text = element_text(size = 14), axis.title = element_text(size = 15)) # Fig 3 - comparing short term yields ------------------------------------- Date_sub = Mex_w$Date <= as.Date('2015-12-31') & Mex_w$Date >= as.Date('2010-01-01') Mex_long <- melt(Mex_w[Date_sub,c("Date","Tgt_rate","TIIE", "MPTBA")], id.vars = "Date") ggplot(Mex_long, aes(x = Date, y = value, color = variable)) + geom_line(linewidth = 1.25) + labs(y = "Interest rates (in %)", x = element_blank()) + scale_x_date(date_breaks = "2 year", date_labels = "%Y") + scale_color_discrete(labels = c("Policy rate", "TIIE", "1 month yield")) + #scale_color_discrete(labels = c("Overnight yield", "10 year yield")) + geom_vline(xintercept = as.Date("2011-12-31"), color = 'black', linetype = "dashed", linewidth = 1.2) + geom_vline(xintercept = as.Date("2014-01-01"), color = 'black', linetype = "dashed", linewidth = 1.2) + theme_minimal()+ theme(legend.position = c(0.8, 0.9),legend.title = element_blank(), legend.text = element_text(size = 14), legend.background = element_rect(linetype="solid",colour ="darkblue"), axis.text = element_text(size = 14), axis.title = element_text(size = 15)) # Fig 4 - Depicting slope ------------------------------------- Mex_w$`10y-TIIE` = Mex_w$GMXN10Y - Mex_w$TIIE Mex_w$`10y-Tgt` = Mex_w$GMXN10Y - Mex_w$Tgt_rate Mex_w$`10y-1mo` = Mex_w$GMXN10Y - Mex_w$MPTBA Mex_long <- melt(Mex_w[,c("Date" ,"10y-Tgt","10y-TIIE", "10y-1mo")],id.vars = "Date") ggplot(Mex_long, aes(x = Date, y = value, color = variable)) + geom_line(linewidth = 1.25) + labs(y = "Slopes", x = element_blank()) + scale_x_date(date_breaks = "2 year", date_labels = "%Y") + scale_color_discrete(labels = c("10yr - Policy rate", "10yr - TIIE", "10yr - 1 mo")) + #scale_color_discrete(labels = c("Overnight yield", "10 year yield")) + geom_hline(yintercept = 0, color = 'red', linetype = "dashed", linewidth = 1.2) + theme_minimal()+ theme(legend.position = c(0.8, 0.9),legend.title = element_blank(), legend.text = element_text(size = 14), legend.background = element_rect(linetype="solid",colour ="darkblue"), axis.text = element_text(size = 14), axis.title = element_text(size = 15)) # Fig 5 - Slope (trying out spreads for motivation slide) ------------------------------------- Mex_w$`10y-Tgt` = Mex_w$GMXN10Y - Mex_w$Tgt_rate Mex_w$`1mo-Tgt` = Mex_w$MPTBA - Mex_w$Tgt_rate Mex_w$`1mo-TIIE` = Mex_w$MPTBA - Mex_w$TIIE Mex_long <- melt(Mex_w[Mex_w$Date <= as.Date("2023-12-31") & Mex_w$Date >= as.Date("2008-04-01"), c("Date" ,"GMXN10Y","1mo-Tgt")],id.vars = "Date") Mex_long <- melt(Mex_w[Mex_w$Date <= as.Date("2023-12-31") & Mex_w$Date >= as.Date("2008-04-01"), c("Date" ,"1mo-Tgt")],id.vars = "Date") ggplot(Mex_long, aes(x = Date, y = value, color = variable)) + geom_line(linewidth = 1.25) + labs(y = "Slopes", x = element_blank()) + scale_x_date(date_breaks = "2 year", date_labels = "%Y") + #scale_color_discrete(labels = c("10yr - Policy rate", "1mo - Policy rate")) + scale_color_discrete(labels = c("10yrmo - Policy rate")) + geom_hline(yintercept = 0, color = 'red', linetype = "dashed", linewidth = 1.2) + theme_minimal()+ theme(legend.position = c(0.8, 0.9),legend.title = element_blank(), legend.text = element_text(size = 14), legend.background = element_rect(linetype="solid",colour ="darkblue"), axis.text = element_text(size = 14), axis.title = element_text(size = 15)) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |