[Uwgarp-commits] r199 - in pkg/GARPFRM: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 30 02:00:04 CEST 2014


Author: tfillebeen
Date: 2014-06-30 02:00:03 +0200 (Mon, 30 Jun 2014)
New Revision: 199

Modified:
   pkg/GARPFRM/R/discountFactorArbitrage.R
   pkg/GARPFRM/R/riskMetricsAndHedges.R
   pkg/GARPFRM/man/PCA.Rd
   pkg/GARPFRM/man/bondConvexity.Rd
   pkg/GARPFRM/man/bondDuration.Rd
   pkg/GARPFRM/man/bondFullPrice.Rd
   pkg/GARPFRM/man/bondPrice.Rd
   pkg/GARPFRM/man/bondSpec.Rd
   pkg/GARPFRM/man/bondYTM.Rd
   pkg/GARPFRM/man/compoundingRate.Rd
   pkg/GARPFRM/man/discountFactor.Rd
   pkg/GARPFRM/man/getLoadings.Rd
   pkg/GARPFRM/man/getWeights.Rd
   pkg/GARPFRM/man/linearHedge.Rd
   pkg/GARPFRM/man/plot.PCA.Rd
   pkg/GARPFRM/man/ytmSolve.Rd
Log:
Examples added

Modified: pkg/GARPFRM/R/discountFactorArbitrage.R
===================================================================
--- pkg/GARPFRM/R/discountFactorArbitrage.R	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/R/discountFactorArbitrage.R	2014-06-30 00:00:03 UTC (rev 199)
@@ -14,7 +14,10 @@
 #' @param m compounding frequency
 #' @param couponRate rate the coupon pays
 #' @return a \code{bond} object with the bond data used for pricing
