Here's a real-life example I encountered recently. I've simplified the
annual return
numbers to 200% for stocks and 100% for bonds (*3 2, respectively) to make
the
math more easily checkable.
I start with a series of daily returns for a stock and bond index:
*/stkret=. 365$3^%365 NB. Daily stock returns - triple over the year
3
*/bndret=. 365$2^%365 NB. Daily bond returns - double over the year
2
I want to use the daily returns of a 60/40 stock/bond benchmark based on
these
index returns to calculate an annual return:
NB. 60/40 stock/bond benchmark - naive calculation:
*/bmkret1=. (0.60*stkret)+0.40*bndret
2.5509869
NB. is demonstrably wrong:
0.6 0.4 +/ . * 3 2
2.6
NB. Alternate version (using cumulative returns) gives correct answer:
{:bmkretcum=. (0.60**/\stkret)+0.40**/\bndret
2.6
So, I've introduced a noticeable loss of precision simply by multiplying
each series by a number less than one before accumulating the returns.
This error is easy to make but harder to catch when using real return
numbers
if we don't have some independent calculation of the final result.
On 12/9/06, John Randall <[EMAIL PROTECTED]> wrote:
Here's one more example of the perils of floating-point arithmetic,
due to William Kahan, designed to show that roundoff error can still
bite us even when the usual suspects (cancellation, tiny divisor) do
not come into play.
...
--
Devon McCormick
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm