سؤال

Is there a rolling maximum function in R that does not require a time series object? I want to simulate reflected Brownian motion, which one can simulate by having Y = Brownian Motion - Maximum of the Brownian motion up to that time. Now say I can simulate Brownian Motion (this is trivial) and I have a series of random times (so not integer times because I want to simulate a continuous time process), how do I find the maximum up till say time 10? For clarity my code so far is:

brownian = function(n=1000, fun=rnorm) {x=cumsum(fun(n))} X= brownian() t=cumsum(abs(sin(seq(1:1000)))) %these are the random times

Now, I would ideally like to write Y= X - .... but can't use any time series arguments b/c TS objects require even time spacing. How would I do this?

هل كانت مفيدة؟

المحلول

Try the following:

x - cummax(x)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top