[R] Odp: while loop problems

Petr PIKAL petr.pikal at precheza.cz
Wed Jun 1 10:56:57 CEST 2011


Hi

Without reproducible example or some code I wonder if anybody can give you 
some advice.

As a wild guess do you use if function correctly i.e. input is "length one 
logical vector" ?

And maybe you do not need loop at all

Regards
Petr

> 
> [R] while loop problems
> 
> Hi , i am trying to get this loop in my r program to work but it is
> not giving me the results that I desire. I am trying to model an
> insurance contract where there are n securities that have a fixed
> likelihood of default vector(data[i,2]) and a payout
> vector(data[i,1]).
> 
> i need to price the value of stop losses at the security level and at
> the portfolio level. to do this i created two while loops for the
> conditional vectors of each level (which will be inputed into the
> function by the user) one while loop to scan through the various
> securities and a final one to model the various scenarios(i.e. monte
> carlo). i tried to Use R's matrix capabilities to help organize the
> results.
> 
> the problem with this code is that the if statement behaves oddly, not
> activating and filtering correctly. this causes the program to be slow
> and provide bad results. it fills the individual protection column
> always rather than conditioning it on the likelihood
> vector(data[i,2]). there is a lot of moving parts but overall it is a
> simple model.
> 
> my end result is to have a vector containing the accumulated values of
> insurance for each type of stop loss(i.e. idiosyncratic and
> aggregate).
> 
> Thanks, Alon.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list