# How to simulate this randomized “finite” sum? [closed]

Consider the the Geometric Brownian motion

$\qquad dX_t=\mu X_t dt+\sigma X_t dW_t$, with $X_0=1$, $\mu=0.2$, and $\sigma=0.30$.

for each $n=1,2,3,..$ let $h_n=1/n$, and let $X^n_n$ be the final value of the discrete process obtained from Euler scheme wrt $h_n$, i.e.

$\qquad X^n_{k+1}=X^n_{k} +\mu X^n_k h_n +X^n_k \sigma \sqrt{h_n} \text{randn}(0,1),$

for $k=0,1,2,\ldots n-1$. Here $\text{randn}(0,1)$ means the standard normal random variable with mean 0, standard deviation 1.

That is, after using Euler scheme ,for each $n=1,2,3, \ldots$ you have a sequence (which depends on $n$)

$\qquad \{1,X_1^2, X_2^n,\ldots, X_n^n \}$.

For simplicity assume that $F_n\equiv X_n^n$.

I do know how to find $F_n$ for $n=1,2,\ldots$.

Assume that $N\sim \text{Geometric}(p)$, i.e, $P(N=k)=(1-p)^{k-1}(p)$ ( let assume $p=0.5$ here for simplicity), for $k=1,2,3,\ldots$.

My question here is:

1. How to simulate this sum

$\qquad Y=\sum_{k=1}^{N}\frac{(F_{k+1}-F_{k})}{2^k} N^2$?

Using geornd(p) provided by matlab, I do know how to generate $N$.

2. How to approximate $E(Y)$?

My confusion comes from here. There are random variables floating around here: $N$ and $F_{k+1}-F_{k}$. Assume that $N$ and $F_k$ are independent, so we have

$\qquad E(Y)=\sum_{k=1}^{\infty}\frac{E[(F_{k+1}-F_{k})]E[N^2 I_{k\leq N}]}{2^k}$.

## closed as unclear what you're asking by D.W.♦, Luke Mathieson, David Richerby, Tom van der Zanden, vonbrandJul 8 '15 at 23:15

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• 1. Questions about Matlab are off-topic here. I've edited the post to remove that. 2. What's randn? 3. What's the definition of $F_k$? You use that notation without ever defining it. Please define all notation and all variables before first use. 4. What have you tried? What are your thoughts? Do you know how to sample from $F_k$? If so, then it seems straightforward to sample from the distribution of $Y$ -- what is your specific problem? 5. What do you mean by your "2)" question? Are you looking for an algorithm to estimate it, or a number? 6. Please ask one question per question. – D.W. Jul 6 '15 at 18:44
• Dear D.W, I define $F_k \equiv X_k^k$, the final value. – Dave Ng Jul 6 '15 at 18:51
• D.W: here $N$ is a random variable and it comes to the sum, and it is also the first time I ran into a randomized sum so to be honest I don't know how to start. – Dave Ng Jul 6 '15 at 18:59
• OK, that helps, thank you. However, I'm still wondering how far you got on your own. Do you know how to sample from $F_k$? In general, if I give you the distribution/definition of a random variable, do you know how to sample from that distribution? For instance, are you familiar with how to sample from a Geometric distribution, or from a normal distribution? Do you know how to sample from $X^n_k$? Are you familiar with using the inverse c.d.f. to sample from an arbitrary distribution? Do you know how to compute the c.d.f. of $F_n$? This will help us tailor what level of an answer you need. – D.W. Jul 6 '15 at 21:33
• – D.W. Jul 6 '15 at 21:36

Let me give you some basic principles that seem helpful for your problem:

• How to estimate an expected value. You want to estimate $\mathbb{E}[Y]$. Here's a standard fact: if you can sample from the distribution of $Y$, then you can estimate $\mathbb{E}[Y]$. Concisely, what you do is sample $n$ values according to the distribution of $Y$, then take their average; the result is a pretty good estimate for $\mathbb{E}[Y]$. The larger the value of $n$, the more accurate your estimate will be.

With more mathematical precision: let $y_1,\dots,y_n$ be the result of sampling $n$ times from the distribution of $Y$. This means that they come from i.i.d. r.v.'s with the same distribution as $Y$. Now let $\hat{y} = (y_1+\dots + y_n)/n$ be the average of these values. Then it follows that $\hat{y}$ is a good estimate for $\mathbb{E}[Y]$ (with high probability). In particular, $\mathbb{E}[\hat{y}] = (\mathbb{E}[y_1]+\dots + \mathbb{E}[y_n])/n = (\mathbb{E}[Y]+\dots + \mathbb{E}[Y])/n = \mathbb{E}[Y]$, so $\hat{y}$ is an unbiased estimator for $\mathbb{E}[Y]$. Also, by a similar calculation, $\text{Var}[\hat{y}] = \text{Var}[Y]/n$; the interpretation of this is that the error in your estimate of $\mathbb{E}[Y]$ will typically be roughly on the order of $\sigma/\sqrt{n}$, where $\sigma = \sqrt{\text{Var}[Y]}$ is the standard deviation of $Y$. Thus, if $Y$ has variance that is not too large, then this approach gives a reasonably accurate estimate of $\mathbb{E}[Y]$.

In your case, this shows how to answer your second question: if you can sample from $Y$, this gives you one candidate way to estimate $\mathbb{E}[Y]$. There are other ways to get an estimate, but this is a simple method that applies whenever you know how to sample from the underlying distribution.

• How to sample from a sum of random length. The next question is, how to sample from $Y$? The challenge you seem to be struggling with is how to deal with the fact that the definition of $Y$ is as a sum containing $N$ terms, but where here $N$ is a random variable.

It turns out there is a simple way to deal with this. In particular, you can sample from $N$ by using the following process:

1. Sample from $N$, i.e., pick a random value for $N$ by sampling from a geometric distribution (since that's the distribution of $N$).
2. Now you have a fixed, constant value for $N$, so it becomes easy to sample from $Y$. In particular, for this fixed value of $N$, sample a random value for $F_1,F_2,\dots,F_{N+1}$ (according to the distribution of these random variables). Then, plug those values into the definition of $Y$; the result will be a random value for $Y$, picked according to the correct definition for $Y$.

In general, if you have a random variable that is defined by some stochastic process, then you can sample from it by simulating the process, sampling from random values whenever the process does.

So, let me spell out the implications for you. This means that if you can figure out how to sample from the distribution of $F_i$, then you can use the above two techniques to sample from the distribution of $Y$ and thereby estimate the value of $\mathbb{E}[Y]$. This reduces your problem to a smaller/simpler one: figuring out how to sample random values, distributed according to the distribution of $F_i$.