marksweston / finance

A library for financial calculations in Ruby
https://rubygems.org/gems/finance
Other
217 stars 93 forks source link

No way to create an amortization for a Rate that doesn't compound monthly #4

Open fringd opened 12 years ago

fringd commented 12 years ago

r = Finance::Rate.new( Flt::DecNum('0.06'), :apr, :duration => 10.years, :compounds => 4 )

a = Finance::Amortization.new( 1000, r )

a.interest seems to have 10_12 entries, not 10_4

doesn't seem to be right with duration set to 10 or 10 * 4 either ( it doesn't apply 1/4 of 0.06 as expected )

is there some way to do this that just isn't obvious from the readme? or is this simply non-working?

wkranec commented 12 years ago

Thanks for bringing this up. I think this is due to the fact that the #years method is a little half-baked at this point:

You should still be able to create the amortization, but (for now) you will have to manually compute the duration, i.e.:

r = Finance::Rate.new( Flt::DecNum('0.06'), :apr, :duration => 40, :compounds => 4 ) a = Finance::Amortization.new( 1000, r )

fringd commented 12 years ago

Hmmm... I think that my problem is that I need the number of payments per year to be something besides 12 as well...

so that you make debt payments 4 times per year instead of 12.

I am trying to mirror the Excel cumprinc function with a number of periods not equal to 12

On Tue, Sep 6, 2011 at 12:52 PM, wkranec reply@reply.github.com wrote:

Thanks for bringing this up.  I think this is due to the fact that the #years method is a little half-baked at this point:

  • It simply multiplies by 12 to get the number of months.
  • Since #years is a Numeric method rather than a Rate method, it doesn't necessarily know the number of compounding periods.

You should still be able to create the amortization, but (for now) you will have to manually compute the duration, i.e.:

r = Finance::Rate.new( Flt::DecNum('0.06'), :apr, :duration => 40, :compounds => 4 ) a = Finance::Amortization.new( 1000, r )

Reply to this email directly or view it on GitHub: https://github.com/wkranec/finance/issues/4#issuecomment-2018725

wkranec commented 12 years ago

The Amortization payments will match the compounding periods of the Rate given. So the example I gave before should work here.

I probably ought to have a #balance method which gives you the balance of the loan in a particular period. This would make it easier to replicate cumprinc.