;; Lisa Zenk ;; B. Alex Bridges ;; ECE-492 ;; Expert Systems Project (defrule job-history "Determine the steadiness of the applicant's job history." (initial-fact) => (printout t crlf "Have you worked at your current job for 2 or more years? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (stable-work yes same-job)) else (printout t crlf "Have you been consistently employed and maintained a regular ") (printout t crlf "consistent level of income? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (stable-work yes consistent-job))) (if (eq ?low no) then ; (printout t crlf "Are you in a line of work in which frequent job turnover can ") (printout t crlf "be customary? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (stable-work yes turnover))) ; (printout t crlf "Have you recently been discharged from the military? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (stable-work yes military))) ; (printout t crlf "Is your work seasonal? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (stable-work yes seasonal))) ; (printout t crlf "Have you just finished school? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (stable-work yes school))) ; (printout t crlf "Have you been laid off because of a plant closing ") (printout t crlf "or an illness? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (stable-work yes laid-off))) ) ) ) (defrule bad-job-history "Check for steadiness of the applicant's job history." (declare (salience -1)) (not (stable-work yes ?)) (not (accepted no ?)) => (assert (accepted no stable-work)) (printout t crlf "The mortgage would not be approved due to unstable work history." crlf) ) (defrule credit-history "Determine the quality of the applicant's credit history." (declare (salience -2)) (not (accepted no ?)) => (printout t crlf "Do you have an established credit history? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (printout t crlf "What numerical rating did you receive on your credit report? ") (bind ?in (read)) (integer ?in) (if (>= ?in 700) then (assert (credit excellent ?in))) (if (and (< ?in 700) (>= ?in 680)) then (assert (credit good ?in))) (if (and (< ?in 680) (>= ?in 620)) then (assert (credit fair ?in))) (if (< ?in 620) then (assert (credit bad ?in))) ; (printout t crlf "Have you declared foreclosure within the past 7 years? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (credit foreclosure discuss)) (printout t crlf "Was the foreclosure within the past 3 years? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (credit fail foreclosure))) ) ; (printout t crlf "Have you declared bankruptcy within the past 10 years? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (credit bankruptcy discuss)) (printout t crlf "Was the bankruptcy within the past 2 years? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (credit fail bankruptcy))) ) else (printout t crlf "Have you paid your bills on time and can prove it? (yes/no) ") (bind ?in (read)) (bind ?low (lowcase ?in)) (if (eq ?low yes) then (assert (credit none bills-paid))) ) ) (defrule bad-credit-history "Check for the quality of the applicant's credit history." (declare (salience -3)) (or (credit fail ?) (not (credit $?))) (not (accepted no ?)) => (assert (accepted no credit)) (printout t crlf "The mortgage would not be approved due to unestablished ") (printout t crlf "or poor credit history." crlf) ) (defrule income "Determine the applicant's income level and allowable expenses." (declare (salience -4)) (not (accepted no ?)) => (printout t crlf "What is your gross annual income? ") (bind ?in (read)) (integer ?in) (assert (monthly-income (/ ?in 12))) ; (assert (allowable-monthly-housing-costs (* (/ ?in 12) .28))) (assert (allowable-monthly-debts (* (/ ?in 12) .36))) ) (defrule expenses "Determine the applicant's actual expenses." (declare (salience -8)) (not (accepted no ?)) (allowable-monthly-housing-costs ?housing-costs) (allowable-monthly-debts ?debts) => (printout t crlf "In order to determine your total monthly housing costs ") (printout t crlf "please answer the following questions regarding your ") (printout t crlf "mortgage, . . . " crlf) ; (printout t "=> What is the interest rate percentage (xx.x)? ") (bind ?in (read)) (float ?in) (bind ?Rate (/ ?in 100)) ; (printout t "=> What is the purchase price of the home? ") (bind ?in (read)) (float ?in) (bind ?HomeAmt ?in) (assert (home-amount ?HomeAmt)) ; (printout t "=> What is the down payment (0 to skip)? ") (bind ?in (read)) (float ?in) (bind ?DownAmt ?in) (assert (down-payment (/ ?DownAmt ?HomeAmt))) ; ; WE NOW CALCULATE THIS INSTEAD OF ASK FOR IT ;(printout t "=> What is the loan amount? ") ;(bind ?in (read)) ;(float ?in) (bind ?LoanAmt (- ?HomeAmt ?DownAmt)) ; (printout t "=> What is the term (years)? ") (bind ?in (read)) (float ?in) (bind ?Term (* ?in 12)) ; ; CALCULATE THE MONTHLY PAYMENT FOR THE MORTGAGE (bind ?dMthlyIntRate (/ ?Rate 12.0)) (bind ?dDenominator (- (** (+ 1 ?dMthlyIntRate) ?Term) 1)) (bind ?dNumerator (* ?dMthlyIntRate (** (+ 1 ?dMthlyIntRate) ?Term))) (bind ?dPI (* ?LoanAmt (/ ?dNumerator ?dDenominator))) (assert (monthly-payment (round ?dPI))) (printout t crlf "The resulting monthly payment is: $" (round ?dPI) crlf) ; (bind ?ins-tax (round (* ?HomeAmt 0.0025))) (printout t crlf "The estimated monthly taxes and insurance is: $" ?ins-tax crlf) ; (printout t crlf "Any additional monthly housing costs ") (printout t crlf "to the nearest whole dollar (i.e. fees)? ") (bind ?in (read)) (integer ?in) (assert (total-monthly-housing-costs (+ ?in (round ?dPI) ?ins-tax))) ; (if (> ?in ?housing-costs) then (assert (expenses housing-costs exceeded)) else (assert (expenses housing-costs acceptable))) ; (printout t crlf "What is your other total monthly debts ") (printout t crlf "to the nearest whole dollar ") (printout t crlf "(i.e. car payment, credit cards, student loan, etc.)? ") (bind ?in (read)) (integer ?in) (assert (total-monthly-debts ?in)) ; (if (> ?in ?debts) then (assert (expenses debts exceeded)) else (assert (expenses debts acceptable))) ) (defrule bad-income-expenses1 "Check for the applicant's income vs. expenses." (declare (salience -9)) (expenses housing-costs exceeded) ;(not (accepted no ?)) => (assert (accepted no housing-costs)) (printout t crlf "The mortgage would not be approved due to the ") (printout t crlf "housing costs exceeding the allowable amount." crlf) ) (defrule bad-income-expenses2 "Check for the applicant's income vs. expenses." (declare (salience -9)) (expenses debts exceeded) ;(not (accepted no ?)) => (assert (accepted no debts)) (printout t crlf "The mortgage would not be approved due to the ") (printout t crlf "debts exceeding the allowable amount." crlf) ) (defrule approval1 "Determine the possibility of the applicant being approved." (declare (salience -10)) (not (accepted no ?)) (credit ?rating ?) (allowable-monthly-housing-costs ?housing-costs-allowable) (allowable-monthly-debts ?debts-allowable) (total-monthly-housing-costs ?housing-costs-total) (total-monthly-debts ?debts-total) (down-payment ?down-given) (home-amount ?home) => ; CONDITION 1: GREAT CREDIT AND INCOME, NO MONEY DOWN (if (or (eq ?rating excellent) (eq ?rating good)) then ;(< (* ?housing-costs-total 2) ?housing-costs-allowable) ;(< (* ?debts-total 2) ?debts-allowable)) (assert (accepted yes condition1)) (printout t crlf "Congratulations! Your mortgage will most likely be ") (printout t crlf "approved with NO money down." crlf) (bind ?down-expected (float .00))) ; ; CONDITION 2: FAIR CREDIT -or- NONE W/ BILLS PAID, INCOME AND 5% DOWN (if (or (eq ?rating fair) (eq ?rating none)) then (assert (accepted yes condition2)) (printout t crlf "Congratulations! Your mortgage will most likely be ") (printout t crlf "approved with a 5% down payment." crlf) (bind ?down-expected (float .05))) ; ; CONDITION 3: BAD CREDIT, INCOME AND 20% DOWN (if (eq ?rating bad) then (assert (accepted yes condition3)) (printout t crlf "Congratulations! Your mortgage will most likely be ") (printout t crlf "approved with a 20% down payment." crlf) (bind ?down-expected (float .20))) ; ; COMPARE THE DOWN PAYMENTS ; (DOWN GIVEN IN DOLLARS vs. DOWN EXPECTED IN PERCENT) (bind ?difference (round (* (abs (- ?down-expected ?down-given)) ?home))) (if (< ?down-given ?down-expected) then (printout t crlf "Your down payment needs to be increased ") (printout t crlf "by $" ?difference " to meet the minimum amount." crlf)) (if (= ?down-given ?down-expected) then (printout t crlf "Your down payment is the exactly the minimum amount." crlf)) (if (> ?down-given ?down-expected) then (printout t crlf "Your down payment is an extra ") (printout t crlf "$" ?difference " over the minimum amount." crlf)) ; ;(printout t crlf "Program exiting . . . " crlf) ) (defrule approval2 "Determine the possibility of the applicant being approved." (declare (salience -12)) (accepted yes ?) (credit ?rating ?) => ; CONDITION 4: FORECLOSURE/BANKRUPTCY, DISCUSS WITH LOAN OFFICER (if (or (eq ?rating foreclosure) (eq ?rating bankruptcy)) then (assert (accepted maybe condition4)) (printout t crlf "Unfortuantely it appears that due to your ") (printout t crlf "past " ?rating " you will need to discuss ") (printout t crlf "your situation with a loan officer." crlf)) )