diff options
Diffstat (limited to 'tranche_functions.R')
| -rw-r--r-- | tranche_functions.R | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/tranche_functions.R b/tranche_functions.R index bb74f221..e1f0ab91 100644 --- a/tranche_functions.R +++ b/tranche_functions.R @@ -390,18 +390,22 @@ dqnorm <- function(x){ fit.prob <- function(Z, w, rho, p0){
## if the weights are not perfectly gaussian, find the probability p such
## E_w(shockprob(p, rho, Z)) = p0
- eps <- 1e-12
- dp <- (crossprod(shockprob(p0,rho,Z),w)-p0)/crossprod(dshockprob(p0,rho,Z),w)
- p <- p0
- while(abs(dp) > eps){
- dp <- (crossprod(shockprob(p,rho,Z),w)-p0)/crossprod(dshockprob(p,rho,Z),w)
- phi <- 1
- while ((p-phi*dp)<0 || (p-phi*dp)>1){
- phi <- 0.8*phi
+ if(p0==0){
+ return(0)
+ }else{
+ eps <- 1e-12
+ dp <- (crossprod(shockprob(p0,rho,Z),w)-p0)/crossprod(dshockprob(p0,rho,Z),w)
+ p <- p0
+ while(abs(dp) > eps){
+ dp <- (crossprod(shockprob(p,rho,Z),w)-p0)/crossprod(dshockprob(p,rho,Z),w)
+ phi <- 1
+ while ((p-phi*dp)<0 || (p-phi*dp)>1){
+ phi <- 0.8*phi
+ }
+ p <- p - phi*dp
}
- p <- p - phi*dp
+ return(p)
}
- return(p)
}
stochasticrecov <- function(R, Rtilde, Z, w, rho, porig, pmod){
|
