Skip to content

Instantly share code, notes, and snippets.

@dmtucker
Created April 25, 2020 03:46
Show Gist options
  • Save dmtucker/89bb3db5fbc8e8cdc8b89d5e15eddaa3 to your computer and use it in GitHub Desktop.
Save dmtucker/89bb3db5fbc8e8cdc8b89d5e15eddaa3 to your computer and use it in GitHub Desktop.
import math
def apy(apr, periods=12):
return (((apr / periods) + 1) ** periods) - 1
def apr(apy, periods=12):
return (((apy + 1) ** (1 / periods)) - 1) * periods
apr_before = 0.12
apr_after = apr(apy=apy(apr=apr_before))
assert apr_after == apr_before, (apr_before, apr_after)
apy_before = 0.12
apy_after = apy(apr=apr(apy=apy_before))
assert apy_after == apy_before, (apy_before, apy_after)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment