This function samples from the solution to the stochastic differential
equation of the geometric wiener process:
rgwiener <- function (n=1, t=1, S0=1000, mu=0, sigma=1) {
S0 * exp((mu - 1/2 * sigma^2) * t + sigma * sqrt(t) * rnorm(n))
}
To test this, note that the geometric wiener process has log(S_t/S0) ~
N((mu -1/2*sigma^2)* t, sigma^2 * t)
So if we let mu = 0, sigma = 1, t =1, S0 = 1000, log(S_t/S0) should be ~
Normal(-0.5, 1).
> samp <- log(rgwiener(100000)/1000)
> hist(samp)
> library(MASS)
> fitdistr(samp, "normal")
mean sd
-0.500553189 1.000032814
( 0.003162381) ( 0.002236141)
which looks good to me.
Because the geometric wiener process is a transformation of the ordinary
wiener process, we can simulate it easily enough (apologies to the
authors of package e1071, whose function rwiener I hacked):
gwiener <- function (mu=0, sigma=1, S0=1000, frequency=1000) {
z <- S0 * exp((mu - 1/2 * sigma^2) * seq(0, 1, length=frequency) +
sigma * cumsum(rnorm(frequency)/sqrt(frequency)))
ts(z, start = 1/frequency, frequency=frequency)
}
> plot(gwiener(), type="l")
Looks ok.
Cheers,
Simon.
Michael Graber wrote:> Dear R People,
>
> Consider I have 3 realizations of an Geometric Brownian process.
> Now i want to overlay the plot of these realizations. In a future point
> in time a probability density curve in this specific point of time
> should overlay this plot ( view rotated 90?).
> I am sorry for not providing any source code. Can anybody point mo to an
> package, or has anybody an idea how to simulate an geometric brownian
> process in R?
>
> Thanks in advance,
>
> Michael Graber
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>
--
Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat.
Centre for Resource and Environmental Studies
The Australian National University
Canberra ACT 0200
Australia
T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
F: +61 2 6125 0757
CRICOS Provider # 00120C
The combination of some data and an aching desire for
an answer does not ensure that a reasonable answer
can be extracted from a given body of data.
- John Tukey.