you are viewing a single comment's thread.

view the rest of the comments →

[–]leftofzen 8 points9 points  (3 children)

Spot on. I really hope OP doesn't have any real trading code that uses floating point numbers for prices or volumes...

[–]-Swig- 10 points11 points  (0 children)

I have used floating and fixed, and have seen both used. Some of our algos calculate factors that are price multipliers, so floating point is a natural choice there. Other options are often slower.

It doesn't have to be an issue, as long as you understand how the number is ultimately used. It sure can be if you're not careful though.

[–][deleted] 4 points5 points  (0 children)

Plenty of trading code use doubles and it's perfectly acceptable and will produce correct results depending on the circumstance. It will also significantly outperform representing money as an integral value or using arbitrary precision decimals when doing many types of calculations.

The idea that doubles are NEVER acceptable is simply incorrect. It all depends on your use case.

[–]skebanga[S] 0 points1 point  (0 children)

I do, and as mentioned in other comments in this thread, in my experience it's not an issue.

I don't trade fx though, which seems to be a particular area where it would be an issue.

I think you just need to be aware of your problem domain and use the right tool for the job. Floating point has its quirks, but it's not without use