# Trying to 'reverse' a formula....

• May 20th 2013, 05:45 AM
richardcarter
Trying to 'reverse' a formula....
I am trying work out a formula based on the information below that will help me to answer the question... "What PRICE is required today that will make the difference between two exponential moving averages the same value as yesterday?" I can work out the formula 'forwards' as I've shown below with my calculations, but I am trying to create a formula where TODAYS PRICE is the unknown variable. Any help would be most appreciated, Thank you.

YP = Yesterday price (=4.29)
YEMA1 = yesterdays 3 day exponential moving average (=4.28)
YEMA2 = yesterdays 5 day exponential moving average (=4.20)
YDiff = YEMA1/YEMA2 (=1.01905)

TP = Todays price (=4.29)
TEMA1 = Today's 3 day exponential moving average =2/4*(TP-YEMA1)+YEMA1 (=4.285)
TEMA2 = Today's 5 day exponential moving average =2/6*(TP-YEMA2)+YEMA2 (=4.23)
TDiff = TEMA1/TEMA2 (=1.013002)

So, just to clarify, I am trying to find out what 'TP' should be that will make 'Tdiff' equal 'Ydiff'.
• May 20th 2013, 07:43 AM
ebaines
Re: Trying to 'reverse' a formula....
For simplicity I'm going to call YEMEA1 = Y_1, YEMEA2=Y_2, Ydif = Yd, TEMA1 = T_1, TEMA2 = T_2, Tdiff = Td

The formula for T1 that you have can be simplified to $T_1 = \frac {T_p} 2 +\frac {Y_1} 2$, and $T_2 = \frac {T_p} 3 + \frac {2Y_2} 3$.

If $Y_d = T_d$, then $Y_d = \frac {T_1}{T_2} = \frac {\frac {T_p} 2 +\frac {Y_1} 2}{\frac {T_p} 3+\frac {2Y_2}{3}}$

Multiply numerator and denominator of the the left hand side by 6, and rearrange:

$Y_d(2T_p+ 4 Y_2) = 3T_p + 3 Y_1$

$T_p(2Y_d-3) = 3Y_1 - 4 Y_dY_2$

Note that Yd times Y_2 = Y_1, so:

$T_p = \frac {3Y_1 - 4 Y_1}{2Y_d-3}$

$T_p = \frac {-Y_1} {2Y_d -3 }$

$T_p = \frac {Y_1}{3-2 Y_d}$

Using your numbers above, where Y_1 = 4.28 and Y_d = 1.01905, you get Tp = 4.4495, T1 = 4.364752, T2 = 4.283168, and Td = 1.019048 (same as Yd).
• May 20th 2013, 02:45 PM
richardcarter
Re: Trying to 'reverse' a formula....
Excellent! Thank you very much.. you've made my day.. I'd already spent quite some time trying to figure this out!
• May 20th 2013, 05:29 PM
richardcarter
Re: Trying to 'reverse' a formula....
I've just been trying to test myself to make sure I understand how you derived at the formula... and so I have decided to use a different example using a 5 day EMA and an 8 day EMA.... (and applying a multiplier of 40 ).. but where I am really stuck is the process you went through to rearrange the formula after multiplying the numerator and denominator... could you break it down into smaller steps.. or point me in the direction of somewhere to go where I can learn how to do this? Thanks again.
• May 21st 2013, 04:46 AM
ebaines
Re: Trying to 'reverse' a formula....
OK. Staruing from:

$Y_d = \frac {\frac {T_p}2 +\frac {Y_1} 2}{\frac {T_p} 3 + \frac 2 Y_2} 3}$

Multiply through by $\frac 6 6$:

$Y_d = \frac {6 (\frac {T_p}2 +\frac {Y_1} 2)}{6(\frac {T_p} 3 + \frac 2 Y_2} 3)} = \frac {3T_p +3Y_1)}{2T_p + 4 Y_2}$

Now multiply through by the denominator on the right hand side:

$Y_d (2T_p + 4 Y_2) = 3T_p+3Y_1$

Regroup to bring the T_p terms to the left hand side and everything else on the right:

$Y_d(2 T_p) - 3T_p = 3Y_1 -4 Y_dY_2$

$T_p(2Y_d-3) = 3Y_1 - 4Y_dY_p$

Sub $Y_1= Y_dY_p$:

$T_p(2Y_d-3) = 3Y_1 - 4Y_1 = -Y_1$

Divide both sides by p $2Y_d-3$:

$T_p = \frac {-Y_1}{2Y_d -3}$

Multiply right hand side by $\frac {-1}{-1}$:

$T_p = ( \frac {-1}{-1}) \frac {-Y_1}{2Y_d -3} = \frac {Y_1}{3 - 2 Y_d}$

Hope this helps.
• May 21st 2013, 08:04 AM
ebaines
Re: Trying to 'reverse' a formula....
There is an error in my previous post but i am unable to edit it.

Quote:

Originally Posted by ebaines
OK. Staruing from:

$Y_d = \frac {\frac {T_p}2 +\frac {Y_1} 2}{\frac {T_p} 3 + \frac 2 Y_2} 3}$

Multiply through by $\frac 6 6$:

$Y_d = \frac {6 (\frac {T_p}2 +\frac {Y_1} 2)}{6(\frac {T_p} 3 + \frac 2 Y_2} 3)} = \frac {3T_p +3Y_1)}{2T_p + 4 Y_2}$

Should be:

Starting from:

$Y_d = \frac {\frac {T_p}2 +\frac {Y_1} 2}{\frac {T_p} 3 + \frac {2 Y_2} 3}}$

Multiply through by $\frac 6 6$:

$Y_d = \frac {6 (\frac {T_p}2 +\frac {Y_1} 2)}{6(\frac {T_p} 3 + \frac {2 Y_2} 3)}} = \frac {3T_p +3Y_1}{2T_p + 4 Y_2}$

The remainder of the post is OK as is.
• May 22nd 2013, 04:58 AM
richardcarter
Re: Trying to 'reverse' a formula....
Ah that's great - just what I needed - thank you!