Mortgage · Calculation
Discounted rent versus buy cash flows
Measure the present-value difference between two housing paths using caller-supplied discount, investment-return, appreciation and cost-inflation assumptions.
Example result · monthlyOwnershipCosts.homePrice: 300000 See output
- Cost per success
- 2 calculation credits
- Production plans
- Standard, Business, Scale, Enterprise
Plan allowances - Free sandbox
- Not available
Integration example
Make a request
Use a production key scoped to rent-or-buy-discounted-cash-flow.
Keep the key on your server. A successful call uses 2 calculation credits.
Set HT_PRODUCTION_KEY on your server. Save as example.mjs and run node example.mjs with Node.js 18 or later.
import { randomUUID } from "node:crypto";
const key = process.env.HT_PRODUCTION_KEY;
if (!key) throw new Error("Set HT_PRODUCTION_KEY on your server.");
const endpoint = "https://calc.hasstechapi.com/v2/calc/rent-or-buy-discounted-cash-flow";
const input = {
"monthlyRent": 1500,
"annualRentIncreaseRate": 2,
"monthlyRentersInsurance": 20,
"homePrice": 300000,
"downPayment": 60000,
"interestRate": 0,
"loanTermYears": 20,
"annualPropertyTax": 3600,
"annualHomeInsurance": 1200,
"annualMaintenance": 3600,
"monthlyHOA": 100,
"buyingClosingCosts": 6000,
"annualHomeAppreciationRate": 2,
"annualInvestmentReturnRate": 3,
"annualDiscountRate": 4,
"yearsToAnalyze": 5,
"sellingCostRate": 5,
"annualOwnershipCostInflationRate": 2
};
const requestId = process.env.HT_REQUEST_ID || Date.now() + "." + randomUUID();
// Keep this ID to look up usage if the connection is interrupted.
console.error("Usage lookup ID:", requestId);
const response = await fetch(endpoint, {
method: "POST",
redirect: "error",
headers: {
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
"Idempotency-Key": requestId
},
body: JSON.stringify(input)
});
if (!response.ok) {
const problem = await response.json().catch(() => null);
const code = problem?.error?.code || response.statusText;
const delay = response.headers.get("retry-after");
if (delay) console.error("Retry-After (seconds):", delay);
console.error("HTTP " + response.status + " " + code + ". Usage lookup ID: " + requestId);
if (Array.isArray(problem?.error?.details)) {
for (const issue of problem.error.details) console.error("Input issue:", JSON.stringify(issue));
}
process.exitCode = 1;
} else {
console.log(JSON.stringify(await response.json(), null, 2));
} cURL (shell)
(
set -eu
: "${HT_PRODUCTION_KEY:?Set HT_PRODUCTION_KEY on your server}"
request_id="${HT_REQUEST_ID:-}"
if [ -z "$request_id" ]; then
request_id=$(python3 -c 'import time, uuid; print(str(time.time_ns() // 1000000) + "." + str(uuid.uuid4()))')
fi
printf 'Usage lookup ID: %s\n' "$request_id" >&2
# On INVALID_INPUT, read error.details in the JSON response body.
curl --disable --silent --show-error --fail-with-body --include \
--request POST 'https://calc.hasstechapi.com/v2/calc/rent-or-buy-discounted-cash-flow' \
--header "Authorization: Bearer $HT_PRODUCTION_KEY" \
--header 'Content-Type: application/json' \
--header "Idempotency-Key: $request_id" \
--data-binary @- <<'HT_INPUT'
{
"monthlyRent": 1500,
"annualRentIncreaseRate": 2,
"monthlyRentersInsurance": 20,
"homePrice": 300000,
"downPayment": 60000,
"interestRate": 0,
"loanTermYears": 20,
"annualPropertyTax": 3600,
"annualHomeInsurance": 1200,
"annualMaintenance": 3600,
"monthlyHOA": 100,
"buyingClosingCosts": 6000,
"annualHomeAppreciationRate": 2,
"annualInvestmentReturnRate": 3,
"annualDiscountRate": 4,
"yearsToAnalyze": 5,
"sellingCostRate": 5,
"annualOwnershipCostInflationRate": 2
}
HT_INPUT
) If your request fails
400 INVALID_INPUT-
Read
error.detailswhen present. Node prints each issue. cURL returns the JSON body. Eachpathpoints into your request. An empty path refers to the whole body.Check the accepted inputs for required fields, units and ranges. Send the corrected JSON as a new request.
401or403- Check that the server has the bearer key for the endpoint’s environment and that the key includes
rent-or-buy-discounted-cash-flow. 429- Read the service error code, check your allowance, and wait for the
Retry-Afterinterval when supplied before trying again. - Lost response,
409or503 - Open Request lookup, select the same environment and enter the printed usage lookup ID. A settled ID has already consumed credits. To retry the same calculation, set
HT_REQUEST_IDto the original ID and reuse the same inputs. A settled request does not return its result again. Unset the variable for a new request, which can consume credits.
The usage lookup ID is the Idempotency-Key your server sends. The response’s x-request-id identifies the HTTP exchange for support.
Output
Example result
These values come from running this operation on the example inputs.
monthlyOwnershipCosts.homePrice- 300000
monthlyOwnershipCosts.downPayment- 60000
monthlyOwnershipCosts.loanAmount- 240000
Full example response (JSON)
{
"status": "available",
"result": {
"monthlyOwnershipCosts": {
"homePrice": 300000,
"downPayment": 60000,
"loanAmount": 240000,
"buyingClosingCosts": 6000,
"monthlyPI": 1000,
"monthlyPropertyTax": 300,
"monthlyHomeInsurance": 100,
"monthlyMaintenance": 300,
"monthlyHOA": 100,
"totalMonthlyOwnershipCost": 1800
},
"rentingCosts": {
"totalRentingCost": 94872.72287999994,
"totalRentPaid": 93672.72287999994,
"totalRentersInsurancePaid": 1200,
"endingMonthlyRent": 1623.6482400000002
},
"opportunityCost": {
"initialDownPayment": 60000,
"annualInvestmentReturnRate": 3,
"yearsInvested": 5,
"futureValue": 69556.444458,
"investmentGain": 9556.444457999998
},
"yearlyProjection": [
{
"year": 1,
"annualOwnershipCost": 21600,
"annualRentCost": 18240,
"cumulativeOwnershipCost": 87600,
"cumulativeRentCost": 18240,
"homeValue": 306000.00000000023,
"loanBalance": 228000,
"principalPaid": 12000,
"interestPaid": 0,
"rawHomeEquity": 78000.00000000023,
"netSaleProceeds": 62700.00000000023,
"buyerInvestmentBalance": 0,
"renterInvestmentBalance": 71385.95343394014,
"buyerNetWorth": 62700.00000000023,
"renterNetWorth": 71385.95343394014,
"netWorthAdvantage": -8685.95343393991
},
{
"year": 2,
"annualOwnershipCost": 21792,
"annualRentCost": 18600,
"cumulativeOwnershipCost": 109392,
"cumulativeRentCost": 36840,
"homeValue": 312120.00000000035,
"loanBalance": 216000,
"principalPaid": 12000,
"interestPaid": 0,
"rawHomeEquity": 96120.00000000035,
"netSaleProceeds": 80514.00000000029,
"buyerInvestmentBalance": 0,
"renterInvestmentBalance": 76763.18779920148,
"buyerNetWorth": 80514.00000000029,
"renterNetWorth": 76763.18779920148,
"netWorthAdvantage": 3750.812200798813
},
{
"year": 3,
"annualOwnershipCost": 21987.839999999997,
"annualRentCost": 18967.2,
"cumulativeOwnershipCost": 131379.84000000008,
"cumulativeRentCost": 55807.19999999998,
"homeValue": 318362.40000000055,
"loanBalance": 204000,
"principalPaid": 12000,
"interestPaid": 0,
"rawHomeEquity": 114362.40000000055,
"netSaleProceeds": 98444.2800000005,
"buyerInvestmentBalance": 0,
"renterInvestmentBalance": 82128.03557028974,
"buyerNetWorth": 98444.2800000005,
"renterNetWorth": 82128.03557028974,
"netWorthAdvantage": 16316.244429710758
},
{
"year": 4,
"annualOwnershipCost": 22187.5968,
"annualRentCost": 19341.744000000002,
"cumulativeOwnershipCost": 153567.43680000014,
"cumulativeRentCost": 75148.944,
"homeValue": 324729.64800000086,
"loanBalance": 192000,
"principalPaid": 12000,
"interestPaid": 0,
"rawHomeEquity": 132729.64800000086,
"netSaleProceeds": 116493.16560000082,
"buyerInvestmentBalance": 0,
"renterInvestmentBalance": 87476.65107687705,
"buyerNetWorth": 116493.16560000082,
"renterNetWorth": 87476.65107687705,
"netWorthAdvantage": 29016.51452312377
},
{
"year": 5,
"annualOwnershipCost": 22391.348736,
"annualRentCost": 19723.778879999998,
"cumulativeOwnershipCost": 175958.78553600004,
"cumulativeRentCost": 94872.72287999994,
"homeValue": 331224.24096000113,
"loanBalance": 180000,
"principalPaid": 12000,
"interestPaid": 0,
"rawHomeEquity": 151224.24096000113,
"netSaleProceeds": 134663.02891200106,
"buyerInvestmentBalance": 0,
"renterInvestmentBalance": 92805.0037970757,
"buyerNetWorth": 134663.02891200106,
"renterNetWorth": 92805.0037970757,
"netWorthAdvantage": 41858.02511492536
}
],
"upfrontCashToClose": 66000,
"totalOwnershipCost": 175958.78553600004,
"totalRentingCost": 94872.72287999994,
"totalInterestPaid": 0,
"totalPrincipalPaid": 60000,
"finalBuyerNetWorth": 134663.02891200106,
"finalRenterNetWorth": 92805.0037970757,
"finalNetWorthAdvantage": 41858.02511492536,
"breakEvenYear": 2,
"buyNPV": -54932.11187652813,
"rentNPV": -89336.35735389893,
"npvAdvantage": 34404.2454773708,
"npvWinner": "buy",
"recommendation": "buy"
},
"formulaVersion": "rent-or-buy-discounted-cash-flow-htcalc-719df2c0e105",
"units": {
"upfrontCashToClose": "USD",
"totalOwnershipCost": "USD",
"totalRentingCost": "USD",
"totalPrincipalPaid": "USD",
"totalInterestPaid": "USD",
"buyNPV": "USD",
"rentNPV": "USD",
"npvAdvantage": "USD"
},
"assumptions": [],
"warnings": [],
"creditCost": 2
}Request contract
Accepted inputs
Fields for this example. Expand the schema for all supported combinations and limits.
FieldType, units and limits
monthlyRentRequiredUS dollars per month
Min 0 · Max 100000000annualRentIncreaseRateRequiredPercent; 5 means 5%
Min 0 · Max 100monthlyRentersInsuranceOptionalUS dollars per month
Min 0 · Max 100000000homePriceRequiredPositive US dollars
Min 0.01 · Max 1000000000downPaymentConditionalUS dollars
Min 0 · Max 1000000000downPaymentRateConditionalPercent; 5 means 5%
Min 0 · Max 100interestRateRequiredAnnual note rate in percent; 6 means 6%
Min 0 · Max 50loanTermYearsRequiredWhole years
Min 1 · Max 50annualPropertyTaxConditionalUS dollars per year
Min 0 · Max 1000000000propertyTaxRateConditionalPercent; 5 means 5%
Min 0 · Max 100annualHomeInsuranceConditionalUS dollars per year
Min 0 · Max 1000000000monthlyHomeInsuranceConditionalUS dollars per month
Min 0 · Max 100000000annualMaintenanceConditionalUS dollars per year
Min 0 · Max 1000000000maintenanceRateConditionalPercent; 5 means 5%
Min 0 · Max 100monthlyHOAOptionalUS dollars per month
Min 0 · Max 100000000buyingClosingCostsConditionalUS dollars
Min 0 · Max 1000000000buyingClosingCostsRateConditionalPercent; 5 means 5%
Min 0 · Max 100annualHomeAppreciationRateRequiredPercent; 5 means 5%
Min 0 · Max 100annualInvestmentReturnRateRequiredPercent; 5 means 5%
Min 0 · Max 100annualDiscountRateRequiredPercent; 5 means 5%
Min 0 · Max 100yearsToAnalyzeRequiredModeled years
Min 1 · Max 50sellingCostRateOptionalPercent; 5 means 5%
Min 0 · Max 100annualOwnershipCostInflationRateOptionalPercent; 5 means 5%
Min 0 · Max 100Example request body (JSON)
{
"monthlyRent": 1500,
"annualRentIncreaseRate": 2,
"monthlyRentersInsurance": 20,
"homePrice": 300000,
"downPayment": 60000,
"interestRate": 0,
"loanTermYears": 20,
"annualPropertyTax": 3600,
"annualHomeInsurance": 1200,
"annualMaintenance": 3600,
"monthlyHOA": 100,
"buyingClosingCosts": 6000,
"annualHomeAppreciationRate": 2,
"annualInvestmentReturnRate": 3,
"annualDiscountRate": 4,
"yearsToAnalyze": 5,
"sellingCostRate": 5,
"annualOwnershipCostInflationRate": 2
} Full JSON schema
{
"type": "object",
"additionalProperties": false,
"properties": {
"monthlyRent": {
"type": "number",
"minimum": 0,
"maximum": 100000000,
"description": "US dollars per month"
},
"annualRentIncreaseRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"monthlyRentersInsurance": {
"type": "number",
"minimum": 0,
"maximum": 100000000,
"description": "US dollars per month"
},
"homePrice": {
"type": "number",
"minimum": 0.01,
"maximum": 1000000000,
"description": "Positive US dollars"
},
"downPayment": {
"type": "number",
"minimum": 0,
"maximum": 1000000000,
"description": "US dollars"
},
"downPaymentRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"interestRate": {
"type": "number",
"minimum": 0,
"maximum": 50,
"description": "Annual note rate in percent; 6 means 6%"
},
"loanTermYears": {
"type": "integer",
"minimum": 1,
"maximum": 50,
"description": "Whole years"
},
"annualPropertyTax": {
"type": "number",
"minimum": 0,
"maximum": 1000000000,
"description": "US dollars per year"
},
"propertyTaxRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"annualHomeInsurance": {
"type": "number",
"minimum": 0,
"maximum": 1000000000,
"description": "US dollars per year"
},
"monthlyHomeInsurance": {
"type": "number",
"minimum": 0,
"maximum": 100000000,
"description": "US dollars per month"
},
"annualMaintenance": {
"type": "number",
"minimum": 0,
"maximum": 1000000000,
"description": "US dollars per year"
},
"maintenanceRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"monthlyHOA": {
"type": "number",
"minimum": 0,
"maximum": 100000000,
"description": "US dollars per month"
},
"buyingClosingCosts": {
"type": "number",
"minimum": 0,
"maximum": 1000000000,
"description": "US dollars"
},
"buyingClosingCostsRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"annualHomeAppreciationRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"annualInvestmentReturnRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"annualDiscountRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"yearsToAnalyze": {
"type": "integer",
"minimum": 1,
"maximum": 50,
"description": "Modeled years"
},
"sellingCostRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
},
"annualOwnershipCostInflationRate": {
"type": "number",
"minimum": 0,
"maximum": 100,
"description": "Percent; 5 means 5%"
}
},
"required": [
"homePrice",
"interestRate",
"loanTermYears",
"monthlyRent",
"annualRentIncreaseRate",
"annualHomeAppreciationRate",
"annualInvestmentReturnRate",
"annualDiscountRate",
"yearsToAnalyze"
],
"allOf": [
{
"oneOf": [
{
"required": [
"downPayment"
]
},
{
"required": [
"downPaymentRate"
]
}
]
},
{
"oneOf": [
{
"required": [
"annualPropertyTax"
]
},
{
"required": [
"propertyTaxRate"
]
}
]
},
{
"oneOf": [
{
"required": [
"annualHomeInsurance"
]
},
{
"required": [
"monthlyHomeInsurance"
]
}
]
},
{
"oneOf": [
{
"required": [
"annualMaintenance"
]
},
{
"required": [
"maintenanceRate"
]
}
]
},
{
"oneOf": [
{
"required": [
"buyingClosingCosts"
]
},
{
"required": [
"buyingClosingCostsRate"
]
}
]
}
]
}Production endpoint: POST https://calc.hasstechapi.com/v2/calc/rent-or-buy-discounted-cash-flow
Formula: rent-or-buy-discounted-cash-flow-htcalc-719df2c0e105
Method and sources
Includes opportunity cost, modeled rent, buyer/renter assets and discounted cash flows. The caller supplies both the growth assumptions and discount rate.
Reviewed .