aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/interpweights.R12
-rw-r--r--R/load_cf.R5
2 files changed, 10 insertions, 7 deletions
diff --git a/R/interpweights.R b/R/interpweights.R
index c8702cdc..57995c89 100644
--- a/R/interpweights.R
+++ b/R/interpweights.R
@@ -8,10 +8,10 @@ interpweights <- function(w, v1, v2){
}
interpvalues <- function(w, v, neww){
- ## Given a distribution D=(w,v), compute new weights
+ ## Given a distribution D=(w,v), compute new values
## such that Dnew=(neww, newv) equals D in distribution
cumw <- cumsum(w)
- cdf <- splinefun(v, cumw, method="monoH.FC")
+ cdf <- splinefun(v, cumw, method="hyman")
eps <- 1e-3
newv <- rep(0, length(neww))
cumneww <- cumsum(neww)
@@ -31,8 +31,8 @@ interpvalues <- function(w, v, neww){
}
mid <- (lo+hi)/2
iter <- 0
- while(abs(cdf(mid)-cumneww[i])>eps){
- if(cdf(mid)>cumneww[i]){
+ while(abs(cdf(mid) - cumneww[i])>eps){
+ if(cdf(mid) > cumneww[i]){
hi <- mid
}else{
lo <- mid
@@ -48,8 +48,8 @@ interpvalues.distr <- function(w, v, neww){
## same as interpvalues, but using the distr
## package. need to check how good it is
require(distr)
- D <- DiscreteDistribution(w, v)
- return( q(D)(neww) )
+ D <- DiscreteDistribution(v, w)
+ return( q(D)(cumsum(neww)) )
}
adjust_scenario <- function(scenario, epsilon){
diff --git a/R/load_cf.R b/R/load_cf.R
index df70e277..26cf22e9 100644
--- a/R/load_cf.R
+++ b/R/load_cf.R
@@ -283,6 +283,7 @@ getcusipcf <- function(params, cfdata, dist, tradedate=Sys.Date()){
return(cusipdata)
}
+
compute.delta <- function(indexdist, dealdata, cusip.pv, K1=0, K2=1){
dealweight <- dealdata$weight
dealprice <- dealdata$price
@@ -292,7 +293,9 @@ compute.delta <- function(indexdist, dealdata, cusip.pv, K1=0, K2=1){
scenariosr <- matrix(0, length(dealweight), nT)
for(t in 1:nT){
scenariosl[,t] <- interpvalues(indexdist$L[,t], seq(0, 1, length=Ngrid), dealweight)
- scenariosr[,t] <- interpvalues(indexdist$R[,t], seq(0, 1, length=Ngrid), dealweight)
+ ## numerical artefact, but we want scenariosr[i,] + scenariosl[i,] <= 1 at all times
+ scenariosr[,t] <- pmin(interpvalues(indexdist$R[,t], seq(0, 1, length=Ngrid), dealweight),
+ 1-scenariosl[,t])
}
## we assume the index is fully funded - need to be changed depending
## on how we fund the swaps (hence floating coupon instead of fixed)