[R-SIG-Finance] Simulating inhomogeneous Poisson process without loop

Harun Ozkan harunozkan at gmail.com
Mon Jul 4 01:57:37 CEST 2011



dt=.01;
t=seq(0, .5, by=dt)
apply(matrix(t),  1,  function (x)  { rbinom(1,1,prob=x  )} )

would produce a  series of Bernoulli trials with success probability t  
\in  [0, .5].
  In my humble opinion, this style is more pertinent in terms of the 
programming logic of R although I am not very sure about the efficiency.

All the best.

7/3/2011 7:09 PM, Krishna wrote:
> A reproducible example would help, have you tried FOREACH
>
>
>
> On Jul 3, 2011, at 7:53 AM, Tristan Linke <tristan.linke at gmail.com> 
> wrote:
>
>> Dear all
>>
>> I want to simulate a stochastic jump variance process in which N is
>> Bernoulli (Poisson approximation) with intensity lambda0 + lambda1*Vt.
>> lambda0 is constant and lambda1 can be interpreted as a regression
>> coefficient on the current variance level Vt. J is the scaling factor
>>
>> How can I rewrite this avoiding the loop structure which is very
>> time-consuming for long simulations?
>>
>> for (i in 1:N){
>> ...
>> N <- rbinom(n=1, size=1, prob=(lambda0+lambda1*Vt))
>> Vt <- ... + J*N
>> ..
>> }
>>
>> P.S. This is going towards the Duffie, Pan, Singleton 2000 Transform 
>> Pricing
>> paper, here stochastic volatility with state-dependent correlated jumps
>> (Eraker 2004).
>>
>> Thanks a lot in advance.
>>
>>    [[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list