lundi 1 mars 2021

Return simulated pricing result

I am quite new to R and try to do a pricing simulation. The goal is to have a vector with length n, that gives a percentage for the coupon that will be received. When I use print, I get exactly the result I want. However, for my subsequent calculations I cannot proceed with results in print format. I tried replacing it with return but this just gives me one result.

Any input is appreciated.

(package used for rgpd is POT)

bond_coupon <- function(n, l) {
     events <- rpois(n, l) #simulates the rate of arrival according to a Poisson process
     for (i in 1:length(events)){
         cat <- rgpd(events[i], loc=1000, scale=100, shape=1) #simulates the severance of each event
         if(events[i]>1){
             coupon <- prod(1-((cat-1000)/cat))
         } else if(events[i]==1){
             coupon<- 1-((cat-1000)/cat)
         } else{
             coupon<- 1.00
         }
         print(coupon)
     }
 }



Aucun commentaire:

Enregistrer un commentaire