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$?
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$.