-#' @author TF
+#' @examples
+#' time = seq(from=0.5, to=2, by=0.5)
+#' bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+#' @author Thomas Fillebeen
 #' @export
 bondSpec = function(time=seq(from=0.5,to=2,by=0.5), face=100, m=2, couponRate=0.01){
   if(!all(diff(time) == (1/m))) stop("misspecification of sequence of time and compounding frequency")
@@ -43,7 +46,11 @@
 #' @param bond a \code{discountFactorArbitrage} object
 #' @param discountCurve vector of discount rates
 #' @return price of the bond
-#' @author TF
+#' @examples
+#' time = seq(from=0.5, to=2, by=0.5)
+#' bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+#' price = bondPrice(bond,DF)
+#' @author Thomas Fillebeen
 #' @export
 bondPrice = function(bond, discountCurve){
   if(!is.bond(bond)) stop("bond must be an object of class 'bond'")
@@ -68,7 +75,9 @@
 #' @param bond a \code{discountFactorArbitrage} object
 #' @param price  of a bond
 #' @return cashFlow of a bond
-#' @author TF
+#' @examples
+#' solve(cashFlow) %*% price
+#' @author Thomas Fillebeen
 #' @export
 discountFactor = function(price, cashFlow){
   DF = solve(cashFlow) %*% price
@@ -104,7 +113,7 @@
 #' bondFullPrice(bond, y1, 8, t0, t1, tn)$dirty
 #' bondFullPrice(bond, y1, 8, t0, t1, tn)$accruedInterest
 #' @return price of the bond: clean, dirty and accrued interest
-#' @author TF
+#' @author Thomas Fillebeen
 #' @export
 bondFullPrice = function(bond, yield, cashFlowPd, t0, t1, currentDate){
   compoundPd = bond$m
@@ -137,7 +146,7 @@
 #' @param m compounding frequency
 #' @param face face value
 #' @return continuously compounding rates
-#' @author TF
+#' @author Thomas Fillebeen
 #' @export
 compoundingRate = function(dat, initialDate=as.Date("1995-05-15"), m, face=100){
   # Convert the dates to a date class
@@ -202,7 +211,12 @@
 #' and time increments
 #' @param time increments of time when discount factors are estimated
 #' @param DF discount factor for during time increments
-#' @author TF
+#' @examples 
+#' 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]))
+#' }
+#' @author Thomas Fillebeen
 #' @export
 spotForwardRates = function(time, DF){
   if(length(time) != length(DF)) stop("both time and DF parameter need to be of the same length")
@@ -232,7 +246,7 @@
 #' @param theta long-term reversion yield
 #' @param sigma randomness parameter. Modelled after Brownan Motion
 #' @return t length of time modelled for
-#' @author TF
+#' @author Thomas Fillebeen
 #' @export
 vasicekPrice = function(r, k, theta, sigma, maturity){
     mean = (1/k)*(1 - exp(-maturity*k)) 
@@ -249,7 +263,7 @@
 #' @param theta long-term reversion yield
 #' @param sigma randomness parameter. Modelled after Brownan Motion
 #' @return t length of time modelled for
-#' @author TF
+#' @author Thomas Fillebeen
 #' @export
 yieldCurveVasicek = function(r, k, theta, sigma, maturity){
   n = length(r)

Modified: pkg/GARPFRM/R/riskMetricsAndHedges.R
===================================================================
--- pkg/GARPFRM/R/riskMetricsAndHedges.R	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/R/riskMetricsAndHedges.R	2014-06-30 00:00:03 UTC (rev 199)
@@ -9,6 +9,11 @@
 #' @param discountCurve vector of discount rates
 #' @param percentChangeYield optional elasticity measure 
 #' @return duration of the bond
+#' @examples
+#' time = seq(from=0.5, to=2, by=0.5)
+#' bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+#' mDuration = bondDuration(bond,DF)
+#' @author Thomas Fillebeen
 #' @export
 bondDuration <- function(bond, discountCurve, percentChangeYield = 0){
   # Get data from the bond and discount curve
@@ -40,6 +45,11 @@
 #' @param bond a \code{bond} object in discountFactorArbitrage
 #' @param discountCurve vector of discount rates
 #' @return convexity of the bond
+#' @examples
+#' time = seq(from=0.5, to=2, by=0.5)
+#' bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+#' convexity = bondConvexity(bond,DF)
+#' @author Thomas Fillebeen
 #' @export
 bondConvexity <- function(bond, discountCurve){
   # Get data from the bond and discount curve
@@ -67,6 +77,11 @@
 #' @param bond a \code{bond} object
 #' @param discountCurve vector of discount rates
 #' @return yield to maturity of the bond
+#' @examples
+#' time = seq(from=0.5, to=2, by=0.5)
+#' bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+#' bondYTM(bond,DF)
+#' @author Thomas Fillebeen
 #' @export
 bondYTM <- function(bond, discountCurve){
   # First step is to calculate the price based on the discount curve
@@ -96,6 +111,7 @@
 #' @param face is the face value
 #' @param targetPrice is the price of the bond
 #' @return Absolute value of difference between the price and the present value
+#' @author Thomas Fillebeen
 #' @export
 ytmSolve <- function(ytm, couponRate, m, nPayments, face, targetPrice){
   C <- face * couponRate / m
@@ -118,6 +134,7 @@
 #' @param regressand a \code{bond} object in discountFactorArbitrage
 #' @param regressor the right hand side
 #' @return delta of the hedge
+#' @author Thomas Fillebeen
 #' @export
 linearHedge <- function(regressand, regressor){
     deltas = matrix(0,nrow=1,ncol= ncol(regressor))
@@ -135,6 +152,7 @@
 #' @param nfactors number of components to extract
 #' @param rotate "none", "varimax", "quatimax", "promax", "oblimin", "simplimax", and "cluster" are possible rotations/transformations of the solution.
 #' @return pca object loadings
+#' @author Thomas Fillebeen
 #' @export
 PCA <- function(data, nfactors, rotate = "none"){
   pca = principal(data, nfactors, rotate="none")
@@ -145,7 +163,7 @@
 #' Retrieve PCA loadings
 #' 
 #' @param object is a pca object
-#' @author TF
+#' @author Thomas Fillebeen
 #' @export 
 getLoadings <- function(object){
 loadings = object$loadings
@@ -155,7 +173,7 @@
 #' Retrieve PCA weights
 #' 
 #' @param object is a pca object
-#' @author TF
+#' @author Thomas Fillebeen
 #' @export 
 getWeights <- function(object){
   weights = object$weight
@@ -171,7 +189,7 @@
 #' @param number specify the nunber of loadings
 #' @param \dots passthrough parameters to \code{\link{plot}}.
 #' @param main a main title for the plot
-#' @author TF
+#' @author Thomas Fillebeen
 #' @method plot PCA
 #' @S3method plot PCA
 plot.PCA <- function(x, y, ..., main="Beta from PCA regression"){

Modified: pkg/GARPFRM/man/PCA.Rd
===================================================================
--- pkg/GARPFRM/man/PCA.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/PCA.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -19,4 +19,7 @@
 This function estimates the delta for hedging a particular bond
 given bond data
 }
+\author{
+Thomas Fillebeen
+}
 

Modified: pkg/GARPFRM/man/bondConvexity.Rd
===================================================================
--- pkg/GARPFRM/man/bondConvexity.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/bondConvexity.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -17,4 +17,12 @@
 This function estimates the convexity of a fixed rate coupon bond
 given the discount curve and bond data.
 }
+\examples{
+time = seq(from=0.5, to=2, by=0.5)
+bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+convexity = bondConvexity(bond,DF)
+}
+\author{
+Thomas Fillebeen
+}
 

Modified: pkg/GARPFRM/man/bondDuration.Rd
===================================================================
--- pkg/GARPFRM/man/bondDuration.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/bondDuration.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -20,4 +20,12 @@
 given the discount curve and bond data. The modified duration is calculated
 using the continuously compounded yield
 }
+\examples{
+time = seq(from=0.5, to=2, by=0.5)
+bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+mDuration = bondDuration(bond,DF)
+}
+\author{
+Thomas Fillebeen
+}
 

Modified: pkg/GARPFRM/man/bondFullPrice.Rd
===================================================================
--- pkg/GARPFRM/man/bondFullPrice.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/bondFullPrice.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -46,6 +46,6 @@
 bondFullPrice(bond, y1, 8, t0, t1, tn)$accruedInterest
 }
 \author{
-TF
+Thomas Fillebeen
 }
 

Modified: pkg/GARPFRM/man/bondPrice.Rd
===================================================================
--- pkg/GARPFRM/man/bondPrice.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/bondPrice.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -17,7 +17,12 @@
 This function calculates the price of a fixed rate coupon bond given the
 discount curve and bond data. First it converts the discountCurve into CF
 }
+\examples{
+time = seq(from=0.5, to=2, by=0.5)
+bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+price = bondPrice(bond,DF)
+}
 \author{
-TF
+Thomas Fillebeen
 }
 

Modified: pkg/GARPFRM/man/bondSpec.Rd
===================================================================
--- pkg/GARPFRM/man/bondSpec.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/bondSpec.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -21,7 +21,11 @@
 \description{
 Created a bond object \code{bond.spec} with data for bond specification.
 }
+\examples{
+time = seq(from=0.5, to=2, by=0.5)
+bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+}
 \author{
-TF
+Thomas Fillebeen
 }
 

Modified: pkg/GARPFRM/man/bondYTM.Rd
===================================================================
--- pkg/GARPFRM/man/bondYTM.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/bondYTM.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -17,4 +17,12 @@
 This function calculates the yield to maturity of a fixed rate coupon bond
 given the discount curve and bond data.
 }
+\examples{
+time = seq(from=0.5, to=2, by=0.5)
+bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+bondYTM(bond,DF)
+}
+\author{
+Thomas Fillebeen
+}
 

Modified: pkg/GARPFRM/man/compoundingRate.Rd
===================================================================
--- pkg/GARPFRM/man/compoundingRate.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/compoundingRate.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -22,6 +22,6 @@
 with specific format, date of reference coumpounding frequency, and face value
 }
 \author{
-TF
+Thomas Fillebeen
 }
 

Modified: pkg/GARPFRM/man/discountFactor.Rd
===================================================================
--- pkg/GARPFRM/man/discountFactor.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/discountFactor.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -17,7 +17,10 @@
 This function calculates the discountFactor (DF) given price
 and cashFlows.
 }
+\examples{
+solve(cashFlow) \%*\% price
+}
 \author{
-TF
+Thomas Fillebeen
 }
 

Modified: pkg/GARPFRM/man/getLoadings.Rd
===================================================================
--- pkg/GARPFRM/man/getLoadings.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/getLoadings.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -12,6 +12,6 @@
 Retrieve PCA loadings
 }
 \author{
-TF
+Thomas Fillebeen
 }
 

Modified: pkg/GARPFRM/man/getWeights.Rd
===================================================================
--- pkg/GARPFRM/man/getWeights.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/getWeights.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -12,6 +12,6 @@
 Retrieve PCA weights
 }
 \author{
-TF
+Thomas Fillebeen
 }
 

Modified: pkg/GARPFRM/man/linearHedge.Rd
===================================================================
--- pkg/GARPFRM/man/linearHedge.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/linearHedge.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -17,4 +17,7 @@
 This function estimates the delta for hedging a particular bond
 given bond data
 }
+\author{
+Thomas Fillebeen
+}
 

Modified: pkg/GARPFRM/man/plot.PCA.Rd
===================================================================
--- pkg/GARPFRM/man/plot.PCA.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/plot.PCA.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -20,6 +20,6 @@
 Plot a fitted PCA object
 }
 \author{
-TF
+Thomas Fillebeen
 }
 

Modified: pkg/GARPFRM/man/ytmSolve.Rd
===================================================================
--- pkg/GARPFRM/man/ytmSolve.Rd	2014-06-29 23:41:29 UTC (rev 198)
+++ pkg/GARPFRM/man/ytmSolve.Rd	2014-06-30 00:00:03 UTC (rev 199)
@@ -25,4 +25,7 @@
 This function solves for the yield to maturity of a fixed rate coupon bond
 given the discount curve and bond data.
 }
+\author{
+Thomas Fillebeen
+}
 



More information about the Uwgarp-commits mailing list