aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/tranche_functions.R30
1 files changed, 15 insertions, 15 deletions
diff --git a/R/tranche_functions.R b/R/tranche_functions.R
index e166b666..175b696d 100644
--- a/R/tranche_functions.R
+++ b/R/tranche_functions.R
@@ -36,9 +36,9 @@ tranche.cl.scenarios <- function(l, r, cs, K1, K2, scaled=FALSE){
## if scaled is TRUE, scale it by the size of the tranche (K2-K1)
## can make use of the fact that the loss and recov distribution are
## truncated (in that case nrow(L) != Ngrid
- if(K1==K2){
+ if(K1 == K2) {
return( 0 )
- }else{
+ } else {
size <- K2 - K1 - trancheloss(l, K1, K2) - trancherecov(r, K1, K2)
sizeadj <- as.numeric(0.5 * (size + c(K2-K1, size[-length(size)])))
if(scaled){
@@ -50,17 +50,17 @@ tranche.cl.scenarios <- function(l, r, cs, K1, K2, scaled=FALSE){
}
funded.tranche.pv <- function(L, R, cs, K1, K2, scaled = FALSE){
- if(K1==K2){
+ if(K1 == K2) {
return(0)
- }else{
+ } else {
size <- K2 - K1 -trancheloss(L, K1, K2) - trancherecov(R, K1, K2)
sizeadj <- as.numeric(0.5 * (size + c(K2-K1, size[-length(size)])))
interest <- crossprod(sizeadj * cs$coupons, cs$df)
principal <- diff(c(0, trancherecov(R, K1, K2)))
principal[length(principal)] <- principal[length(principal)] + size[length(size)]
principal <- crossprod(cs$df, principal)
- if(scaled){
- pv <- (interest + principal)/(K2-K1)
+ if(scaled) {
+ pv <- (interest + principal) / (K2-K1)
}else{
pv <- (interest + principal)
}
@@ -71,15 +71,15 @@ funded.tranche.pv <- function(L, R, cs, K1, K2, scaled = FALSE){
tranche.pl <- function(L, cs, K1, K2, Ngrid=nrow(L), scaled=FALSE){
## computes the protection leg of a tranche
## if scaled
- if(K1==K2){
+ if(K1 == K2) {
return(0)
- }else{
+ } else {
support <- seq(0, 1, length=Ngrid)[1:nrow(L)]
cf <- K2 - K1 - crossprod(trancheloss(support, K1, K2), L)
cf <- c(K2 - K1, cf)
- if(scaled){
+ if(scaled) {
return( 1/(K2-K1) * crossprod(diff(cf), cs$df))
- }else{
+ } else {
return( crossprod(diff(cf), cs$df))
}
}
@@ -88,14 +88,14 @@ tranche.pl <- function(L, cs, K1, K2, Ngrid=nrow(L), scaled=FALSE){
tranche.pl.scenarios <- function(l, cs, K1, K2, scaled=FALSE){
## computes the protection leg of a tranche
## if scaled
- if(K1==K2){
+ if(K1==K2) {
return(0)
- }else{
+ } else {
cf <- K2 - K1 - trancheloss(l, K1, K2)
cf <- c(K2 - K1, cf)
- if(scaled){
+ if(scaled) {
return( 1/(K2-K1) * as.numeric(crossprod(diff(cf), cs$df)))
- }else{
+ } else {
return( as.numeric(crossprod(diff(cf), cs$df)))
}
}
@@ -225,7 +225,7 @@ adjust.skew <- function(index1, index2, method=c("ATM", "TLP", "PM")) {
index2=index2, el2=el2, K2=K2val)
K1eq <- c(K1eq, prog$minimum)
}
- } else if (method=="PM") {
+ } else if (method == "PM") {
K1eq <- c()
m <- max(K2) + 0.25
for(K2val in K2) {