diff options
Diffstat (limited to 'R/intex_deal_functions.R')
| -rw-r--r-- | R/intex_deal_functions.R | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/R/intex_deal_functions.R b/R/intex_deal_functions.R index bb8c09d3..640b7cd0 100644 --- a/R/intex_deal_functions.R +++ b/R/intex_deal_functions.R @@ -283,20 +283,40 @@ recoveryfromscenarios <- function(scenariosd, scenariosr){ ## compute the forward recovery rate based on the term
## structure of recovery scenarios
## we run into trouble for very stressed scenarios
- ## this code should cap the scenarios at 0 it this happens
+ ## this code should cap the scenarios at 0 if this happens
intexrecov <- matrix(0, n.scenarios, ncol(scenariosr))
for(i in 1:n.scenarios){
current <- 1
intexrecov[i,1] <- scenariosr[i,1]
for(t in 2:ncol(scenariosr)){
w <- scenariosd[i,current]/scenariosd[i,t]
- if(scenariosr[i,t]-w*scenariosr[i,current]>=0){
- intexrecov[i,t] <- (scenariosr[i,t]-w*scenariosr[i,current])/(1-w)
- current <- current+1
- }else{
- intexrecov[i,t] <- 0
- }
+ ## if(scenariosr[i,t]-w*scenariosr[i,current]>=0){
+ ## intexrecov[i,t] <- (scenariosr[i,t]-w*scenariosr[i,current])/(1-w)
+ ## current <- current+1
+ ## }else{
+ ## intexrecov[i,t] <- 0
+ ## }
+ intexrecov[i,t] <- (scenariosr[i,t]-w*scenariosr[i,current])/(1-w)
+ current <- current + 1
}
}
return(intexrecov)
}
+
+severityfromscenarios <- function(scenariosd, scenariosr){
+ ## compute the forward recovery rate based on the term
+ ## structure of recovery scenarios
+ ## we run into trouble for very stressed scenarios
+ ## this code should cap the scenarios at 0 if this happens
+ intexseverity <- matrix(0, n.scenarios, ncol(scenariosr))
+ for(i in 1:n.scenarios){
+ current <- 1
+ intexseverity[i,1] <- 1-scenariosr[i,1]
+ for(t in 2:ncol(scenariosr)){
+ w <- scenariosd[i,current]/scenariosd[i,t]
+ intexseverity[i,t] <- 1 - (scenariosr[i,t]-w*scenariosr[i,current])/(1-w)
+ current <- current+1
+ }
+ }
+ return(intexseverity)
+}
|
