[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:floating Point reprsentation was perceived Calculation error in MS



PureBytes Links

Trading Reference Links

Sorry, but I long ago forgotten all that I ever knew about internal
representation and floating point precision. I was trained as a scientist,
so 'am very wary of mistaken views of precision. But, here's an example:
I have a very large SQL server database of stock  and commodity prices which
I use in testing. Now numbers from the exchange typically come in as say
49.25. I store them in the database as double prcision floating point.
However, the number is very often not stored as 49.249999999999999..... or
it's equivalent in floating point.

I would urge you to read say, numerical recipes  by Press, Teukolsky et al,
In this they talk about floating point representation, and the last bit
being a phantom i.e., it could be turned on or off. e.g. a half- and I
choose that form precisely, would be represented by 0 (the sign bit)
followed by 01111111 the last bit could be a phantom 1 or zero. This is a
function of machine accuracy. Clearly, one can use packages such as
Mathematica with enhanced floating point represention but I believe that one
should uunderstand what one is modelling, My advice is recognise that one
will not always get precisely the effect one would expect and code
accordingly. Are you going to do a deal when an indicator reads
2.00000000000 and not 2.0000000000001 or 1.99999999999999?
----- Original Message -----
From: "Genevieve, Louisa, Herve" <genher@xxxxxxxxxxxxx>
To: <metastock@xxxxxxxxxxxxx>
Sent: Tuesday, October 02, 2001 7:58 AM
Subject: RE: Calculation error in MS


> When I replicated the experiment I created a security with, as closes 1.47
> and 1.5 as Orea's. I, then, read David's reply, and thought if I enter
1.47
> why would MS store it (internally) as 1.47000...1?David,  do you mean that
> at a basic binary level , MS can not store a number with infinite 0's, as
> 1.4700000000......and therefore has to store it as 1.47000.....1? But if
it
> was the case , then, could  the result of a calculation EVER be equal to a
> fix number? In the case of Orea's problem the result of the calculation IS
2
> ( and not 2.000001), if it get strored as 2.000001 then this could never
be
> equal to 2?? right??? In wich case, any formula of the type if( the
resultat
> of a calculation=a fix number(2 for instance), Do someting, Do somethin
> else) will NEVER work! I am very confused.......Anyone has more thoughts
on
> the subject?
>
> Herve
>
> -----Original Message-----
> From: owner-metastock@xxxxxxxxxxxxx
[mailto:owner-metastock@xxxxxxxxxxxxx]On
> Behalf Of David Jennings
> Sent: Monday, 1 October 2001 4:42 AM
> To: metastock@xxxxxxxxxxxxx
> Subject: Re: Calculation error in MS
>
>
> I can't say i have tried to replicate your results, but it doesn't seem
> unexpected. It relates to the precision of data held in MetaStock. I'm
sure
> there are similar experiences in the archives. Take heart, MetaStock is
not
> alone in this. Other trading programs suffer from the same problem e.g.
> TradeStation and also databases e.g. Microsoft SQL server. If you look at
> the internal representation it may well be 2.000000001 because 1.47 was
held
> as 1.4700000001 say. This should not be seen as a limitation, but as
> something to be aware of, especially if you are subtracting  a small
number
> from a large number or calculating over long time periods. I would urge
you
> to look at the absolute tolerance, rather than the number itself. There
are
> a number of techniques around to get over such
> ----- Original Message -----
> From: "SR" <raftsp@xxxxxxxxx>
> To: <metastock@xxxxxxxxxxxxxxxxxx>
> Sent: Monday, October 01, 2001 10:26 AM
> Subject: RE: Calculation error in MS
>
>
> > Hello dear friends
> >
> > Today I noticed the following very strange error, while back-testing
with
> > Metastock 6.52 for windows:
> >
> > Previous bar's close = 1.5
> > This bar's close = 1.47
> >
> > All the calculations made (manually  or electronically ) will agree that
> the
> > percentage of this  change is  -2
> > I made an indicator for calculating the change in MS itself, which also
> > agrees with this percentage:
> >
> >  ( C - Ref(C, -1) ) * 100 / Ref(C, -1)
> >
> > The above returns -2  allright.
> >
> > So far so good.
> > But the strange thing is, that when I tried to verify this percentage
with
> > binary or ternary indicators, they did NOT recognize the change -2% as
> true!
> > In fact, they consider the result as >2% !
> > Here is a ternary indicator that I used for verification :
> >
> > perc:= ( C - Ref(C, -1) ) * 100 / Ref(C, -1);
> > If(perc > -2, 1,
> > If(perc < -2, -1, 0))
> >
> > The result returned in the above case was NOT zero (0) as it should be,
> but
> > one (1) which means that the change is represented by a number larger
> > than -2
> >
> > Has anybody else experienced such a thing? Do I have a virus in my
> computer?
> > A math terrorist maybe? Has my MS crashed quietly?
> > Can someone repeat the above experiment and tell me the results please?
> >
> > Thanks
> > Orea
> >
> >
> >
>
>
>