Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:44:49+00:00 2026-05-24T02:44:49+00:00

I would like to use the bigdecimal/newton module in Ruby for an implementation of

  • 0

I would like to use the bigdecimal/newton module in Ruby for an implementation of XIRR. I have written a script to try it out by following this example.

When I run the code (Ruby 1.9.2 on Mac OS X 10.6), I get the following error:

/opt/local/lib/ruby1.9/1.9.1/bigdecimal/ludcmp.rb:84:in `div': wrong number of arguments(2 for 1) (ArgumentError)
   from /opt/local/lib/ruby1.9/1.9.1/bigdecimal/ludcmp.rb:84:in `block in lusolve'
   from /opt/local/lib/ruby1.9/1.9.1/bigdecimal/ludcmp.rb:78:in `downto'
   from /opt/local/lib/ruby1.9/1.9.1/bigdecimal/ludcmp.rb:78:in `lusolve'
   from /opt/local/lib/ruby1.9/1.9.1/bigdecimal/newton.rb:60:in `nlsolve'
   from gistfile1.rb:52:in `<main>'

Is this because of an error in my program, or something in the
BigDecimal library?

#!/opt/local/bin/ruby1.9
require 'bigdecimal'
require 'bigdecimal/newton'
require 'time'
include Newton

transactions = [
  {amount:BigDecimal::new("-1000"), date:Time.parse("2011-01-01")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-02-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-03-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-04-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-05-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-06-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-07-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-08-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-09-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-10-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-11-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2011-12-11")},
  {amount:BigDecimal::new("100"), date:Time.parse("2012-01-11")},
]

class Function
  values ={ eps: "1.0e-16", one: "1.0", two: "2.0", ten: "10.0", zero: "0.0" }

  values.each do |key, value|
    define_method key do
      BigDecimal::new value
    end
  end

  def initialize(transactions)
    @transactions = transactions
  end

  def values(x)
    start = @transactions[0][:date]
    value = []

    value << @transactions.reduce(0) do |sum, t|
      pwr = (t[:date] - start) / 365
      r = t[:amount] / (1.0 + x[0]) ** pwr
      sum + r
    end

    value
  end
end

f = Function.new(transactions)
x = [f.zero]
n = nlsolve(f,x)
puts x

Any debugging assistance would be greatly appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:44:49+00:00Added an answer on May 24, 2026 at 2:44 am

    The problem is that you are mixing BigDecimals with “normal” numbers in your calculation.
    Try to replace values by this:

    values = { 
      eps: BigDecimal.new("1.0e-16"), 
      one: BigDecimal.new("1.0"), 
      two: BigDecimal.new("2.0"), 
      ten: BigDecimal.new("10.0"), 
      zero: BigDecimal.new("0.0") 
    }
    

    and the block in def values(x) by

    value << @transactions.reduce(0) do |sum, t|
      pwr = (t[:date] - start) / BigDecimal.new("365.0")
      r = t[:amount] / (BigDecimal.new("1.0") + x[0]) ** pwr
      sum + r
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like use a panel whose children have coordinates specified as percentage of
I currently have some large strings that I would like use as test data
Designing my RESTful API, I would like use following URI http://[HOST]/[PLANET]/[LAT];[LONG] e.g. http://myserver/earth/50.2;29.1 What
I am using AdoNetAppender (SQL server) in my asp.net application and would like use
I would like to use a language that I am familiar with - Java,
I would like to use something like CLR Profiles on .Net 2.0 to see
I would like to use as and is as members of an enumeration. I
I would like to use a component that exposes the datasource property, but instead
I would like to use client-side Javascript to perform a DNS lookup (hostname to
I would like to use javascript to develop general-purpose GUI applications. Initially these are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.