## The Maths

This outlines & links to important information related to how Mansion calculates values used in assumptions. We've included the Python and JS code for those interested.

Something missing? Please email us at support@mansionlife.com
Defining more Clearly Annualized Rate of Return
Mansion utilizes a few terms throughout the site like "Annualized Return" or ARR (Annualized Rate of Return). It is important to note that these calculations or definitions are numerical techniques that find approximations for returns given certain inputs.

When we use these formulas, we will list the assumptions used in the formulas and you can see the detailed math below. Although formulas may be similar to IRR, to avoid confusion with GIPS accepted methodology for IRR calculations, our displayed rates of return are "annualized rates of return" representing cash flows recognized annually.
The Code for the Maths
You can view the code below in Javascript for our calculations. This code has some fixed assumptions which will vary by the use of the calculator based on where it's used on the site or based on assumptions for a given market or property.
``````

function newton(f, df, x0, tol = 1e-7, maxIter = 1000) {
let x = x0;
for (let i = 0; i < maxIter; i++) {
let dx = f(x) / df(x);
x = x - dx;
if (Math.abs(dx) < tol) {
return x;
}
}
throw new Error("Newton's method did not converge");
}

function irr(cashFlows) {
let f = r => cashFlows.reduce((acc, cf, i) => acc + cf / Math.pow(1 + r, i), 0);
let df = r => cashFlows.reduce((acc, cf, i) => acc - i * cf / Math.pow(1 + r, i + 1), 0);
return newton(f, df, 0.1);
}

function calculateCashFlows(
initialOfferingAmount,
annualAppreciation,
annualCashFlowPct,
initialInvestment,
holdingPeriod,
annualCashFlowIncrease,
dispositionExpensePct,
initialHomeValue,
cashReserves,
furnishingValue
) {
let cashFlows = [-initialInvestment];
let dividendsFlows = [];
let ownershipPercentage = initialInvestment / initialOfferingAmount;

for (let year = 1; year <= holdingPeriod; year++) {
let annualCashFlow = initialOfferingAmount * annualCashFlowPct * Math.pow(1 + annualCashFlowIncrease, year - 1) * ownershipPercentage;
cashFlows.push(annualCashFlow);
dividendsFlows.push(annualCashFlow);
}

let homeValues = Array.from({ length: holdingPeriod + 1 }, (_, i) => initialHomeValue * Math.pow(1 + annualAppreciation, i));
let unrealizedAppreciation = Array.from({ length: holdingPeriod }, (_, i) => homeValues[i + 1] - homeValues[i]);
let unrealizedAppreciationFlows = unrealizedAppreciation.map(value => value * ownershipPercentage);

let totalIncrease = homeValues[homeValues.length - 1] - homeValues;
let finalHomeValue = homeValues[homeValues.length - 1];

let finalValue = (finalHomeValue + cashReserves + furnishingValue) - (finalHomeValue * dispositionExpensePct);
let netProceeds = finalValue * ownershipPercentage;
cashFlows[cashFlows.length - 1] += netProceeds;

return { cashFlows, dividendsFlows, homeValues, unrealizedAppreciation, unrealizedAppreciationFlows, totalIncrease, finalHomeValue };
}

// Example usage (You'll need to provide values for these variables)
let initialOfferingAmount = 799506,
annualAppreciation = 0.0896,
annualCashFlowPct = 0.048,
initialInvestment = 10000,
holdingPeriod = 7,
annualCashFlowIncrease = 0.05,
dispositionExpensePct = 0.04,
initialHomeValue = 655000,
furnishingValue = 55719,
cashReserves = 24287;

let { cashFlows, dividendsFlows, homeValues, unrealizedAppreciation, unrealizedAppreciationFlows, totalIncrease, finalHomeValue } = calculateCashFlows(
initialOfferingAmount,
annualAppreciation,
annualCashFlowPct,
initialInvestment,
holdingPeriod,
annualCashFlowIncrease,
dispositionExpensePct,
initialHomeValue,
cashReserves,
furnishingValue
);

let irrResult = irr(cashFlows);
let totalReturnedValue = cashFlows[cashFlows.length - 1];
let netReturnedValue = totalReturnedValue - initialInvestment;

console.log(irrResult);
console.log(totalReturnedValue);
console.log(netReturnedValue);
console.log(totalIncrease);
console.log(cashFlows);
console.log(dividendsFlows);
console.log(homeValues);
console.log(finalHomeValue);
console.log(unrealizedAppreciation);
console.log(unrealizedAppreciationFlows);

```
```

An Explanation of the Math and Methods

Newton's Method (used in Mansion Calculator):

The `newton` function implements Newton's method, which is an iterative numerical technique used to find approximations to the roots (or zeros) of a real-valued function.
- **Parameters**:
- `f`: The function for which we want to find the root.
- `df`: The derivative of the function `f`.
- `x0`: Initial guess.
- `tol`: Tolerance level for the approximation (default is 1e-7).
- `maxIter`: Maximum number of iterations (default is 1000).

- **Assumptions**:
- The function `f` is differentiable and has a continuous derivative.
- There exists a root close to the initial guess `x0`.

Average Annual Rate of Return (ARR):
The `arr` (or 'irr') function calculates the Average Annual Rate of Return for a series of cash flows. ARR is the discount rate that makes the Net Present Value (NPV) of a series of cash flows equal to zero. This is not the GIPS standards thus we don't represent the output as IRR when displayed.

- **Parameters**:
- `cashFlows`: An array of cash flows.

- **Assumptions**:
- Cash flows occur at regular intervals, annually in our calculator.
- The ARR exists and is unique.

Cash Flows Calculation:
The `calculateCashFlows` function calculates various cash flows and values associated with an investment.

- **Parameters**:
- Various parameters related to the investment, such as initial offering value, appreciation rates, cash flow percentages, etc.

- **Assumptions**:
- Cash flows and home values grow at constant rates.
- Ownership percentage remains constant throughout the holding period.

Calculation of `totalReturnedValue`:
`totalReturnedValue` is the total amount returned at the end of the investment period. It's calculated as the sum of the last year's cash flow (which includes the net proceeds from the sale of the home) and the dividends received in that year.

Calculation of `arrResult`:
`arrResult` is the Average Annual Rate of Return for the series of cash flows. It represents the annualized rate of return for the investment, taking into account the timing and amount of each cash flow on an annual basis.

Summary:
1. **Newton's Method**: An iterative method used to find the root of a function. Assumes the function is differentiable and has a continuous derivative.

2. **ARR**: Represents the discount rate that makes the NPV of cash flows zero. Assumes cash flows occur at regular intervals and that the ARR is unique. This is code specific only and IS NOT INTENDED TO REFLECT GIPS OR OTHER STANDARDS FOR IRR.

3. **Cash Flows Calculation**: Calculates the cash flows and values associated with an investment based on various parameters. Assumes constant growth rates and constant ownership percentage.

4. **totalReturnedValue**: Represents the total amount returned at the end of the investment period, including the net proceeds from the sale of the home after disposition expenses assumed at the rate shown.

5. **arrResult**: The annualized rate of return for the investment, considering the timing and amount of each cash flow.

This code provides a comprehensive analysis of an investment, considering various factors like appreciation, cash flows, and ownership percentage. The calculations are based on standard financial principles and make certain assumptions for simplicity and ease of computation.

## The Mansion Experience

Smart homes with amazing Charlotte locations, modern workstations, restful beds, hotel-grade cleaning, and 24/7 concierge service. It’s a luxury hotel experience, but better.