Created
August 29, 2020 16:41
-
-
Save jaeseokan94/9864fc6e950c2d6c458d3a813112716f to your computer and use it in GitHub Desktop.
Airbtics Airbnb calculator - v1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateRev(values){ | |
let valuesLen = Object.keys(values).length; | |
if (valuesLen < 13){ | |
console.log("not enough filled ", valuesLen) | |
return false | |
} | |
for (var key in values) { | |
values[key] = Number(values[key]) | |
} | |
let adr = values.adr; | |
let availableDay = 365*values.availability*0.01; | |
let occupancy = values.occupancy*0.01; | |
let tax = values.profitTax; | |
let mortgageCost = (values.housePrice-values.downPayment)*0.01*values.interestRate | |
let firstYearRev = adr*availableDay*occupancy; | |
let yearGrowingExpense = values.annualCost+values.monthlyCost*12 | |
let yearExp = yearGrowingExpense+mortgageCost | |
let yearProfitBeforeTax = firstYearRev-yearExp; | |
let taxThisYear = (yearProfitBeforeTax>0) ? yearProfitBeforeTax*0.01*tax : 0 | |
let firstYearTax = taxThisYear; | |
let firstYearExpense = yearExp; | |
yearExp = yearExp + taxThisYear; | |
let totalOneOffCost = values.downPayment + values.oneOffCost; | |
let cac = (yearProfitBeforeTax/totalOneOffCost)*100; | |
let netRentalYield = (yearProfitBeforeTax/values.housePrice)*100; | |
let profitAfterTax = yearProfitBeforeTax-taxThisYear | |
let totalRevenues = [firstYearRev] | |
let totalExpenses = [yearExp] | |
let totalProfits = [profitAfterTax] | |
let firstYearProfitAfterTax = profitAfterTax | |
let currentPropertyPrice = values.housePrice; | |
let profitAccum = totalProfits.reduce((a, b) => a + b, 0); | |
console.log("year 1 profit = " + profitAfterTax + " accum = " + profitAccum) | |
let revenueObjs = [ | |
{ | |
"year":1, | |
"revenue": firstYearRev, | |
"expense": yearExp, | |
"profitAccum": profitAccum, | |
"propertyEvaluation": currentPropertyPrice | |
} | |
] | |
for (let i = 2; i < 31; i++) { | |
adr = adr + (adr*0.01*values.annualADRIncrease); | |
let yearRev = adr*availableDay*occupancy; | |
yearGrowingExpense = yearGrowingExpense + (yearGrowingExpense*0.01*values.expenseIncrease) | |
yearExp = yearGrowingExpense + mortgageCost | |
console.log("exp " + yearExp + " yearGrowingExpense " + yearGrowingExpense + " mortgageCost " + mortgageCost ) | |
let profit = yearRev-yearExp; | |
console.log("rev " + yearRev + " exp " + yearExp) | |
taxThisYear = profit*0.01*tax; | |
let yearExpWithTax = yearExp + taxThisYear; | |
profitAfterTax = profit-taxThisYear; | |
currentPropertyPrice = currentPropertyPrice + currentPropertyPrice*0.01*values.annualAppreciation; | |
totalProfits.push(profitAfterTax) | |
totalRevenues.push(yearRev) | |
totalExpenses.push(yearExpWithTax) | |
profitAccum = totalProfits.reduce((a, b) => a + b, 0); | |
console.log("year " + i + " profit = " + profitAfterTax + " accum = " + profitAccum) | |
revenueObjs.push( | |
{ | |
"year":i, | |
"revenue": Math.round(yearRev), | |
"expense": Math.round(yearExp), | |
"profitAccum": Math.round(profitAccum), | |
"propertyEvaluation": Math.round(currentPropertyPrice) | |
} | |
) | |
} | |
let returnObj = { | |
'cac': Math.round(cac), | |
'firstYearRev': Math.round(firstYearRev), | |
'firstYearProfitAfterTax' : Math.round(firstYearProfitAfterTax), | |
'firstYearTax' : Math.round(firstYearTax), | |
'firstYearExpense': Math.round(firstYearExpense), | |
'netRentalYield': Math.round(netRentalYield), | |
'revenueObjs' : revenueObjs, | |
} | |
return returnObj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: typescript / make name self explainable. This was just a quick MVP.