-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate-mortgage.pl
301 lines (247 loc) · 10.3 KB
/
calculate-mortgage.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
% Calculations
% ===========================================================================
% Estate Price = [Estate m2] * [Estate Price per m2]
% Property Price per m3 = Property Price Assessment (Property specification)
% Property Price = [Building m3] * [Property Price per m3]
% Depreciation Rate = Depreciation Table (PropertyAge)
% Depreciation = Building Price * Depreciation Rate
% Loan = Estate Price + Property Price – Depreciation
% Required Mortgage = [Loan] - [Capital]
% First Mortgage = (66% of Loan) - [Security]
% Second Mortgage = 14% of [Loan]
% Total Mortgage = First Mortgage + Second Mortgage
% Mortgage Interest = 5% (First Mortgage + Second Mortgage)
% Additional Costs p.a. = 1% of Loan excl. Property Price p.a.
% Total Liabilities p.a. = Additional Costs p.a. + Mortgage Interest p.a.
% Calculatory Affordability = Total Liabilities / [Income]
% Provided Cash Ratio = Capital/Loan
% ============================================================================
% Example Mortage Application Queries
isApproved("Holger", "Wache", 20, 300000, 50000, 150000, 500, 1000, 200, 10, 5 , 200, 20, 200, 3, "Sheddach", 200, "Doppel" ).
% False
isApproved("Hermann", "Grieder", 5, 200000, 3000000, 250000, 1000, 650, 350, 2, 3 , 350, 22, 200, 2, "Mansardendach", 100, "Carport" ).
% True
isApproved("Michael", "Jordan", 15, 5000000, 1500000, 800000, 3000, 2000, 2000, 10, 10 , 400, 100, 400, 7, "Pultdach", 400, "Einzel" ).
% True
isApproved("Peter", "Pan", 8, 50000, 2500, 150000, 500, 1000, 200, 100, 3, 190, 50, 320, 1, "Flachdach", 600, "Nein" ).
% False
% 7 total cases according to decision matrix
% INPUT - Queries
isApproved(FirstName, LastName, PropertyAge, Income, Capital, Security, EstateSqm, EstatePriceSqm, PropertyM3, Distance, Rooms, RoomPriceSqm, KitchenSqm, KitchenPriceSqm, Floors, Roof, BasementSqm, Garage):-
loan(EstateSqm, EstatePriceSqm, Distance, PropertyM3, Rooms, RoomPriceSqm, KitchenSqm, KitchenPriceSqm, Floors, Roof, BasementSqm, Garage,PropertyAge, X),
isApprovedLevelPCRVariant1(FirstName, LastName, Capital, X),
calculatoryAfforadbility(X, Income, Security, Z),
Z=<0.3.
isApproved(FirstName, LastName, PropertyAge, Income, Capital, Security, EstateSqm, EstatePriceSqm, PropertyM3, Distance, Rooms, RoomPriceSqm, KitchenSqm, KitchenPriceSqm, Floors, Roof, BasementSqm, Garage):-
loan(EstateSqm, EstatePriceSqm, Distance, PropertyM3, Rooms, RoomPriceSqm, KitchenSqm, KitchenPriceSqm, Floors, Roof, BasementSqm, Garage,PropertyAge, X),
isApprovedLevelPCRVariant2(FirstName, LastName, Capital, X),
calculatoryAfforadbility(X, Income, Security, Z),
Z=<0.4.
isApprovedLevelPCRVariant1(FirstName, LastName, Capital, Loan):-
isApprovedLevelPYTH(FirstName, LastName),
providedCashRatio(Capital, Loan, X),
X >=0.2, providedCashRatio(Capital, Loan, Z),
Z <0.3.
isApprovedLevelPCRVariant2(FirstName, LastName, Capital, Loan):-
isApprovedLevelPYTH(FirstName, LastName),
providedCashRatio(Capital, Loan, X),
X >=0.3.
isApprovedLevelPYTH(FirstName, LastName):-
isApprovedLevelZEK(FirstName, LastName),
not(pythagorasEntry(FirstName, LastName)).
isApprovedLevelZEK(FirstName, LastName):-
not(zekEntry(FirstName, LastName)).
% Calculations
% =========================================================
% Estate Price = [Estate m2] * [Estate Price per m2]
estateprice(EstateSqm, EstatePriceSqm, X):- X is EstateSqm * EstatePriceSqm.
% Property Price =[ Building m3] * [Property Price per m3]
propertyprice(
Propertym3,
Distance,
Nrooms,
RoomPriceSqm,
KitchenSqm,
KitchenpriceSqm,
Floors,
Roof,
BasementSqm,
Garage, Y):-
propertypricecalculation(
Distance,
Nrooms,
RoomPriceSqm,
KitchenSqm,
KitchenpriceSqm,
Floors,
Roof,
BasementSqm,
Garage,
X),
Y is Propertym3 * X.
% Depreciation Rate = Depreciation Table (PropertyAge)
depreciationrate(PropertyAge,Y):- PropertyAge=<5, Y=1.
depreciationrate(PropertyAge,Y):- PropertyAge=<10, PropertyAge>5, Y=3.
depreciationrate(PropertyAge,Y):- PropertyAge=<15, PropertyAge>10, Y=7.
depreciationrate(PropertyAge,Y):- PropertyAge=<20, PropertyAge>15, Y=11.
depreciationrate(PropertyAge,Y):- PropertyAge=<25, PropertyAge>20, Y=16.
depreciationrate(PropertyAge,Y):- PropertyAge=<30, PropertyAge>25, Y=21.
depreciationrate(PropertyAge,Y):- PropertyAge=<35, PropertyAge>30, Y=26.
depreciationrate(PropertyAge,Y):- PropertyAge=<40, PropertyAge>35, Y=31.
depreciationrate(PropertyAge,Y):- PropertyAge=<45, PropertyAge>40, Y=36.
depreciationrate(PropertyAge,Y):- PropertyAge=<50, PropertyAge>45, Y=41.
depreciationrate(PropertyAge,Y):- PropertyAge=<55, PropertyAge>50, Y=46.
depreciationrate(PropertyAge,Y):- PropertyAge=<60, PropertyAge>55, Y=52.
depreciationrate(PropertyAge,Y):- PropertyAge=<65, PropertyAge>60, Y=57.
depreciationrate(PropertyAge,Y):- PropertyAge=<75, PropertyAge>65, Y=63.
depreciationrate(PropertyAge,Y):- PropertyAge=<80, PropertyAge>75, Y=68.
depreciationrate(PropertyAge,Y):- PropertyAge=<85, PropertyAge>80, Y=74.
depreciationrate(PropertyAge,Y):- PropertyAge=<90, PropertyAge>85, Y=80.
depreciationrate(PropertyAge,Y):- PropertyAge=<95, PropertyAge>90, Y=86.
depreciationrate(PropertyAge,Y):- PropertyAge>95, Y=92.
depreciation(PropertyPrice,PropertyAge,Z):- depreciationrate(PropertyAge, X), Z is PropertyPrice * (X/100).
% Loan = Estate Price + Property Price – Depreciation
loan(EstateSqm,
EstatePriceSqm,
Distance,
PropertyM3,
Rooms,
RoomPriceSqm,
KitchenSqm,
KitchenPriceSqm,
Floors,
Roof,
BasementSqm,
Garage,
PropertyAge, X):-
estateprice(EstatePriceSqm, EstateSqm, U),
propertyprice(
PropertyM3,
Distance,
Rooms,
RoomPriceSqm,
KitchenSqm,
KitchenPriceSqm,
Floors,
Roof,
BasementSqm,
Garage,
V),
depreciation(V, PropertyAge,W),
X is U+V-W.
% First Mortgage = (66% of loan) - [Security]
firstMortgage(Loan,Security,X):- X is (Loan * 0.66) - Security.
% Second Mortgage = 14% of [loan]
secondMortgage(Loan,X):- X is (Loan * 0.14).
% Mortgage Interest = 5% (First Mortgage + Second Mortgage)
mortageInterest(Loan, Security, Z):- firstMortgage(Loan, Security, X), secondMortgage(Loan, Y), Z is (X+Y) * 0.05.
% Additional Costs p.a. = 1% of Loan p.a.
additionalCost(Loan,X):- X is (Loan * 0.01).
% Total Liabilities p.a. = Additional Costs p.a. + Mortgage Interest p.a.
totalLiabilites(Loan, Security, Z):- additionalCost(Loan, X), mortageInterest(Loan, Security, Y), Z is X+Y.
% Calculatory Affordability = Total Liabilities / [Income]
calculatoryAfforadbility(Loan, Income, Security, Z):- totalLiabilites(Loan, Security, X), Z is X/Income.
% Provided Cash Ratio = Capital/Loan
providedCashRatio(Capital, Loan, X):- X is (Capital/Loan).
% Virtual API for ZEK Entries
% Checks if a Person has a ZEK Entry (which is not good)
zekEntry("Beatrice", "Sutter").
zekEntry("Karin", "Keller").
zekEntry("Peter", "Meier").
zekEntry("Melanie", "Graber").
zekEntry("Stephan", "Ospel").
zekEntry("Holger", "Wache").
% Virtual API for Pythagoras Entry
% Checks if a Person is in the Pythagoras list (which is not good)
pythagorasEntry("Max", "Muster").
pythagorasEntry("Hans", "Glauser").
pythagorasEntry("Hans", "Tester").
pythagorasEntry("Hans", "Müller").
pythagorasEntry("Hans", "Holzer").
pythagorasEntry("Rolf", "Mustermann").
propertypricecalculation(Distance, Rooms, RoomPriceSqm, KitchenSqm,
KitchenPriceSqm, Floors, Roof, BasementSqm, Garage, Y):-
pointscalculation(
Distance,
Rooms,
RoomPriceSqm,
KitchenSqm,
KitchenPriceSqm,
Floors,
Roof,
BasementSqm,
Garage,
X),
propertysqmprice(X,Y).
pointscalculation(Distance, Rooms, RoomPriceSqm, KitchenSqm,
KitchenPriceSqm, Floors, Roof, BasementSqm, Garage, Z):-
distance(Distance, N),
rooms(Rooms, O),
roompricesqm(RoomPriceSqm, P),
kitchensqm(KitchenSqm,Q),
kitchenpricesqm(KitchenPriceSqm,R),
floors(Floors,S),
roof(Roof,T),
basementsqm(BasementSqm,U),
garage(Garage,V),
Z is (N+O+P+Q+R+S+T+U+V) / 9.
propertysqmprice(X,Y):- X>=1, X<2, Y is 300.
propertysqmprice(X,Y):- X>=2, X<3, Y=450.
propertysqmprice(X,Y):- X>=3, X<4, Y=500.
propertysqmprice(X,Y):- X>=4, X<5, Y=550.
propertysqmprice(X,Y):- X>=5, X<6, Y=600.
propertysqmprice(X,Y):- X=6, Y=750.
distance(X,Y):- X>=0, X<5, Y=6.
distance(X,Y):- X>=6, X<10, Y=5.
distance(X,Y):- X>=10, X<20, Y=4.
distance(X,Y):- X>=20, X<30, Y=3.
distance(X,Y):- X>=30, X<40, Y=2.
distance(X,Y):- X>=40, Y=1.
rooms(X,Y):- X>=11, Y=6.
rooms(X,Y):- X>=9, X=<10, Y=5.
rooms(X,Y):- X>=7, X=<8, Y=4.
rooms(X,Y):- X>=5, X=<6, Y=3.
rooms(X,Y):- X>=3, X=<4, Y=2.
rooms(X,Y):- X=<2, Y=1.
roompricesqm(X,Y):- X>=1200, Y=6.
roompricesqm(X,Y):- X>=1000, X<1200, Y=5.
roompricesqm(X,Y):- X>=800, X<1000, Y=4.
roompricesqm(X,Y):- X>=600, X<800, Y=3.
roompricesqm(X,Y):- X>=500, X<600, Y=2.
roompricesqm(X,Y):- X<500, Y=1.
kitchensqm(X,Y):- X>=30, Y=6.
kitchensqm(X,Y):- X>=20, X<30, Y=5.
kitchensqm(X,Y):- X>=15, X<20, Y=4.
kitchensqm(X,Y):- X>=10, X<15, Y=3.
kitchensqm(X,Y):- X>=5, X<10, Y=2.
kitchensqm(X,Y):- X<5,Y=1.
kitchenpricesqm(X,Y):- X>=1600, Y=6.
kitchenpricesqm(X,Y):- X>=1400, X<1600, Y=5.
kitchenpricesqm(X,Y):- X>=1200, X<1400, Y=5.
kitchenpricesqm(X,Y):- X>=1000, X<1200, Y=5.
kitchenpricesqm(X,Y):- X>=800, X<1000, Y=5.
kitchenpricesqm(X,Y):- X<800, Y=5.
floors(X,Y):- X>=6, Y=6.
floors(X,Y):- X=5, Y=5.
floors(X,Y):- X=4, Y=4.
floors(X,Y):- X=3, Y=3.
floors(X,Y):- X=2, Y=2.
floors(X,Y):- X=1, Y=1.
roof(X,Y):- X="Mansardendach", Y=6.
roof(X,Y):- X="Satteldach", Y=5.
roof(X,Y):- X="Sheddach", Y=4.
roof(X,Y):- X="Walmdach", Y=3.
roof(X,Y):- X="Pultdach", Y=2.
roof(X,Y):- X="Flachdach", Y=1.
basementsqm(X,Y):- X>=150, Y=6.
basementsqm(X,Y):- X>=120, X<150, Y=5.
basementsqm(X,Y):- X>=100, X<120, Y=4.
basementsqm(X,Y):- X>=60, X<100, Y=3.
basementsqm(X,Y):- X>20, X<60, Y=2.
basementsqm(X,Y):- X=<20,Y=1.
garage(X,Y):- X="Tiefgarage", Y=6.
garage(X,Y):- X="Doppel", Y=5.
garage(X,Y):- X="Einzel", Y=4.
garage(X,Y):- X="Gemeinschaft", Y=4.
garage(X,Y):- X="Carport", Y=2.
garage(X,Y):- X="Nein", Y=1.