Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
62.23 is not equal to 62.23, apparently. data.current price vs history. A floating Python strike isclose() call.

The key line checks equality between these two:

        float(data.current(s, 'price')) == float(data.history(s, 'price', 1, '1m')[-1])

Appreciate if anyone can shed some light on it. Doesn't apply every time. Might happen at least sometimes with any symbol.

2017-02-07 12:59 info:53 INFO XIV 62.23 == 62.23 is False. Why?

3 responses

Would help if I add the code probably, forgot.

Awe snap, of course. Thanks for the links.

Changed to show a lot of decimals and as strings.

2017-02-27 12:59 info:52 INFO TSLA 245.92000000000001591616 != 245.91999999999998749445  
2017-02-28 12:59 info:52 INFO TSLA 249.98000000000001818989 != 249.97999999999998976818  
2017-03-15 12:59 info:52 INFO TSLA 255.95000000000001705303 != 255.94999999999998863132  
2017-04-07 12:59 info:52 INFO TSLA 302.53700000000003456080 != 302.53699999999997771738  
2017-04-18 12:59 info:52 INFO TSLA 300.78000000000002955858 != 300.77999999999997271516  

Just the first line values:

245.92000000000001591616  
245.91999999999998749445  
                log.info('{} {} != {}'.format(  
                    s.symbol,  
                    '%.20f' % data.current(s, 'price'),  
                    '%.20f' % data.history(s, 'price', 1, '1m')[-1]  
                ))

Instead of isclose() I went with this:
dcp = float('%.3f' % dcp)

Posted conclusions, code about prices at https://www.quantopian.com/posts/clarifying-prices-by-various-methods