Lånekalkylator
body {
font-family: Arial, sans-serif;
padding: 20px;
max-width: 600px;
margin: auto;
}
label, select, input, button {
display: block;
margin: 10px 0;
width: 100%;
}
.result {
margin-top: 20px;
}
Lånekalkylator
Lånebelopp:
Ränta (% per år):
Amorteringstid (år):
Uppläggningsavgift:
Aviavgift (per betalningstillfälle):
Betalningstillfällen:
Månadsvis
Kvartalsvis
Beräkna
Månadskostnad:
Total kostnad:
Effektiv ränta:
function calculateLoan() {
const loanAmount = parseFloat(document.getElementById(’loanAmount’).value);
const interestRate = parseFloat(document.getElementById(’interestRate’).value) / 100;
const amortizationPeriodYears = parseFloat(document.getElementById(’amortizationPeriodYears’).value);
const setupFee = parseFloat(document.getElementById(’setupFee’).value);
const invoiceFee = parseFloat(document.getElementById(’invoiceFee’).value);
const paymentFrequency = document.getElementById(’paymentFrequency’).value === ’monthly’ ? 12 : 4;
const totalPayments = amortizationPeriodYears * paymentFrequency;
const monthlyPayment = calculateMonthlyPayment(loanAmount, interestRate / paymentFrequency, totalPayments) + (invoiceFee * paymentFrequency / 12);
const totalCost = monthlyPayment * totalPayments + setupFee;
let effectiveInterestRate = calculateEffectiveInterestRate(loanAmount + setupFee, invoiceFee, amortizationPeriodYears, paymentFrequency, monthlyPayment);
document.getElementById(’monthlyPayment’).innerHTML = `Månadskostnad: ${monthlyPayment.toFixed(2)} kr`;
document.getElementById(’totalCost’).innerHTML = `Total kostnad: ${totalCost.toFixed(2)} kr`;
document.getElementById(’effectiveInterestRate’).innerHTML = `Effektiv ränta: ${effectiveInterestRate.toFixed(2)}%`;
}
function calculateMonthlyPayment(principal, monthlyInterestRate, totalPayments) {
return principal * (monthlyInterestRate / (1 – Math.pow(1 + monthlyInterestRate, -totalPayments)));
}
function calculateEffectiveInterestRate(principal, invoiceFee, years, paymentFrequency, monthlyPayment) {
let low = 0, high = 1;
let mid = 0, npv = 0, iteration = 0;
const maxIterations = 10000, tolerance = 0.0001;
const totalPayments = years * paymentFrequency;
while (low < high && iteration < maxIterations) { mid = (low + high) / 2; npv = -principal; for (let i = 1; i 0) { high = mid; } else { low = mid + tolerance; } iteration++; } return mid * paymentFrequency * 100; // Convert to an annual rate } \n\n[/cs_content_seo][/cs_element_layout_column][/cs_element_layout_row][/cs_element_section][/cs_content]