[Uwgarp-commits] r189 - pkg/GARPFRM/sandbox
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jun 14 01:32:18 CEST 2014
Author: tfillebeen
Date: 2014-06-14 01:32:18 +0200 (Sat, 14 Jun 2014)
New Revision: 189
Modified:
pkg/GARPFRM/sandbox/principleComponent.R
pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R
Log:
duration hedge
Modified: pkg/GARPFRM/sandbox/principleComponent.R
===================================================================
--- pkg/GARPFRM/sandbox/principleComponent.R 2014-06-13 16:37:10 UTC (rev 188)
+++ pkg/GARPFRM/sandbox/principleComponent.R 2014-06-13 23:32:18 UTC (rev 189)
@@ -2,10 +2,33 @@
library(psych)
library(GPArotation)
+######### 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
+time = seq(from=0.5, to=2, by=0.5)
+# First define a bond object to be used throughout the analysis, where m is the compound frequency
+bond_1 = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+# Duration measures the effect of a small parallel shift in the yield curve
+mDuration_1 = bondDuration(bond_1,DF_1)
+# # 2: Initialize the Discount Factors (DF)
+DF_2 = 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_2 = bondSpec(time, face=100, m=2, couponRate = 0.0475)
+# 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
+
+
+# Load Data for historcal analysis tools
data(crsp.short)
data = largecap.ts[,2:6]
head(data)
+
# Empirical application: Linear hedge estimation
# OLS Level-on-Level regression
deltas = linearHedge(data[,1],data[,2:5])
@@ -16,11 +39,6 @@
hedgedInstruments = data%*%deltas
plot(hedgedInstruments, type="l", main = "Hedged Price Difference", xlab="Time",ylab="Difference")
-
-######### Applying duration as a hedge######## TO-DO
-
-
-
# Have a single, empirical description of the behavior of the term structure that can be applied across all
# assets. Principal Compnents (PCs) provide such an emperical description
# Retain components that combined account for x% of the cumulative variance
Modified: pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R
===================================================================
--- pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R 2014-06-13 16:37:10 UTC (rev 188)
+++ pkg/GARPFRM/sandbox/test_discountFactorArbitrage.R 2014-06-13 23:32:18 UTC (rev 189)
@@ -4,7 +4,7 @@
data(bonds)
-# The Cash Flows from Fixed-Rate Government Coupon Bonds
+## The Cash Flows from Fixed-Rate Government Coupon Bonds
# Discount Factors and the Law of One Price
# Initialize: The Cash Flows from Fixed-Rate: treasury bonds ticking in quarters
cashFlow = rbind(c(100, 0, 0, 0), c(2 + 7/8, 102 + 7/8, 0, 0), c(3 + 3/4, 3 + 3/4, 103 + 3/4, 0), c(3 + 3/4, 3 + 3/4, 3 + 3/4, 103 + 3/4))
@@ -17,7 +17,7 @@
(cashFlow%*%price)/100
-# Estimate bondPrice
+## Estimate bondPrice
# Choose a 2 year bond with semiannual payments to match number of bond prices and CFs
time = seq(from=0.5, to=2, by=0.5)
# First define a bond object to be used throughout the analysis, where m is the compound frequency
@@ -29,6 +29,7 @@
bondYTM(bond,DF)
# Duration measures the effect of a small parallel shift in the yield curve
+# if rate goes up 10 basis points the relative P&L will change by mDuration*0.1%
mDuration = bondDuration(bond,DF)
# Duration plus convexity measure the effect of a larger parallel shift in the yield curve
# Note however, they do not measure the effect of non-parallel shifts
@@ -76,7 +77,7 @@
abline(h = theta, col="red", lty=2)
-# Appliation: Idiosyncratic Pricing of US Treasury Notes and Bonds
+## Appliation: Idiosyncratic Pricing of US Treasury Notes and Bonds
t0 = as.Date("2013-08-15")
t1 = as.Date("2014-02-15")
tn = as.Date("2013-10-04")
@@ -89,7 +90,7 @@
bondFullPrice(bond, y1, 8, t0, t1, tn)$accruedInterest
-# Estimating the term structure: compounded rates from discount factors
+## Estimating the term structure: compounded rates from discount factors
# Ulitzing data in the following format: Cusip, IssueDate, MaturityDate, Name, Coupon, Bid/Ask
head(dat)
ccRate = compoundingRate(dat, initialDate=as.Date("2000-05-15"), m=4, face=100)
@@ -97,4 +98,4 @@
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")
+plot(x=years, y=rate, type="l", ylab="Rate", xlab="Time to Maturity", main="Term Structure: Spot Rates")
\ No newline at end of file
More information about the Uwgarp-commits
mailing list