<?php
function calculateDSCR($interest_rate, $fixed_or_arm, $io_term, $loan_amount, $taxes, $insurance, $hoa, $gross_rent) {
// Convert annual interest rate to a monthly rate
$monthly_interest_rate = $interest_rate / 100 / 12;
$io_months = 0; // Default

// Determine the number of months based on IO term description
switch ($io_term) {
case '18 Month Interest Only No Impounds':
$io_months = 18;
break;
case '24 Month Interest Only':
$io_months = 24;
break;
case '36 Month Interest Only':
$io_months = 36;
break;
case '30 Year Due In 5 Year PITI':
$io_months = 60; // Assuming this term means a 30-year loan with something specific happening in the first 5 years
break;
}

// Calculate monthly payment
if ($io_months > 0) {
$monthly_payment = $loan_amount * $monthly_interest_rate; // Interest-only payment
} else {
$n = 360; // Total number of payments (30 years x 12 months)
$monthly_payment = $loan_amount * ($monthly_interest_rate * pow(1 + $monthly_interest_rate, $n)) / (pow(1 + $monthly_interest_rate, $n) - 1);
}

// Calculate PITIA payment
$pitia_payment = $monthly_payment + $taxes + $insurance + $hoa;

// Calculate DSCR
$dscr = $gross_rent / $pitia_payment;

return $dscr;
}

// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$interest_rate = floatval($_POST['interest_rate']);
$fixed_or_arm = $_POST['fixed_or_arm'];
$io_term = $_POST['io_term'];
$loan_amount = floatval($_POST['loan_amount']);
$taxes = floatval($_POST['taxes']);
$insurance = floatval($_POST['insurance']);
$hoa = floatval($_POST['hoa']);
$gross_rent = floatval($_POST['gross_rent']);

$dscr = calculateDSCR($interest_rate, $fixed_or_arm, $io_term, $loan_amount, $taxes, $insurance, $hoa, $gross_rent);

echo "DSCR: " . number_format($dscr, 3) . "<br>";
echo $dscr >= 1.0 ? "Loan qualifies for DSCR." : "Loan does not qualify for DSCR.";
}
?>

<!-- HTML form for input -->
<form method="post">
Interest Rate (%): <input type="text" name="interest_rate"><br>
Fix or ARM (Enter 'Fix' or 'ARM'): <input type="text" name="fixed_or_arm"><br>
IO Term: <select name="io_term">
<option value="0">Select IO Term</option>
<option value="18 Month Interest Only No Impounds">18 Month Interest Only No Impounds</option>
<option value="24 Month Interest Only">24 Month Interest Only</option>
<option value="36 Month Interest Only">36 Month Interest Only</option>
<option value="30 Year Due In 5 Year PITI">30 Year Due In 5 Year PITI</option>
</select><br>
Loan Amount ($): <input type="text" name="loan_amount"><br>
Taxes ($): <input type="text" name="taxes"><br>
Insurance ($): <input type="text" name="insurance"><br>
HOA ($, enter 0 if not applicable): <input type="text" name="hoa"><br>
Gross Rent ($): <input type="text" name="gross_rent"><br>
<input type="submit" value="Calculate DSCR">
</form>

Get started with your Digital Mortgage

No hassle, no obligation

Get Started Now!

This site uses cookies to process your loan application and other features. You may elect not to accept cookies which will keep you from submitting a loan application. By your clicked consent/acceptance you acknowledge and allow the use of cookies. By clicking I Accept you acknowledge you have read and understand Accelerated Lending Group's Privacy Policy.