### Install FastXirr Gem via CLI Source: https://github.com/fintual-oss/fast-xirr/blob/main/README.md Command to install the FastXirr gem directly from RubyGems using the command-line interface. This is useful for quick setup or testing outside of a project's Gemfile. -------------------------------- ### Test FastXirr Gem Source: https://github.com/fintual-oss/fast-xirr/blob/main/README.md Instructions for running the test suite for the FastXirr gem. This requires installing development dependencies via Bundler and then executing the tests using the `rake` command. ```bash bundle install rake test ``` -------------------------------- ### Install FastXirr Gem via RubyGems Source: https://github.com/fintual-oss/fast-xirr/blob/main/README.md Instructions for adding the FastXirr gem to your project's Gemfile and installing it using Bundler. This is the standard method for integrating the gem into a Ruby application. ```ruby gem 'fast_xirr' ``` ```bash bundle install ``` -------------------------------- ### Build FastXirr Gem from Source Source: https://github.com/fintual-oss/fast-xirr/blob/main/README.md Steps to build the FastXirr gem from its source code. This involves cloning the repository, building the gem file using the gemspec, and then installing the local gem file. ```bash git clone https://github.com/fintual-oss/fast-xirr.git cd fast_xirr gem build fast_xirr.gemspec # This will create a .gem file, e.g., fast_xirr-1.x.x.gem gem install ./fast_xirr*.gem ``` -------------------------------- ### Configure XIRR Calculation Options Source: https://github.com/fintual-oss/fast-xirr/blob/main/README.md Illustrates how to customize XIRR calculations by setting tolerance (`tol`), maximum iterations (`max_iter`), and the initial bracket interval (`initial_bracket`) for Brent's method. These parameters can help improve convergence or performance. ```ruby require 'fast_xirr' require 'date' cashflows = [ [1000, Date.new(1985, 1, 1)], [-600, Date.new(1990, 1, 1)], [-6000, Date.new(1995, 1, 1)] ] result = FastXirr.calculate(cashflows: cashflows, tol: 1e-2, max_iter: 100) puts "XIRR: #{result}" # => XIRR: 0.22305878076614422 result = FastXirr.calculate(cashflows: cashflows, tol: 1e-8, max_iter: 2) puts "XIRR: #{result}" # => XIRR: NaN # You can also specify the initial bracket (search interval) for Brent's method result = FastXirr.calculate( cashflows: cashflows, initial_bracket: [-0.5, 5.0] ) puts "XIRR: #{result}" # => XIRR: 0.22568333743016633 ``` -------------------------------- ### Calculate XIRR with FastXirr Source: https://github.com/fintual-oss/fast-xirr/blob/main/README.md Demonstrates the basic usage of the FastXirr gem to calculate the Extended Internal Rate of Return (XIRR) for a given set of cash flows and dates. The cash flows are provided as an array of [amount, date] pairs. ```ruby require 'fast_xirr' require 'date' cashflows = [ [1000, Date.new(1985, 1, 1)], [-600, Date.new(1990, 1, 1)], [-6000, Date.new(1995, 1, 1)] ] result = FastXirr.calculate(cashflows: cashflows) puts "XIRR: #{result}" # => XIRR: 0.22568401743016633 ``` -------------------------------- ### Handle XIRR Calculation Failure (NaN) Source: https://github.com/fintual-oss/fast-xirr/blob/main/README.md Shows how FastXirr handles cases where a solution cannot be found, returning `nan`. It also demonstrates how to check if the result is `nan` using the `.nan?` method. ```ruby require 'fast_xirr' require 'date' result = FastXirr.calculate(cashflows: [[1000, Date.new(1985, 1, 1)]]) puts "XIRR: #{result}" # => XIRR: NaN result.nan? # => true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.