Utilities for computing durations as decimal months and for discrete month-by-month compounding. Built in Python with pandas. Sized for quick Hacktoberfest contributions.
-
months_elapsed_decimal(start, end, eom_rule=True)
Returns elapsed time as decimal months. Counts whole calendar months first, then a final fractional month. End-of-month aware. -
compounded_value(principal, monthly_rate, start, end)
Computes value under discrete monthly compounding. Applies whole months as powers, then a pro-rata fractional month.
- Python 3.12
- pandas and pytest are installed via the steps below
-
Ensure
uvis installed and on your PATH
uv --version -
Create a fresh environment and install locked dependencies
uv sync -
Run tests
uv run pytest
-
Create a virtual environment
python3 -m venv .venv
. .venv/bin/activate -
Install dependencies
pip install -r requirements.txt -
Run tests
python -m pytest
Python API
from settlementcalculator import months_elapsed_decimal, compounded_value
# Decimal months
m = months_elapsed_decimal('2024-01-31', '2024-03-15')
print(round(m, 4)) # expected about 1.4839
# Discrete monthly compounding
v = compounded_value(principal=1000.0, monthly_rate=0.01,
start='2024-01-31', end='2024-03-15')
print(round(v, 2))2024-01-31 to 2024-02-29 → 1.0
2023-01-31 to 2023-02-28 → 1.0
2024-01-31 to 2024-03-15 → about 1.4839
2025-03-01 to 2025-03-31 → about 0.9677
same day → 0.0
• pyproject.toml and uv.lock define and lock dependencies
• requirements.txt is provided for pip users
• Tests live under tests/
• .python-version pins 3.12
• In pyproject.toml set requires-python = ">=3.12,<3.13"
• Keep pull requests small and focused
• Add or update tests when behaviour changes
• If you are here for Hacktoberfest
• the repository topic hacktoberfest should be set by a maintainer
• merged pull requests count after the seven-day review window