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

Add EFFECT formula #21

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ To use Exonio you just have to call the method you like to use. Example:

## Available Formulas

### EFFECT

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
```

### FV

What is the future value after 10 years of saving $100 now, with
Expand Down
17 changes: 17 additions & 0 deletions lib/exonio/financial.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
module Exonio
module Financial
# Calculates the effective annual interest rate, given a nominal interest rate and the number of
# compounding periods. Nominal interest rate is the stated rate on the financial product.
# Effective annual interest rate is the interest rate actually earned due to compounding.
# constant-amount periodic payments and a constant interest rate.
#
# @param rate [Float] The nominal interest rate as decimal (not per cent) per period
# @param nper [Integer] The number of compounding periods
#
# @return [Float]
#
# @example
# Exonio.effect(0.05, 12 * 10) # ==> 0.05126014873337037
#
def effect(rate, nper)
(1 + rate / nper) ** nper - 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 @@ -2,6 +2,17 @@
require 'bigdecimal'

describe Exonio::Financial do
describe '#effect' do
let(:rate) { 0.05 }
let(:nper) { 12 * 10 }

it 'computes effect with default arguments' do
results = Exonio.effect(rate, nper)

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

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