3
$\begingroup$

I know that if I take take a brownian motion of, say, 30 steps of standard deviation 1, then the standard deviation of my endpoint will be sqrt(30). But what if the standard deviation of the 30 steps is defined by a function? How do I relate the endpoint standard deviation to that function?

An example in R, first with a standard fixed volatility random walk.

library(xts)
mysd <- 0.1 / sqrt(255) # small sd so that we don't walk too far
genwalk <- function(stepsizes) {i <- 1; for(x in stepsizes) i <- c(i, i[length(i)] * exp(x)); return(i)} # random walk function - geometric
acc <- matrix(0, 1000)
plot(genwalk(rnorm(30, 0, mysd)), type = "l", ylim = c(0.88, 1.12), col = "#0000001A")
for(x in 1:1000) {walk <- genwalk(rnorm(30, 0, mysd)); acc[x] <- last(walk); lines(walk, col = "#0000001A")}
title("1000 30-step random walks with step size 0.1/sqr(255)")

enter image description here No surprises here:

> sd(acc)
[1] 0.03484051
> mysd * sqrt(30)
[1] 0.03429972
> title("1000 30-step random walks with step size 0.1/sqr(255)")
> library(moments)
> kurtosis(acc)
[1] 3.048236
> mean(acc)
[1] 1.000664

So I know how to get from a standard deviation of x to the standard deviation of a 30-step walk: multiple x by the square root of the number of steps.

But what if x is a function rather than a constant? How do I then relate the function to the endpoint standard deviation? Let's say my function is a decay weighting of length 30 with half life 10:

decay <- exp((-log(2) / 10) * 30:1) # exponential decay, 30 steps

enter image description here

> plot(genwalk(rnorm(30, 0, mysd) * decay), type = "l", ylim = c(0.88, 1.12), col = "#0000001A")
> for(x in 1:1000) {walk <- genwalk(rnorm(30, 0, mysd) * decay); acc[x] <- last(walk); lines(walk, col = "#0000001A")}
> title("Random walks with step size 0.1/sqr(255) * decay weighting")

enter image description here

> sd(acc)
[1] 0.01645629
> mysd
[1] 0.006262243
> kurtosis(acc)
[1] 2.882403
> mean(acc)
[1] 1.000137

So it looks like the endpoints are still nicely normally distributed (mean ~ 0, kurtosis ~ 3), but I have no clue how to relate the standard deviation of the endpoints, that is sd(acc) above = 0.1645629 to mysd which was the step size multiplier for the decay function.

Basically: how do I get from the decay function which was applied to the standard deviation of step sizes, to the standard deviation of the endpoints?

