Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have series of two stocks prices. Let's say that stock 1 has prices:

$A_1$, $A_2$, $A_3$, $A_4$, ..., $A_i$ (where $i$ is time)

And stock 2 has prices:

$B_1$, $B_2$, $B_3$, $B_4$, ..., $B_i$ (where $i$ is time)

As stocks are higly correlated I want to compute each stock price from another. The obvious algorithm would be:

$A_i$ = Sum ($A_1/B_1$ ... $A_i/B_i$) / $i \cdot B_i$;

$B_i$ = Sum ($B_1/A1$ ... $B_i/A_i$) / $i \cdot A_i$;

The problem is - to make this computations I need to track both $A_i/B_i$ and $B_i/A_i$. I was thinking to track just one of them. So I was thinking that

$B_i$ = Sum ($B_1/A1$ ... $B_i/A_i$) / $i \cdot A_i$;

is equal to

$B_i$ = (1 / Sum ($A_1/B_1$ ... $A_i/B_i$)) / $i \cdot A_i$;

However a quick test show that such assumption is wrong:

(2 + 3 + 4 + 5) / 4 = 3.5

(1/2 + 1/3 + 1/4 + 1/5) / 4 = 77 / 240 ~ 0.32

1/3.5 ~ 0.29

0.29 != 0.32

Close but not equal! Why so? Can I avoid tracking both $A_1/B_1$ and $B_1/A_1$?

share|cite|improve this question
because $\frac{1}{a}+\frac{1}{b}\neq \frac{1}{a+b}$, and please use $\LaTeX$ is hard to unterstand what you want – Dominic Michaelis Feb 24 '13 at 11:04

If your avearage of all $\frac{A_i}{B_i}$ looks like $\frac{2+3+4+5}4$ and not like $\frac{3.4+3.6+3.3+3.7}4$ it may seem like the two variable are not too correlated after all; in the latter case the difference between the two calculation becomes smaller. Abetter idea would be to perform a correct linear regression, a simple one should suffice. For this you need only keep track of $n$, $\sum A_i$, $\sum B_i$, $\sum A_iB_i$ and $\sum A_i^2$. Note that this again introduces an asymmetry (as $\sum B_i^2$ is not needed), but the linear extimation $B=\alpha\cdot A+\beta$ may still be inverted as $A=\frac1\alpha \cdot B-\frac\beta\alpha$.

share|cite|improve this answer
2 3 4 5 was an example. in real life it's more 2.01 2.001 2.00 1.99 9998 or something like that. difference is not more than ~0.1% – javapowered Feb 24 '13 at 11:09
If the differences aren't large, the formula you give won't be far off. But it can't be that much work to add up the numbers... In any case, read up on time series. – vonbrand Feb 24 '13 at 12:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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