Skip to content

Commit

Permalink
final small touches
Browse files Browse the repository at this point in the history
  • Loading branch information
meagangardner committed Feb 1, 2025
1 parent 0fa0065 commit 1ba5796
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,23 @@ from financecalculator2025.n_periods import n_periods
```
payment = calculate_contribution(principal=20000, future_value=0, annual_rate=5, n_periods=24)
```

- If you need to calculate future value of an investment, you can use `future_value` function:

```
future_value = future_value(principal=5000, annual_rate=7, n_periods=36, contribution=200)
```

<img src="https://github.com/UBC-MDS/FinanceCalculator2025/blob/main/img/fv_df_output.png?raw=true">

<img src="https://github.com/UBC-MDS/FinanceCalculator2025/blob/main/img/fv_df_output.png?raw=true" height="75">
- If you need to calculate present value for a target amount, you can use `present_value` function:

```
present_value = present_value(principal=5000, annual_rate=4, n_periods=120, contribution=50)
```

<img src="https://github.com/UBC-MDS/FinanceCalculator2025/blob/main/img/pv_df_output.png?raw=true">

<img src="https://github.com/UBC-MDS/FinanceCalculator2025/blob/main/img/pv_df_output.png?raw=true" height="75">
- If you need to calculate the number of months to reach a goal, , you can use `n_periods` function:

```
Expand Down
4 changes: 0 additions & 4 deletions src/financecalculator2025/n_periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,5 @@ def n_periods(principal, annual_rate, future_value, contribution=0):
# return a positive integar
n_periods = max(1, round(n_periods))

# warning: if n_periods less than 5
if 1 <= n_periods <= 5:
warnings.warn("The number of periods is unusually low. Did you accidentally input years instead of months?", UserWarning)

return n_periods

9 changes: 1 addition & 8 deletions tests/test_n_periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_n_periods_positive_values():

def test_principal_equal_to_future_value():
# situation with principal = future_value, should return 0
assert n_periods(1000, 5, 1000, contribution=100) == 0
assert n_periods(1000, 6, 1000, contribution=100) == 0

def test_n_periods_negative_values():
# situation with all negative
Expand Down Expand Up @@ -63,13 +63,6 @@ def test_n_periods_low_interest_warning():
assert len(w) == 1
assert issubclass(w[-1].category, UserWarning)

# Test warning appears for n_periods < 6 months
def test_n_periods_low_periods_warning():
with warnings.catch_warnings(record=True) as w:
n_periods(1000, 5, 1500, contribution=100)
assert len(w) == 1
assert issubclass(w[-1].category, UserWarning)

# Test warning appears for negative annual_rate:
def test_n_periods_negative_interest_warning():
with warnings.catch_warnings(record=True) as w:
Expand Down

0 comments on commit 1ba5796

Please sign in to comment.