$\endgroup$
  • $\begingroup$ Can you add a (hopefully) simple phrasing of your question, in mathematical terms? I don't know R and have no desire to read all this code. Just state what is your random variable (as a sum of other RVs, perhaps) etc. $\endgroup$ – Yair Daon Jan 21 '15 at 15:28
  • $\begingroup$ Although your question does not appear to assume anything about the distribution of the increments, your code appears to use lognormal increments. Could you clarify this and tell us what you mean by a "random walk" and whether you want your question answered in the full generality in which it is asked, or answered only for this special kind of random walk? Also, your code does not execute: what is the function last supposed to do? $\endgroup$ – whuber Jan 23 '15 at 18:44
  • $\begingroup$ @whuber: I am sorry about the last function. This is from the package xts. It returns the last row of an xts matrix, or a the last element of a vector. In this case I have a matrix of 1 column so it's a vector, and last returns the last element each time. I have amended the code. $\endgroup$ – Thomas Browne Jan 24 '15 at 16:39
  • $\begingroup$ My motivation is to model the way that traders think about markets. The recent trading patterns determine their thinking with higher importance than samples going further back in time. My hypothesis is that this weighting scheme in their minds, is decay weighted. Hence the lognormal distribution that I wish to apply to the "random walk" (brownian motion), but I may wish to change the function that is applied so a general answer would be helpful (although I think that Yair Daon has already done so). Many thanks for helping a non-mathematician (computer scientist here) with formalizing this. $\endgroup$ – Thomas Browne Jan 24 '15 at 16:53
  • $\begingroup$ If you switch to an additive model, as you put in one of your answers, then @YairDaon is telling you exactly what you need for a general case. (In fact, in mysd * sqrt(sum(decay^2)) just replace your decay weights for the ones you'd prefer and you get to compute the answer). $\endgroup$ – Cristián Antuña Jan 24 '15 at 17:09
4
+100
$\begingroup$

If I understand correctly, we seek the std of the following random variable:

$$ S := \sum_i X_i f(i) = \sum a_iX_i, $$ where $\mathbb{E}[X_i] = 0, \mathbb{E}[X_i^2] = \sigma^2$, where $\{X_i\}_{i=1}^n$ are independent and $a_i$ are non random. Calculate the variance:

$$ var(S) = var(\sum_i a_i X_i) = \sum_i var(a_iXi) = \sum a_i^2 \sigma^2 = \sigma^2\sum a_i^2, $$ where we've relied on the independence of $X_i$ in the second equality (see this). The standard deviation is thus $\sigma\sqrt{\sum_i a_i^2}$.

Please note that you can make the std of $a_iX_i$ be whatever you want by setting $a_i = \frac{\text{wahtever you want}}{\sigma}$.

$\endgroup$
  • 1
    $\begingroup$ You dropped the square of $a_i$ halfway through and did not recover it later. I'm sure that was a typo you will want to correct. You might also want to reformulate your answer without reference to a normal distribution of the $X_i$: it is neither necessary nor explicitly assumed in the question (normality appears to be used there only to generate examples in R). $\endgroup$ – whuber Jan 23 '15 at 18:22
  • $\begingroup$ Thank you for responding! I need to hold off casting any votes, though, until I can figure out what the question really is asking--see my request for clarification in a comment to the question. $\endgroup$ – whuber Jan 23 '15 at 18:46
  • $\begingroup$ This appears to answer my question. The only subtlety is that I apply the next step by multiplying by 1 * 1+(a2X2) rather than additively, however for small steps, this should work well, and in the context of my problem, actually it is I who should probably move to an additive version of the problem. I think this is the idea behind the answer from Cristian Atuna. $\endgroup$ – Thomas Browne Jan 24 '15 at 17:00
  • 1
    $\begingroup$ @ThomasBrowne it seems, from what you write, that you are using some variation of an ARCH\GARCH model. See wikipedia. Let me suggest that you change your question. Write exactly what you need to find (preferably in latex). This will facilitate answering your question. $\endgroup$ – Yair Daon Jan 24 '15 at 17:19
  • 1
    $\begingroup$ @ThomasBrowne you are welcome! This question could've been answered much more quickly and without a bounty had you removed the code and plots and wrote the problem in "plain" math. You would have got an answer within an hour probably. $\endgroup$ – Yair Daon Jan 24 '15 at 17:23
3
$\begingroup$

You'll get what you want by typing this formula:

> mysd * sqrt(sum(decay^2))
[1] 0.01611228

Which is basically the answer @YahirDaon gave you. Let me abuse a little bit of the Brownian Motion definition in this answer.

You should note that this expression only works because, as you put it: "You dont walk too far away". Or, what is the same, your x vector does not differ significantly from zero, since mysd is small.

Because, in this case, your geometric brownian motion can be tought as $e^{\sum_1^nX_i} \approx \sum_1^nX_i$. (Use a Taylor expansion to see this). That is, regular Brownian Motion's formulae are a good approximation. In fact, your formula for variance $\sigma^2 * \sqrt{30}$ is that of a regular Brownian Motion, and only works here because of the same reason: x is a vector with a small norm.

The correct formula (as $\mu = 0$) is: $\sqrt{e^{30\sigma^2}.(e^{30\sigma^2}-1)}$. And you can check that it yields a very similar result:

sqrt(exp(30*mysd^2)*(exp(30*mysd^2)-1))
[1] 0.03433

But if you use a mysd $\gg 0$ both in the iid increments case and the varying ones (which technically isn't even a Brownian Motion because it is defined as having iid increments), then you should check more general Lèvy processes.

btw: Random Walk is not the same as Brownian Motion (the former is a more general concept). You seem to refer to a BM because of the formulae you use, so maybe you should avoid refering to it as Random Walk (which it is, but your formulas are specific to BM, not any RW).

btw2: these notes might help you: http://www.columbia.edu/~ks20/FE-Notes/4700-07-Notes-GBM.pdf

$\endgroup$
  • 1
    $\begingroup$ I have looked for where geometric Brownian motion was mentioned in the question but have been unable to find it. What is the reason you discuss it here? $\endgroup$ – whuber Jan 23 '15 at 18:24
  • 1
    $\begingroup$ I thought this line tried to generate a GBM here: for(x in stepsizes) i <- c(i, i[length(i)] * exp(x)); return(i)}, since it does not sum the increments when building his process. I might have misunderstood the question, in that case, my answer is, well, wrong. $\endgroup$ – Cristián Antuña Jan 23 '15 at 18:32
  • 2
    $\begingroup$ That's a good interpretation. To me it says that for this example, a random walk with lognormally distributed increments is being generated. However, since I don't see a specific indication of the distribution in the question, I have supposed it is more general than that. I think we will need to ask the OP to clarify the question. $\endgroup$ – whuber Jan 23 '15 at 18:40
  • 1
    $\begingroup$ @whuber it is true that the question is much more general than the example, I just went with it w/o considering a more general case. $\endgroup$ – Cristián Antuña Jan 23 '15 at 18:47
  • $\begingroup$ I am assuming brownian motion, in a financial markets context. Colloquially we use the term random walk amongst non-mathematicians and I apologise for the lack of rigour. The use of sqrt(255) is often used to take a daily standard deviation to an annual one, as there are approximately 255 valid trading days in a year, and a circa 10% volatility is common in currency markets. $\endgroup$ – Thomas Browne Jan 24 '15 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.