-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example doesn't work with ruby 1.9.3 #7
Comments
Hi Keith, Thanks for bringing this issue to my attention. I wasn't able to replicate the error you got on 1.9.3p0, I got the same one you had for 1.9.2p290:
In this case, I believe it to be an error with the docs ... rounding a rate object by itself doesn't make sense, we should only be able to round the value representing the rate applied in a specific time period (i.e. apr, monthly, etc.). I think the appropriate fix here is to correct the docs to read:
Please send along more details if you continue to see DomainErrors. |
Yea the second one was definitely just a doc correction. Maybe the first one was a combination of the ruby version + a specific version of another gem. In case it helps here is my gem list. actionmailer (3.1.3) |
I just tried the same example above and can confirm a few things -It does work without the rails stack (on just pure irb in 1.9.3p0) It seems there's a conflict with rails somewhere... |
With ruby1.9.3p0 your XIRR example does not work:
@Transactions = []
@Transactions << Transaction.new(-1000, :date => Time.new(1985,01,01))
@Transactions << Transaction.new( 600, :date => Time.new(1990,01,01))
@Transactions << Transaction.new( 600, :date => Time.new(1995,01,01))
@transactions.xirr(0.6).round(2) #=> Rate("0.024851", :apr, :compounds => :annually)
It results in this error:
Math::DomainError: Zero or negative argument for log
'from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/finance-1.1.0/lib/finance/cashflows.rb:106:in
**' from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/finance-1.1.0/lib/finance/cashflows.rb:106:in
block in xnpv'from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/finance-1.1.0/lib/finance/cashflows.rb:105:in
each' from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/finance-1.1.0/lib/finance/cashflows.rb:105:in
inject'from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/finance-1.1.0/lib/finance/cashflows.rb:105:in
xnpv' from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/finance-1.1.0/lib/finance/cashflows.rb:35:in
values'from /Users/krschacht/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/bigdecimal/newton.rb:71:in
nlsolve' from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/finance-1.1.0/lib/finance/cashflows.rb:88:in
xirr'from (irb):21
from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in
start' from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in
start'from /Users/krschacht/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands.rb:40:in
<top (required)>' from script/rails:6:in
require'from script/rails:6:in `
Downgrading to ruby 1.9.2p290 and ran the same thing and it error'd with:
NoMethodError: undefined method
'round' for Rate.new(0.024851, :apr):Finance::Rate from (irb):6 from /Users/krschacht/.rvm/gems/ruby-1.9.2-p290@rails313/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in
start'from /Users/krschacht/.rvm/gems/ruby-1.9.2-p290@rails313/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in
start' from /Users/krschacht/.rvm/gems/ruby-1.9.2-p290@rails313/gems/railties-3.1.3/lib/rails/commands.rb:40:in
<top (required)>'from script/rails:6:in
require' from script/rails:6:in
At least we're making progress. :)
@transactions.xirr(0.6).apr.round(2)
Fixed the last issue.
The text was updated successfully, but these errors were encountered: