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

[amibroker] Re: Floating point precision (or lack thereof)



PureBytes Links

Trading Reference Links

I wanted to come back to this, even though its been some time. With
the "new" AlmostEqual (i know its been around for a while), this
problem can be solved. Problem originally was, with L equal to 38.78,
the condition

IIF(L<38.78,X,Y)

was yielding X because of imprecise representation. One way to get
around it using AlmostEqual is by doing:

IIF(L<38.78 AND NOT AlmostEqual(L,38.78),X,Y)

This results in the correct behavior.

Belated thanks for implementing this function



--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxx> wrote:
>
> No matter what precision you use, fraction of 0.1 can not be represented
> accurrately on binary computer.
> 
> If you read the article I pointed out
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
> 
> you would see that regardless if you use 32, 64 or 80 bits floating
point
> calculations are never 'exact' and even if you write (C++)
> 
> double x = 3/7; // not DOUBLE precision here
> if( x == 3/7)
> {
>   part A;
> }
> 
> then sometimes part A will be executed and sometimes not (depending on:
> compiler, release/debug mode, processor used and so on and so on.
> 
> So there is no point in discussing this.
> 
> Simply == (equality) check is prone to rounding errors when using
floating point
> no matter how many bits you use (you can even use 2048 bits floating
point and it won't help)
> 
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "qqqqq_99999_qqqqq" <qqqqq_99999_qqqqq@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Wednesday, August 24, 2005 7:10 PM
> Subject: [amibroker] Re: Floating point precision (or lack thereof)
> 
> 
> >
> > FYI
> >
> > TradeStation supports Double-Precision Floating Point Variables since
> > TradeStation 7.0.
> >
> > http://www.tradestation.com/new/tradestation7.shtm
> >
> > Whats's New in TradeStation 7.0
> >
> > TradeStation EasyLanguage Enhancements:
> > Support for Double-Precision Floating Point Variables
> > EasyLanguage allows for numeric value types to be specified as
> > integers, single floats, or double-precision floating point values
> > (doubles), resulting in a improved calculation performance by using
> > integers where floats have previously been used, in addition to
> > enhanced calculation precision through the use of doubles. The numeric
> > values that are impacted by this change are Variables, Inputs, Arrays
> > , Functions and Plots.
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxxx>
> > wrote:
> >> Hello,
> >>
> >> Some reading:
> >> http://docs.sun.com/source/806-3568/ncg_goldberg.html
> >>
> >> 1. Precision is 7 significant digits.
> >> 2. No PRICE information on ANY market is provided with greater
accurracy
> >> than 7 digits.
> >> 3. Because of (2), all major software packages including
> > Tradestation, Metastock
> >> and others use 32 bit floating point IEEE standard and
> >> there are NO problems using it assuming that you code properly.
> >> 4. Round() function does not change anything because certain decimal
> > fractions
> >> (like 0.1) can not be represented as binary fraction (because 1/10
> > can not be
> >> expressed as finite sum of binary fractions 1/2, 1/4, 1/8, 1/16,
> > 1/32, 1/64, 1/128, and so on ......)
> >> And all computers work with binary numbers only (except some ancient
> > machines that
> >> were using BCD codes).
> >>
> >> This is as plain obvious fact like the fact that 1/3 can not be
> > represented
> >> as decimal fraction. And if you round 1/3 expressed in decimal system
> >> 0.333333333 to any number of places you won't get accurate result no
> > matter what.
> >>
> >> Actually in EVERY encoding system (using any base) there are
> > fractions not
> >> representable by finite number of digits)
> >>
> >> Sorry guys but this is elementary school math.
> >>
> >> Best regards,
> >> Tomasz Janeczko
> >> amibroker.com
> >> ----- Original Message ----- 
> >> From: "Graham" <kavemanperth@xxxx>
> >> To: <amibroker@xxxxxxxxxxxxxxx>
> >> Sent: Wednesday, August 24, 2005 8:54 AM
> >> Subject: Re: [amibroker] Floating point precision (or lack thereof)
> >>
> >>
> >> > Yes it caused problems getting charts like PF charts correct.
> >> > You can work around it by rounding up or down eg in you case
> >> > an example  Round(L*100)/100
> >> > or
> >> > Unless you absolutely need accuracy past 5 digits, don't.
> >> >
> >> >
> >> > On 8/24/05, giggollo99 <giggollo@xxxx> wrote:
> >> >> Hi all,
> >> >>
> >> >> When i display values in commentary window like High, Low etc, I'm
> >> >> seeing values which appear to be imprecise. For example, my
> > downloaded
> >> >> data contains a low of 38.78 for a particular bar, but when I
display
> >> >> the value in Commentary window to 8 decimal places i get:
> >> >>
> >> >> L=38.77999878
> >> >>
> >> >> This causes problems in backtesting because if i code this
condition
> >> >>
> >> >> IIF(L<38.78,X,Y)
> >> >>
> >> >> the code will yield X when in fact it should yield Y because
the low
> >> >> is not less than 38.78 (it is exactly 38.78). This occurs simply
> >> >> because of the imprecise representation of the value in AB.
> >> >>
> >> >> Does anyone know how to get around this, and if its normal for the
> >> >> value to be imprecise in AB?
> >> >>
> >> >> Thanks a lot,
> >> >> g
> >> >>
> >> >>
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> Please note that this group is for discussion between users only.
> >> >>
> >> >> To get support from AmiBroker please send an e-mail directly to
> >> >> SUPPORT {at} amibroker.com
> >> >>
> >> >> For other support material please check also:
> >> >> http://www.amibroker.com/support.html
> >> >>
> >> >>
> >> >> Yahoo! Groups Links
> >> >>
> >> >>
> >> >>
> >> >>
> >> >>
> >> >>
> >> >>
> >> >
> >> >
> >> > -- 
> >> > Cheers
> >> > Graham
> >> > AB-Write >< Professional AFL Writing Service
> >> > Yes, I write AFL code to your requirements
> >> > http://e-wire.net.au/~eb_kavan/ab_write.htm
> >> >
> >> >
> >> >
> >> > Please note that this group is for discussion between users only.
> >> >
> >> > To get support from AmiBroker please send an e-mail directly to
> >> > SUPPORT {at} amibroker.com
> >> >
> >> > For other support material please check also:
> >> > http://www.amibroker.com/support.html
> >> >
> >> >
> >> > Yahoo! Groups Links
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >
> >
> >
> >
> >
> >
> > Please note that this group is for discussion between users only.
> >
> > To get support from AmiBroker please send an e-mail directly to
> > SUPPORT {at} amibroker.com
> >
> > For other support material please check also:
> > http://www.amibroker.com/support.html
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/