Understanding your rate of return (RoR) is crucial for evaluating the profitability of an investment over a specific period. It's a fundamental metric that helps investors compare the performance of different assets and strategies. The rate of return expresses the gain or loss on an investment as a percentage of the initial investment.
function calculateRateOfReturn() {
var initialInvestment = parseFloat(document.getElementById("initialInvestment").value);
var finalValue = parseFloat(document.getElementById("finalValue").value);
var investmentPeriod = parseFloat(document.getElementById("investmentPeriod").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(initialInvestment) || isNaN(finalValue) || isNaN(investmentPeriod) || initialInvestment <= 0 || investmentPeriod <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
var profitOrLoss = finalValue – initialInvestment;
var rateOfReturn = (profitOrLoss / initialInvestment) * 100;
var annualRateOfReturn = rateOfReturn / investmentPeriod;
var resultHTML = "