Closed c-castillo closed 8 years ago
Finance::Rate
is an object representing an interest rate.
Based on my understanding, Excel's RATE() function returns an interest rate, based on some number of constant payments and a present value. I think of it as a higher-level IRR() function (which can be accessed in Finance
via Array#irr
).
Excel: RATE(10,500,-200000) #=> -0.398102343635752
Now set C4 = 200000, and C5:C14 = -500: IRR(C4:C14) #=> -0.398102343635752
Finance: [200000,-500,-500,-500,-500,-500,-500,-500,-500,-500,-500].irr #=> -0.398102343635752
That last line should work, but doesn't ... I'll have to do some digging as to why. Otherwise, we could implement excel's functionality quite easily:
def excelRATE(num, payment, present_value)
cashflow = [] << present_value
num.times do
cashflow << payment
end
cashflow.irr
end
I'll post again when I can get this example working properly.
Thanks, Bill
Bill, thanks a lot! Your examples helped me to understand the Rate function. I run a couple of tests in both Excel and irb console, and in some cases the values match, but in some cases it doesn't. I'm trying to figure out why.
Thanks again!
Closing due to age.
I need to implement the excel RATE() function to do some financial calculus. I didn't understand both MS documentation and this gem documentation, so... is rate method the ruby implementation of that Excel function?