From 2a457c28ae57ee5d37ddc6c7453ae004ed28cf7c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 25 May 2026 08:43:06 +0000 Subject: [PATCH] feat: add calculateSIP utility with rounded monthly projections Agent-Logs-Url: https://github.com/Tejas164321/FinPal/sessions/c977c4a9-6c5a-491b-83b7-441e7e58963d Co-authored-by: Tejas164321 <157705337+Tejas164321@users.noreply.github.com> --- src/lib/calculators.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/lib/calculators.ts diff --git a/src/lib/calculators.ts b/src/lib/calculators.ts new file mode 100644 index 0000000..6183e66 --- /dev/null +++ b/src/lib/calculators.ts @@ -0,0 +1,36 @@ +export interface SIPProjection { + month: number; + invested: number; + returns: number; + gain: number; +} + +export function calculateSIP( + monthlyAmount: number, + annualReturnRate: number, + years: number +): SIPProjection[] { + const totalMonths = Math.max(0, Math.floor(years * 12)); + const monthlyRate = annualReturnRate / 12 / 100; + const projections: SIPProjection[] = []; + + for (let month = 1; month <= totalMonths; month += 1) { + const invested = monthlyAmount * month; + const returns = + monthlyRate === 0 + ? invested + : monthlyAmount * + (((Math.pow(1 + monthlyRate, month) - 1) / monthlyRate) * + (1 + monthlyRate)); + const gain = returns - invested; + + projections.push({ + month: Math.round(month), + invested: Math.round(invested), + returns: Math.round(returns), + gain: Math.round(gain), + }); + } + + return projections; +}