[Uwgarp-commits] r192 - in pkg/GARPFRM: . R sandbox vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 26 21:28:54 CEST 2014


Author: tfillebeen
Date: 2014-06-26 21:28:54 +0200 (Thu, 26 Jun 2014)
New Revision: 192

Modified:
   pkg/GARPFRM/NAMESPACE
   pkg/GARPFRM/R/discountFactorArbitrage.R
   pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R
   pkg/GARPFRM/vignettes/FixedIncome.lyx
Log:
vignette fixed edited

Modified: pkg/GARPFRM/NAMESPACE
===================================================================
--- pkg/GARPFRM/NAMESPACE	2014-06-16 21:15:08 UTC (rev 191)
+++ pkg/GARPFRM/NAMESPACE	2014-06-26 19:28:54 UTC (rev 192)
@@ -87,6 +87,7 @@
 export(rollSD)
 export(rollSimpleVolatility)
 export(simpleVolatility)
+export(spotForwardRates)
 export(tangentPortfolio)
 export(uvGARCH)
 export(vasicekPrice)

Modified: pkg/GARPFRM/R/discountFactorArbitrage.R
===================================================================
--- pkg/GARPFRM/R/discountFactorArbitrage.R	2014-06-16 21:15:08 UTC (rev 191)
+++ pkg/GARPFRM/R/discountFactorArbitrage.R	2014-06-26 19:28:54 UTC (rev 192)
@@ -178,7 +178,31 @@
   return(rate)
 }
 
+#' Estimate spot and forward rates
+#' 
+#' This function calculates the forward or forward rates given an discount factors 
+#' and time increments
+#' @param time increments of time when discount factors are estimated
+#' @param DF discount factor for during time increments
+#' @author TF
+#' @export
+spotForwardRates = function(time, DF){
+  if(length(time) != length(DF)) stop("both time and DF parameter need to be of the same length")
+spotRates = matrix(0,length(time),1)
+for(i in 1:(length(time))){
+  spotRates[i] = (2-2*DF[i]^(1/(2*time[i]))) / DF[i]^(1/(2*time[i]))
+}
 
+forwardRates = matrix(0,length(time),1)
+forwardRates[1] = spotRates[1]
+for(j in 1:(length(time)-1)){
+  forwardRates[j+1] = (DF[j]/DF[j+1] - 1) *2
+}
+rates = cbind(spotRates, forwardRates)
+colnames(rates)= cbind("Spot","Forward")
+return(rates)
+}
+
 ### Modelling a Zero-Coupon Bond (ZCB)
 #' There are three main types of yield curve shapes: normal, inverted and flat (or humped)
 #' Estimate Vasicek zero-coupon bond to be used in term structure

Modified: pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R
===================================================================
--- pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R	2014-06-16 21:15:08 UTC (rev 191)
+++ pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R	2014-06-26 19:28:54 UTC (rev 192)
@@ -107,4 +107,9 @@
 years = ccRate$years
 rate = ccRate$ccRate
 # Plot of continuously compounded spot rates
-plot(x=years, y=rate, type="l", ylab="Rate", xlab="Time to Maturity", main="Term Structure: Spot Rates")
\ No newline at end of file
+plot(x=years, y=rate, type="l", ylab="Rate", xlab="Time to Maturity", main="Term Structure: Spot Rates")
+
+# Spot, Forward, and Par Rates
+DF = c(0.996489, 0.991306, 0.984484, 0.975616, 0.964519)
+time = seq(from=0.5, to=2.5, by=0.5)
+

Modified: pkg/GARPFRM/vignettes/FixedIncome.lyx
===================================================================
(Binary files differ)



More information about the Uwgarp-commits mailing list