Investment ROI Calculator
Calculate the Return on Investment (ROI) for your investment. ROI is a performance measure used to evaluate the efficiency of an investment or compare the efficiency of a number of different investments. ROI measures the amount of return on a particular investment, relative to the investment's cost. To calculate ROI, the benefit (or return) of an investment is divided by the cost of the investment.
Initial Investment:
Current Value / Final Sale Price:
Time Period (in years):
Calculate ROI
function calculateROI() {
var initialInvestment = parseFloat(document.getElementById("initialInvestment").value);
var currentValue = parseFloat(document.getElementById("currentValue").value);
var timePeriodYears = parseFloat(document.getElementById("timePeriodYears").value);
var roiPercentageElement = document.getElementById("roiPercentage");
var annualizedROIElement = document.getElementById("annualizedROI");
if (isNaN(initialInvestment) || isNaN(currentValue) || isNaN(timePeriodYears) || initialInvestment <= 0 || timePeriodYears <= 0) {
roiPercentageElement.textContent = "Please enter valid positive numbers for all fields.";
annualizedROIElement.textContent = "";
return;
}
var profit = currentValue – initialInvestment;
var roi = (profit / initialInvestment) * 100;
var annualizedROI = (roi / timePeriodYears);
roiPercentageElement.textContent = "Return on Investment (ROI): " + roi.toFixed(2) + "%";
annualizedROIElement.textContent = "Annualized ROI: " + annualizedROI.toFixed(2) + "%";
}
#roi-calculator {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 5px;
max-width: 500px;
margin: 20px auto;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
}
#roi-calculator button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
#roi-calculator button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
padding-top: 15px;
border-top: 1px solid #eee;
}
#result h3 {
margin-top: 0;
}
#result p {
margin-bottom: 8px;
}