1

I'm trying to get a daily rate from an annual rate of 26%.

In Python, 1.26**(1/365) gives me 1.0

In Excel, 1.26^(1/365) gives me 1.000633, which is what I want.

Why is Python doing this and how can I get a more accurate result?

Alex Riley
  • 169,130
  • 45
  • 262
  • 238
Alexis Eggermont
  • 7,665
  • 24
  • 60
  • 93
  • 1
    If you want to compare your calculations to that of your bank take into account that sometimes (i.e., not always) a financial year is assumed to have 360 days, and a month 30 days. – user1016274 Nov 07 '15 at 13:46
  • Possible duplicate of [How can I force division to be floating point? Division keeps rounding down to 0](http://stackoverflow.com/questions/1267869/how-can-i-force-division-to-be-floating-point-division-keeps-rounding-down-to-0) – Nick is tired Apr 24 '17 at 14:47

1 Answers1

6

You are using Python 2.x so 1 / 365 is zero (division of two integers returns an integer). Anything to the power of zero is 1.

You need to use true division; you could make one of the numbers a floating point number to trigger this:

>>> 1.26 ** (1.0 / 365)
1.000633383299703
Alex Riley
  • 169,130
  • 45
  • 262
  • 238