If we assume that our investment grows according to: A(N) = A(0) (1 + R)N where we start with $A(0) and, after N months (or days or years ...), we have $A(N), then it's easy to compute R, the monthly Rate of Return (or daily or yearly ...): R = {A(N)/A(0)}1/N - 1 This formula ignores everything that's happened between the beginning and the end (after N months). What we really want is the following:
log(A(0)), log(A(1)), log(A(2)), ..., log(A(N))
For sanitary reasons, we let these numbers be called
So far, so good. e0={y0 - K}, e1={y1 - (M+K)}, e2={y2 - (2M+K)}, ..., e100={y100 - (100M+K)} and the sum of the squares of these errors, Σen2, is: {y0 - K}2+{y1 - (M+K)}2+ {y2 - (2M+K)}2+ ...+{y100 - (100M+K)}2 Remember, we know the numbers y0, y1, y2, etc. (they're the logarithms of the dollar values of our investment, after 0, 1, 2, 3, etc. months). What we want is to choose just two numbers, M and K, so the sum of the squares of these errors is as small as possible (which, by the way, defines what we mean by the optimal or "Best" ... but you may have another definition). We'll call this error E(M,K), so: E(M,K) = Σ {yn - (nM+K)}2 where the sum is from n = 0 to n = N (= 100, say) and maximize like so (careful ... some Calculus here): d/dM E(M,K) = 0 or Σ n{yn - (nM+K)} = 0 or MΣn2 + KΣn = Σnyn d/dK E(M,K) = 0 or Σ {yn - (nM+K)} = 0 or MΣn + KΣ1 = Σyn The solution is:
... left as an exercise ...*
Here's the logarithm of the TSE 300 over some 14-year period and the straight line Mn + K (with M and K as per formula, above, calculated from the logarithms of the TSE) You can use log10 or loge or logπ or whatever and the horizontal axis could be labelled 0, 1, 2, 3, ... 14 and that's n.
Now plot exp(Mn+K) versus A(n) |
* In general, if we want the "best" straight line fit to points (x1,y1), (x2,y2), (x3,y3), ..., (xN,yN) like so: we start with a line y = Mx + K and minimize the error E(M,K) = Σ {yn - (Mxn+K)}2 and get equations similar to those above, namely:
MΣxn + KΣ1 = Σyn
The solution is
Mamma mia! Uh ... did I mention that Σ1 = 1+1+1+...+1 = N ?
Of course, if you have MS Excel, the calculation of M=SLOPE and K=INTERCEPT is easy. Just put the logarithms of the Data, LN(Data), in column A and the xs in column B and and use the Excel commands: =SLOPE(A1:A100,B1:B100)This'll give a line: y = Mx+K. The "best fit" to the Data is then EXP(y) = EXP(Mx+K) vs x ... for example:
Note: our "Best Fit" minimized the mean squared error for the logarithm of the data. That's because we're looking at best "straight-line" fits
We could also try to mimic the S&P directly, with y = C (1+R)n and n is the number of days (weeks? years?) and R is the gain per day (week? year?) and we try to minimize: E(M,K) = Σ {yn - C (1+R)n}2 by choice of C and R. Good luck! (But check out Best Fit to stock prices.) Oh, one more thingy: The Standard Deviation (SD) of any set of numbers x1, x2, ..., xN (not necessarily those considered above!) is given by: SD2 = (1/N) Σ (xn - A)2 where A is the average of the x's, namely A = (1/N) Σ xn. Note: The Standard Deviation is ALWAYS positive (or, at least it's never negative). Okay, to calculate SD, we
Of course, who's to say that minimizing the Mean Squared Error is really the "Best Fit"? Suppose e1, e2, ... eN are the absolute values of the errors and we wish to minimize "something", by appropriate choice of M = SLOPE and K = INTERCEPT.
Normally we wish to minimize
SQRT{(1/N)Σ
en2}. Let's compare these two "error measures". Under what conditions will (1/N)Σ en < SQRT{(1/N)Σ en2} ? This will be true if: {(1/N)Σ en}2 < (1/N)Σ en2 And this will be true if: (1/N)Σen2 - {(1/N)Σ en}2 > 0
which we recognize as a Standard Deviation, so the inequality is true if the Standard Deviation of the errors, en, is positive. But any Standard Deviation is ALWAYS positive !! Conclusion? The MEAN of the absolute values of the errors is a smaller error measure than the ROOT MEAN SQUARE error measure. |