Skip to content
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

When using XIRR get a TypeError in Rate.rb #19

Open
wQwRtaufxJw7UFLCXzXz opened this issue Feb 5, 2013 · 4 comments
Open

When using XIRR get a TypeError in Rate.rb #19

wQwRtaufxJw7UFLCXzXz opened this issue Feb 5, 2013 · 4 comments
Assignees

Comments

@wQwRtaufxJw7UFLCXzXz
Copy link

wrong argument type Flt::DecNum (expected scalar Numeric)

in

finance (1.1.2) lib/finance/rates.rb:162:in `**'

changing

    def Rate.to_nominal(rate, periods)
      rate, periods = rate.to_d, periods.to_d                                                               

      if periods.infinite?                                                                                  
        (rate + 1).log                                                                                      
      else
         periods * ((1 + rate) ** (1 / periods) - 1)                                                         
      end                                                                                                   
    end  

by adding the line

periods = periods.to_f

to the else statements

      if periods.infinite?                                                                                  
        (rate + 1).log                                                                                      
      else
        periods = periods.to_f # my workaround
        periods * ((1 + rate) ** (1 / periods) - 1)                                                         
      end                                                                                                   

seems to fix it. Is this a bug you recognize?

@wQwRtaufxJw7UFLCXzXz
Copy link
Author

Ruby version:

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.2]

Rails version:

Rails 3.2.11

@wQwRtaufxJw7UFLCXzXz
Copy link
Author

The most interesting thing is that SOMETIMES (I'd say about 50%) This random TypeError will show, and sometimes it works completely fine. It's so weird.

#<Class:0x007f9555d36fc0> can't be coerced into BigDecimal

in

/Users/ctwiz/.rvm/gems/ruby-1.9.3-p194/bundler/gems/finance-990fd53d46c3/lib/finance/cashflows.rb:118:in `**'
/Users/ctwiz/.rvm/gems/ruby-1.9.3-p194/bundler/gems/finance-990fd53d46c3/lib/finance/cashflows.rb:118:in `block in xnpv'
/Users/ctwiz/.rvm/gems/ruby-1.9.3-p194/bundler/gems/finance-990fd53d46c3/lib/finance/cashflows.rb:117:in `each'
/Users/ctwiz/.rvm/gems/ruby-1.9.3-p194/bundler/gems/finance-990fd53d46c3/lib/finance/cashflows.rb:117:in `inject'
/Users/ctwiz/.rvm/gems/ruby-1.9.3-p194/bundler/gems/finance-990fd53d46c3/lib/finance/cashflows.rb:117:in `xnpv'
/Users/ctwiz/.rvm/gems/ruby-1.9.3-p194/bundler/gems/finance-990fd53d46c3/lib/finance/cashflows.rb:35:in `values'
/Users/ctwiz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/bigdecimal/jacobian.rb:61:in `dfdxi'
/Users/ctwiz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/bigdecimal/jacobian.rb:80:in `block in jacobian'
/Users/ctwiz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/bigdecimal/jacobian.rb:79:in `each'
/Users/ctwiz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/bigdecimal/jacobian.rb:79:in `jacobian'
/Users/ctwiz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/bigdecimal/newton.rb:58:in `nlsolve'
/Users/ctwiz/.rvm/gems/ruby-1.9.3-p194/bundler/gems/finance-990fd53d46c3/lib/finance/cashflows.rb:100:in `xirr'
actionpack (3.2.11) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.11) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.11) lib/action_view/template.rb:143:in `render'

@marksweston
Copy link
Owner

@ctwiz is this still a live issue for you?

@marksweston marksweston self-assigned this Nov 25, 2015
@wQwRtaufxJw7UFLCXzXz
Copy link
Author

@marksweston I'm no longer attached to that project. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants