Created
December 3, 2024 18:39
-
-
Save XtremeOwnageDotCom/e75320410bd5339c32b16b3e664953e4 to your computer and use it in GitHub Desktop.
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
// Version 1: https://pastebin.com/EHkdSBuM | |
// Version 2: https://pastebin.com/6P8mNPqN | |
// - Fixed display on retirement percentage. (Static number replaced with correct variable) | |
// - Removed annual sales tax for vehicle being included. (Sales tax only applicable when purchasing the vehicle) | |
// - Enforced 401k max yearly contriutions. (IRS-enforces a max annual contribution limit) | |
// - Fixed formatting, and duplicate numbers. (aka, totals being displayed twice) | |
using System; | |
class CostCalculator | |
{ | |
private const double GrossIncome = 300000; | |
// Exemptions | |
private const double HealthInsuranceMontly = 815; //Based on https://www.coveredca.com/ | |
private const double RetirementPercent = 12; // Assuming 8% employer match, and target goal of 20% | |
private const double Max401Annual = 23000; // https://www.fidelity.com/learning-center/smart-money/401k-contribution-limits#:~:text=The%20IRS%20sets%20the%20maximum,2024%2C%20this%20rose%20to%20%2423%2C000. | |
// Taxes | |
private const double StateTaxPercent = 9.875; // Based on https://maps.cdtfa.ca.gov/ (random street in SF) | |
private const double SocialSecurityPercent = 6.2; // Based on https://www.ssa.gov/oact/cola/cbb.html#:~:text=We%20call%20this%20annual%20limit,for%20employees%20and%20employers%2C%20each. | |
private const double MedicarePercent = 1.45; // Based on https://www.irs.gov/taxtopics/tc751 | |
private const double AdditionalMedicarePercent = 0.9; // Also based on https://www.irs.gov/taxtopics/tc751 | |
// Renting / Buying Home | |
private const double AnnualRent = 14560; // Based on https://www.apartments.com/rent-market-trends/san-francisco-ca/ | |
private const double HomePrice = 1200000; // Based on https://www.zillow.com/home-values/20330/san-francisco-ca/ | |
private const double PropertyTaxPercent = 1.17; // Based on https://www.sftaxappeal.com/post/san-francisco-property-tax-calculator#:~:text=For%20the%20fiscal%20year%202023,to%20determine%20your%20tax%20liability. | |
private const double MortgageInterestPercent = 7.37; // Based on https://www.google.com/search?q=current+mortage+rates | |
private const int MortgageTermYears = 30; // Typical term for $$$$ | |
private const double UtilityMonthlyCost = 240; // Based on https://californiamoversusa.com/resources/cost-of-living-in-san-francisco-ca/#:~:text=As%20mentioned%20before%2C%20the%20average,example)%20or%20consume%20more%20gas. | |
// Transportation | |
private const double PublicTransitAnnualCost = 1000; // Based on Monthly Pass: https://www.sfmta.com/getting-around/muni/fares | |
// Car ownership variables... Random numbers for base-model tesla. | |
// Fees based on https://www.dmv.ca.gov/portal/vehicle-registration/registration-fees/ | |
private const double CarPurchasePrice = 40240; | |
private const double CarSalesTaxPercent = 8.6; | |
private const double FederalTaxCredit = 7500; | |
private const double StateRebate = 2000; | |
private const double HomeChargerCost = 2000; | |
private const double CarLoanAnnualPercent = 7; | |
private const double CarInsurance = 3397; | |
private const double CarMaintenance = 538; | |
private const double CarTires = 544; | |
private const double CarCharging = 1458; | |
private const double CarRegistration = 400; | |
// Flags | |
private const bool Renting = true; // True for renting, false for owning | |
private const bool UsingPublicTransit = true; // True for public transit, false for owning a car | |
static void Main(string[] args) | |
{ | |
// Set the culture to US English | |
System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("en-US"); | |
System.Globalization.CultureInfo.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); | |
// Perform Calculations | |
double exemptions = CalculateExemptions(out double healthInsurance, out double retirementContribution); | |
double taxableIncome = GrossIncome - exemptions; | |
double totalTaxes = CalculateTaxes(taxableIncome, out double federalTax, out double stateTax, out double socialSecurityTax, out double medicareTax, out double additionalMedicareTax); | |
double netIncome = GrossIncome - totalTaxes - exemptions; | |
double housingCost = CalculateHousingCost(out double propertyTaxes, out double monthlyMortgagePayment, out double annualUtilities); | |
double transportationCost = CalculateTransportationCost(out double carLoanAnnualCost); | |
double leftOver = netIncome - housingCost - transportationCost; | |
// Output Tree-Like Breakdown | |
Console.WriteLine($"Gross Income: {GrossIncome:C}"); | |
Console.WriteLine($"Left Over: {leftOver:C}"); | |
Console.WriteLine(); | |
Console.WriteLine(); | |
Console.WriteLine($"├── Exemptions: {exemptions:C}"); | |
Console.WriteLine($"│ ├── Health Insurance: {healthInsurance:C}"); | |
Console.WriteLine($"│ ├── 401k Contribution ({RetirementPercent / 100:P0}): {retirementContribution:C}"); | |
Console.WriteLine($"│ └── Total Exemptions: {exemptions:C}"); | |
Console.WriteLine($"├── Taxes: {totalTaxes:C}"); | |
Console.WriteLine($"│ ├── Federal Income Tax: {federalTax:C}"); | |
Console.WriteLine($"│ ├── California State Tax: {stateTax:C}"); | |
Console.WriteLine($"│ ├── Social Security Tax: {socialSecurityTax:C}"); | |
Console.WriteLine($"│ ├── Medicare Tax: {medicareTax:C}"); | |
Console.WriteLine($"│ └── Additional Medicare Tax: {additionalMedicareTax:C}"); | |
Console.WriteLine($"├── Net Income: {netIncome:C}"); | |
Console.WriteLine($"├── Housing: {housingCost:C}"); | |
if (Renting) | |
{ | |
Console.WriteLine($"│ └── Annual Rent: {AnnualRent:C}"); | |
} | |
else | |
{ | |
Console.WriteLine($"│ ├── Property Taxes: {propertyTaxes:C}"); | |
Console.WriteLine($"│ └── Monthly Mortgage Payment: {monthlyMortgagePayment:C}"); | |
} | |
Console.WriteLine($"│ └── Utilities: {annualUtilities:C}"); | |
Console.WriteLine($"├── Transportation: {transportationCost:C}"); | |
if (UsingPublicTransit) | |
{ | |
Console.WriteLine($"│ └── Public Transit Annual Cost: {PublicTransitAnnualCost:C}"); | |
} | |
else | |
{ | |
Console.WriteLine($"│ ├── Car Loan Annual Cost: {carLoanAnnualCost:C}"); | |
Console.WriteLine($"│ ├── Insurance: {CarInsurance:C}"); | |
Console.WriteLine($"│ ├── Maintenance: {CarMaintenance:C}"); | |
Console.WriteLine($"│ ├── Tires: {CarTires:C}"); | |
Console.WriteLine($"│ ├── Charging: {CarCharging:C}"); | |
Console.WriteLine($"│ └── Registration: {CarRegistration:C}"); | |
} | |
} | |
static double CalculateExemptions(out double healthInsurance, out double retirementContribution) | |
{ | |
healthInsurance = HealthInsuranceMontly * 12; | |
double calculatedRetirementContribution = GrossIncome * (RetirementPercent / 100); | |
// Use the lesser of calculated contribution or max allowed | |
retirementContribution = Math.Min(calculatedRetirementContribution, Max401Annual); | |
return healthInsurance + retirementContribution; | |
} | |
static double CalculateTaxes(double taxableIncome, out double federalTax, out double stateTax, out double socialSecurityTax, out double medicareTax, out double additionalMedicareTax) | |
{ | |
// Federal Tax Brackets for Single Filers in 2024 | |
(double rate, double threshold)[] federalBrackets = new (double, double)[] | |
{ | |
(0.10, 11600), | |
(0.12, 47150), | |
(0.22, 100525), | |
(0.24, 191950), | |
(0.32, 243725), | |
(0.35, 609350), | |
(0.37, double.MaxValue) | |
}; | |
federalTax = CalculateProgressiveTax(taxableIncome, federalBrackets); | |
stateTax = taxableIncome * (StateTaxPercent / 100); | |
socialSecurityTax = Math.Min(160000, GrossIncome) * (SocialSecurityPercent / 100); | |
medicareTax = GrossIncome * (MedicarePercent / 100); | |
additionalMedicareTax = GrossIncome > 200000 ? (GrossIncome - 200000) * (AdditionalMedicarePercent / 100) : 0; | |
return federalTax + stateTax + socialSecurityTax + medicareTax + additionalMedicareTax; | |
} | |
static double CalculateHousingCost(out double propertyTaxes, out double monthlyMortgagePayment, out double annualUtilities) | |
{ | |
annualUtilities = UtilityMonthlyCost * 12; | |
if (Renting) | |
{ | |
propertyTaxes = 0; | |
monthlyMortgagePayment = 0; | |
return AnnualRent + annualUtilities; | |
} | |
propertyTaxes = HomePrice * (PropertyTaxPercent / 100); | |
monthlyMortgagePayment = CalculateMonthlyMortgage(HomePrice, 20, MortgageInterestPercent, MortgageTermYears); | |
return (monthlyMortgagePayment * 12) + propertyTaxes + annualUtilities; | |
} | |
static double CalculateTransportationCost(out double carLoanAnnualCost) | |
{ | |
if (UsingPublicTransit) | |
{ | |
carLoanAnnualCost = 0; | |
return PublicTransitAnnualCost; | |
} | |
carLoanAnnualCost = CalculateAnnualLoanCost(CarPurchasePrice, 20, CarLoanAnnualPercent, 5); | |
return carLoanAnnualCost + CarInsurance + CarMaintenance + CarTires + CarCharging + CarRegistration; | |
} | |
static double CalculateProgressiveTax(double income, (double rate, double threshold)[] brackets) | |
{ | |
double tax = 0; | |
double remainingIncome = income; | |
double previousThreshold = 0; | |
foreach (var bracket in brackets) | |
{ | |
if (remainingIncome > bracket.threshold - previousThreshold) | |
{ | |
tax += (bracket.threshold - previousThreshold) * bracket.rate; | |
remainingIncome -= bracket.threshold - previousThreshold; | |
previousThreshold = bracket.threshold; | |
} | |
else | |
{ | |
tax += remainingIncome * bracket.rate; | |
break; | |
} | |
} | |
return tax; | |
} | |
static double CalculateMonthlyMortgage(double homePrice, double downPaymentPercent, double annualInterestRate, int termYears) | |
{ | |
double loanAmount = homePrice * ((100 - downPaymentPercent) / 100); | |
double monthlyInterestRate = annualInterestRate / 100 / 12; | |
int numberOfPayments = termYears * 12; | |
return (loanAmount * monthlyInterestRate) / | |
(1 - Math.Pow(1 + monthlyInterestRate, -numberOfPayments)); | |
} | |
static double CalculateAnnualLoanCost(double purchasePrice, double downPaymentPercent, double annualInterestRate, int termYears) | |
{ | |
double loanAmount = purchasePrice * ((100 - downPaymentPercent) / 100); | |
double annualInterestRateDecimal = annualInterestRate / 100; | |
return loanAmount * annualInterestRateDecimal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment