Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/bundler/pry-byebug-3.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
julianolf authored Aug 9, 2023
2 parents b08a2af + 535f63a commit 1725af8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,23 @@ To use Exonio you just have to call the method you like to use. Example:

### EFFECT

The Excel EFFECT function returns the effective annual interest rate, given a nominal interest rate and the number of compounding periods per year.
The Excel EFFECT function returns the effective annual interest rate, given a nominal interest rate and the number of compounding periods per year.
Effective annual interest rate is the interest rate actually earned due to compounding.
More about this function [EFFECT](https://exceljet.net/excel-functions/excel-effect-function)

```ruby
Exonio.effect(0.05, 10 * 12) # ==> 0.05126014873337037
```

### NOMINAL

The Excel NOMINAL function returns the nominal interest rate when given an effective annual interest rate and the number of compounding periods per year. The effective rate is the actual rate due to compounding. The nominal rate is typically the stated rate.
More about this function [NOMINAL](https://exceljet.net/functions/nominal-function)

```ruby
Exonio.nominal(0.05, 12 / 6) # ==> 0.04939015319191986
```

### FV

What is the future value after 10 years of saving $100 now, with
Expand Down
16 changes: 16 additions & 0 deletions lib/exonio/financial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ def effect(rate, nper)
(1 + rate / nper) ** nper - 1
end

# Calculates the nominal interest rate when given an effective annual interest rate and the number of compounding periods per year.
# The effective rate is the actual rate due to compounding. The nominal rate is typically the stated rate.
#
# @param rate [Float] The effective annual interest rate as decimal (not per cent).
# @param npery [Integer] Number of compounding periods per year.
#
# @return [Float]
#
# @example
# Exonio.nominal(0.05, 12 / 2) # ==> 0.04939015319191986
#
def nominal(rate, npery)
npery * ((1 + rate)**(1.0/npery) - 1)
end


# Calculates the future value of an annuity investment based on
# constant-amount periodic payments and a constant interest rate.
#
Expand Down
11 changes: 11 additions & 0 deletions spec/financial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
end
end

describe '#nominal' do
let(:rate) { 0.05 }
let(:npery) { 12 / 6 }

it 'computes nominal with default arguments' do
results = Exonio.nominal(rate, npery)

expect(results).to eq(0.04939015319191986)
end
end

describe '#fv' do
let(:rate) { 0.05 / 12 }
let(:nper) { 12 * 10 }
Expand Down

0 comments on commit 1725af8

Please sign in to comment.