Skip to content

Main content

Germany Mortgage Calculator Source Code

Browse the implementation files for Germany Mortgage Calculator.
tool.ts typescript
import {
	calculateGermanyMortgage,
	type GermanyMortgageResult
} from '../calculation';
import { formatCurrencyAmount } from '../../format/currency/tool';
import { parseFiniteNumber } from '../../parse/number/tool';
import CountryMortgageCalculator from '../CountryMortgageCalculator.svelte';

const money = (value: number) =>
	formatCurrencyAmount(value, 'EUR', 'en-US');

export const formatGermanyMortgage = (
	result: GermanyMortgageResult
): string =>
	`${money(
		result.monthlyPayment
	)} monthly annuity during the fixed-interest period\n\n` +
	`Loan amount ${money(result.loanAmount)}\n` +
	`Purchase price plus acquisition costs ${money(
		result.propertyTotal
	)}\n` +
	`Acquisition costs ${money(result.acquisitionCosts)}\n` +
	`Principal repaid ${money(result.principalRepaid)}\n` +
	`Interest paid during fixed period ${money(
		result.totalInterestDuringFixedPeriod
	)}\n` +
	`Remaining balance for follow-on financing ${money(
		result.remainingBalance
	)}`;

export const germanyMortgageCalculator = (
	propertyPriceInput: unknown = 450000,
	equityInput: unknown = 100000,
	interestRateInput: unknown = 3.5,
	initialRepaymentInput: unknown = 2,
	fixedInterestYearsInput: unknown = 10,
	propertyTransferTaxInput: unknown = 6,
	notaryAndRegistryInput: unknown = 1.5,
	brokerInput: unknown = 0
): string => {
	const values = [
		propertyPriceInput,
		equityInput,
		interestRateInput,
		initialRepaymentInput,
		fixedInterestYearsInput,
		propertyTransferTaxInput,
		notaryAndRegistryInput,
		brokerInput
	].map(parseFiniteNumber);

	if (values.some((value) => value === null)) return '';

	const result = calculateGermanyMortgage({
		annualInterestRate: values[2] as number,
		brokerRate: values[7] as number,
		equity: values[1] as number,
		fixedInterestYears: values[4] as number,
		initialRepaymentRate: values[3] as number,
		notaryAndRegistryRate: values[6] as number,
		propertyPrice: values[0] as number,
		propertyTransferTaxRate: values[5] as number
	});

	return result ? formatGermanyMortgage(result) : '';
};

const germanyMortgagePreview = (
	propertyPrice: unknown = 450000,
	equity: unknown = 100000,
	interestRate: unknown = 3.5
) =>
	germanyMortgageCalculator(
		propertyPrice,
		equity,
		interestRate
	);

export const Tool: TypeTool = {
	name: 'Germany Mortgage Calculator',
	slug: 'mortgage-calculator/de',
	intro:
		'Estimate a German annuity mortgage, acquisition costs, and the remaining balance after the fixed-interest period.',
	tool: germanyMortgageCalculator,
	i: [],
	o: [
		{
			label: 'German mortgage estimate',
			placeholder: 'Mortgage estimate',
			render: 'custom',
			renderas: CountryMortgageCalculator,
			type: 'text'
		}
	],
	preview: {
		i: [
			{
				label: 'Property price',
				placeholder: 'Property price in EUR',
				type: 'number',
				value: '450000'
			},
			{
				label: 'Available equity',
				placeholder: 'Equity in EUR',
				type: 'number',
				value: '100000'
			},
			{
				label: 'Interest rate',
				placeholder: 'Annual interest rate (%)',
				type: 'number',
				value: '3.5'
			}
		],
		o: [
			{
				label: 'Mortgage estimate',
				placeholder: 'Mortgage estimate',
				render: 'textarea',
				type: 'text'
			}
		],
		tool: germanyMortgagePreview
	},
	alternative: [
		{
			title: 'US Mortgage Calculator',
			url: '/mortgage-calculator/us'
		},
		{
			title: 'Japan Mortgage Calculator',
			url: '/mortgage-calculator/jp'
		}
	],
	cite: [
		{
			title:
				'Verbraucherzentrale: Common property-financing models',
			url: 'https://www.verbraucherzentrale.de/wissen/geld-versicherungen/bau-und-immobilienfinanzierung/immobilienfinanzierung-diese-modelle-gibt-es-und-das-sollten-sie-beachten-5801'
		},
		{
			title:
				'Verbraucherzentrale: Affordability and acquisition costs',
			url: 'https://www.verbraucherzentrale.de/wissen/geld-versicherungen/bau-und-immobilienfinanzierung/immobilienfinanzierung-so-berechnen-sie-was-sie-sich-leisten-koennen-5822'
		}
	]
};

export default Tool;

Description

Browse the implementation files for Germany Mortgage Calculator.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools