## PHP Functions to Convert APR to APY and APY to APR

Posted on February 12th, 2008 in General,Programming by Brandon

Thanks to The Finance Buff for these formulas. Here are some simple PHP functions to convert and APY to an APR and back

```function apy_to_apr(\$rate, \$periods = 365)
{
return  ( \$periods *  pow( (1+\$rate), (1/\$periods) )) - \$periods;
}

function apr_to_apy(\$rate, \$periods = 365)
{
return ( pow( (1+ (\$rate/\$periods)), \$periods) - 1);
}```

### 2 Responses to 'PHP Functions to Convert APR to APY and APY to APR'

Subscribe to comments with RSS or TrackBack to 'PHP Functions to Convert APR to APY and APY to APR'.

1. Jerry Browne said,

on April 15th, 2008 at 1:22 pm

I’m having trouble following the equations.

would you please show me with a step by step process.

I also don’t understand some of the terms being used.

Thank you, Jerry B.

2. Brandon said,

on April 15th, 2008 at 8:45 pm

I’ve tried to use variable names that make sense:

\$rate = The interest rate as a decimal (ie 5% as 0.05)
\$periods = The number of compounding periods (365 would be compounded daily)

I didn’t come up with the formulas on my own. I found them at The Finance Buff and just converted them to PHP functions. I’ve tried them out and the results appear to be correct to me.

Thanks,
Brandon

### Post a comment

Please copy the string nuY8mQ to the field below: