[Uwgarp-commits] r190 - in pkg/GARPFRM: R sandbox
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jun 14 01:42:56 CEST 2014
Author: tfillebeen
Date: 2014-06-14 01:42:55 +0200 (Sat, 14 Jun 2014)
New Revision: 190
Modified:
pkg/GARPFRM/R/riskMetricsAndHedges.R
pkg/GARPFRM/sandbox/principleComponent.R
pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R
Log:
sensitivity analysis
Modified: pkg/GARPFRM/R/riskMetricsAndHedges.R
===================================================================
--- pkg/GARPFRM/R/riskMetricsAndHedges.R 2014-06-13 23:32:18 UTC (rev 189)
+++ pkg/GARPFRM/R/riskMetricsAndHedges.R 2014-06-13 23:42:55 UTC (rev 190)
@@ -18,7 +18,7 @@
face = bond$face
time = bond$time
# Calculate the ytm
- ytm = bondYTM(bond=bond, discountCurve=discountCurve + percentChangeYield)
+ ytm = bondYTM(bond=bond, discountCurve=discountCurve) + percentChangeYield
# Convert to continuously compounded rate
y_c = m * log(1 + ytm / m)
# Get the cashflows of coupon amounts and face value
Modified: pkg/GARPFRM/sandbox/principleComponent.R
===================================================================
--- pkg/GARPFRM/sandbox/principleComponent.R 2014-06-13 23:32:18 UTC (rev 189)
+++ pkg/GARPFRM/sandbox/principleComponent.R 2014-06-13 23:42:55 UTC (rev 190)
@@ -2,7 +2,7 @@
library(psych)
library(GPArotation)
-######### Applying duration as a hedge
+# Applying duration as a hedge
# #1: Initialize the Discount Factors (DF)
DF_1 = rbind(0.968,0.9407242,0.9031545,0.8739803)
# Choose a 2 year bond with semiannual payments to match number of bond prices and CFs
@@ -20,7 +20,8 @@
# Duration measures the effect of a small parallel shift in the yield curve
mDuration_2 = bondDuration(bond_2,DF_2)
# Hedging Ratio: for every bond_2 used there needs to be hedgeRatio amount of bond_1s
-hedgeRatio = mDuration_2/mDuration_1
+# If you hold the portfolio bond_2, you want to sell hedgeRatio units of bonds
+hedgeRatio = - mDuration_2/mDuration_1
# Load Data for historcal analysis tools
Modified: pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R
===================================================================
--- pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R 2014-06-13 23:32:18 UTC (rev 189)
+++ pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R 2014-06-13 23:42:55 UTC (rev 190)
@@ -35,9 +35,6 @@
# Note however, they do not measure the effect of non-parallel shifts
convexity = bondConvexity(bond,DF)
-# Measure a 10% increase in yield on duration
-newmDuration = bondDuration(bond,DF, 0.1)
-
## Example with a longer compounding time sequence:
# Yields of bond with varying coupons over Estimation and Plot
# Utilizing a discount factor trable rewrite DF 10 years semiannually
@@ -48,7 +45,18 @@
bond = bondSpec(time, face=100, m=2, couponRate = 0.04)
bondYTM(bond,DF)
+# Illustrating elasticity of YTM: measure 1% and 10% increase in yield on duration
+DF = rbind(0.95434,0.9434,0.917232,0.89,0.85678,0.8396,0.81242,0.7921,0.7693,0.7473,0.7298,0.7050)
+# Choose a 2 year bond with semiannual payments to match number of bond prices and CFs
+time = seq(from=0.5, to=6, by=0.5)
+# First define a bond object to be used throughout the analysis, where m is the compound frequency
+bond = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+# Duration measures the effect of a small parallel shift in the yield curve
+mDuration = bondDuration(bond,DF)
+mDuration = bondDuration(bond,DF,0.01)
+mDuration = bondDuration(bond,DF,0.1)
+
### Valuation and Risk Model Section- Yield Curve Shapes
# Vasicek Modeling to illustrate different yield curve calibrations
# Initialize Model
More information about the Uwgarp-commits
mailing list