function calculateROI() {
// Get Inputs
var price = parseFloat(document.getElementById('purchasePrice').value);
var down = parseFloat(document.getElementById('downPayment').value);
var rate = parseFloat(document.getElementById('interestRate').value);
var years = parseFloat(document.getElementById('loanTerm').value);
var rent = parseFloat(document.getElementById('monthlyRent').value);
var expenses = parseFloat(document.getElementById('monthlyExpenses').value);
// Validation to prevent NaN errors
if (isNaN(price) || isNaN(down) || isNaN(rate) || isNaN(years) || isNaN(rent) || isNaN(expenses)) {
// Do not run calculation if fields are empty, or handle gracefully
return;
}
// 1. Calculate Mortgage Payment (P&I)
// Formula: M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1 ]
var principal = price – down;
var monthlyRate = (rate / 100) / 12;
var numberOfPayments = years * 12;
var mortgagePayment = 0;
if (monthlyRate > 0) {
mortgagePayment = principal * (monthlyRate * Math.pow(1 + monthlyRate, numberOfPayments)) / (Math.pow(1 + monthlyRate, numberOfPayments) – 1);
} else {
mortgagePayment = principal / numberOfPayments;
}
// 2. Calculate Totals
var totalMonthlyExpenses = mortgagePayment + expenses;
var monthlyCashFlow = rent – totalMonthlyExpenses;
var annualCashFlow = monthlyCashFlow * 12;
// 3. Calculate Cash on Cash Return
// CoC = Annual Pre-Tax Cash Flow / Total Cash Invested (assuming Down Payment is total investment for this simplified calc)
var cashOnCash = 0;
if (down > 0) {
cashOnCash = (annualCashFlow / down) * 100;
}
// 4. Update UI
document.getElementById('resMortgage').innerText = "$" + mortgagePayment.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
document.getElementById('resTotalExpenses').innerText = "$" + totalMonthlyExpenses.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
var mcfEl = document.getElementById('resMonthlyCashFlow');
mcfEl.innerText = "$" + monthlyCashFlow.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
mcfEl.style.color = monthlyCashFlow >= 0 ? "#27ae60" : "#c0392b";
var acfEl = document.getElementById('resAnnualCashFlow');
acfEl.innerText = "$" + annualCashFlow.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
acfEl.style.color = annualCashFlow >= 0 ? "#27ae60" : "#c0392b";
var cocEl = document.getElementById('resCoC');
cocEl.innerText = cashOnCash.toFixed(2) + "%";
cocEl.style.color = cashOnCash >= 0 ? "#27ae60" : "#c0392b";
document.getElementById('resultBox').style.display = 'block';
}
Understanding Rental Property Cash Flow
Investing in real estate is one of the most reliable ways to build wealth, but it requires precise calculations to ensure profitability. The most critical metric for any buy-and-hold investor is Cash Flow. Cash flow is the net amount of money moving into or out of a business, project, or financial product. For a rental property, it is calculated by subtracting all operating expenses and debt service from the gross rental income.
How to Use This Calculator
This calculator helps you determine two key performance indicators: Monthly Cash Flow and Cash on Cash Return (CoC). Here is what the inputs represent:
Purchase Price: The total cost to buy the property.
Down Payment: The cash amount you pay upfront. This allows the calculator to determine your loan amount.
Interest Rate & Term: Used to calculate your monthly principal and interest (mortgage) payments.
Monthly Expenses: This should include property taxes, insurance, HOA fees, property management fees, and a budget for repairs/vacancy.
What is a Good Cash on Cash Return?
Cash on Cash Return measures the annual return the investor made on the property in relation to the amount of mortgage paid during the same year. It is considered one of the most important ROI metrics because it looks at the actual cash invested rather than the total loan value.
While "good" is subjective, many investors target the following ranges:
8-12%: Considered a solid return in most stable markets.
15%+: Excellent return, often found in lower-cost markets or properties requiring renovation.
Below 5%: May be risky unless the property is in a high-appreciation area.
Example Calculation Scenarios
Let's look at how different inputs affect your bottom line using a standard rental scenario:
Scenario
Rent
Mortgage + Expenses
Monthly Cash Flow
Annual ROI
Positive Cash Flow
$2,200
$1,800
+$400
~9.6%
Break Even
$1,800
$1,800
$0
0%
Negative Cash Flow
$1,500
$1,800
-$300
-7.2%
Why Operating Expenses Matter
Many novice investors make the mistake of only subtracting the mortgage payment from the rent. However, you must account for Operating Expenses (OpEx). As a rule of thumb, expenses (excluding the mortgage) often eat up 35% to 50% of the gross rent. Always include:
Vacancy Rate: Assume the property sits empty for 1 month a year (approx. 8%).
Maintenance: Set aside 5-10% of rent for future repairs (roof, HVAC, etc.).
Property Management: Usually 8-10% of monthly rent if you hire a professional manager.
Use the calculator above to adjust your offer price or down payment until you reach your desired Cash on Cash Return.