From f57ef932a3db52e80c7187ef599d313a217f6de1 Mon Sep 17 00:00:00 2001 From: Amark19 Date: Sun, 9 Nov 2025 21:44:37 +0530 Subject: [PATCH] added step up in sip calculator --- .../templates/calculator/SIP_calculator.html | 12 ++++- staticfiles/js/calculator/SIP_calculator.js | 45 +++++++++++-------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/mysite/templates/calculator/SIP_calculator.html b/mysite/templates/calculator/SIP_calculator.html index dee3467..78a6f7b 100644 --- a/mysite/templates/calculator/SIP_calculator.html +++ b/mysite/templates/calculator/SIP_calculator.html @@ -2,7 +2,7 @@ {% block MDesc %} Calculate SIP and Lumpsum returns with interactive sliders. Estimate your wealth creation through systematic investment plans in mutual funds. {% endblock %} -{% block MKW %}SIP calculator,calculator of sip,sip calculator india,systematic investment plan calculator,lumpsum calculator,mutual fund calculator,sip returns calculator{% endblock %} +{% block MKW %}SIP calculator,Step Up SIP Calculator,sip calculator india,systematic investment plan calculator,lumpsum calculator,mutual fund calculator,sip returns calculator{% endblock %} {% block Mr %} {% now "d/m/Y" %} {% endblock %} @@ -204,6 +204,16 @@

SIP Calculator

+ +
+ + +
+
+
+ +
+
diff --git a/staticfiles/js/calculator/SIP_calculator.js b/staticfiles/js/calculator/SIP_calculator.js index 9520e83..57dcfbf 100644 --- a/staticfiles/js/calculator/SIP_calculator.js +++ b/staticfiles/js/calculator/SIP_calculator.js @@ -35,26 +35,30 @@ function getMonthlyRate(annualReturn) { } // Calculate SIP -function calculateSIP(monthlyInvestment, annualReturn, years) { +function calculateSIP(monthlyInvestment, annualReturn, years, stepUpPercent = 0) { const monthlyRate = getMonthlyRate(annualReturn); - const totalMonths = years * 12; - - const totalInvested = monthlyInvestment * totalMonths; + let totalInvested = 0; let totalValue = 0; - - if (monthlyRate > 0) { - const factor = (Math.pow(1 + monthlyRate, totalMonths) - 1) / monthlyRate; - totalValue = monthlyInvestment * factor * (1 + monthlyRate); - } else { - totalValue = totalInvested; + + let currentInvestment = monthlyInvestment; + const stepUpMultiplier = 1 + (stepUpPercent / 100); + + for (let year = 1; year <= years; year++) { + // For each year, do 12 months of SIP + for (let month = 1; month <= 12; month++) { + totalInvested += currentInvestment; + const monthsRemaining = (years - year) * 12 + (12 - month + 1); + totalValue += currentInvestment * Math.pow(1 + monthlyRate, monthsRemaining); + } + currentInvestment *= stepUpMultiplier; // Increase SIP for next year } - + const estimatedReturns = totalValue - totalInvested; - + return { - totalInvested: totalInvested, - estimatedReturns: estimatedReturns, - totalValue: totalValue + totalInvested, + estimatedReturns, + totalValue }; } @@ -80,8 +84,9 @@ function updateResults() { const monthlyInvestment = parseFloat(document.getElementById('monthlyInvestment').value); const annualReturn = parseFloat(document.getElementById('expectedReturn').value); const years = parseInt(document.getElementById('timePeriod').value); - - result = calculateSIP(monthlyInvestment, annualReturn, years); + const stepUpPercent = parseFloat(document.getElementById('sipStepup').value); + + result = calculateSIP(monthlyInvestment, annualReturn, years, stepUpPercent); } else { const lumpsumAmount = parseFloat(document.getElementById('lumpsumAmount').value); const annualReturn = parseFloat(document.getElementById('lumpsumReturn').value); @@ -111,7 +116,9 @@ function updateDisplays() { const monthlyInvestment = parseFloat(document.getElementById('monthlyInvestment').value); const annualReturn = parseFloat(document.getElementById('expectedReturn').value); const years = parseInt(document.getElementById('timePeriod').value); - + const stepUpPercent = parseFloat(document.getElementById('sipStepup').value); + + document.getElementById('sipStepupDisplay').value = formatPercentage(stepUpPercent); document.getElementById('monthlyInvestmentDisplay').value = formatCurrency(monthlyInvestment); document.getElementById('expectedReturnDisplay').value = formatPercentage(annualReturn); document.getElementById('timePeriodDisplay').value = formatYears(years); @@ -119,6 +126,7 @@ function updateDisplays() { updateSliderFill('monthlyInvestment', 'monthlyInvestmentFill'); updateSliderFill('expectedReturn', 'expectedReturnFill'); updateSliderFill('timePeriod', 'timePeriodFill'); + updateSliderFill('sipStepup', 'sipStepupFill'); } else { const lumpsumAmount = parseFloat(document.getElementById('lumpsumAmount').value); const annualReturn = parseFloat(document.getElementById('lumpsumReturn').value); @@ -178,6 +186,7 @@ document.getElementById('lumpsumToggle').addEventListener('click', function() { document.getElementById('monthlyInvestment').addEventListener('input', updateDisplays); document.getElementById('expectedReturn').addEventListener('input', updateDisplays); document.getElementById('timePeriod').addEventListener('input', updateDisplays); +document.getElementById('sipStepup').addEventListener('input', updateDisplays); // Lumpsum sliders event listeners document.getElementById('lumpsumAmount').addEventListener('input', updateDisplays);