def CleanDeal(self, sFICO, pLTV, sTerm): # This function will clean up the sFICO, pLTV, and sTerm # parameters, so they can be used to find APR and Monthly payment # If uncleanable, return 0-0-0; else, return Fico-LTV-Term # The returned values will correspond to a grid point on the # tabulated APRGrid and MonthlyGrid dictionaries try: if isNull(sFICO): FICO = self.LowFico else: FICO = max(self.LowFico, min(self.HighFico, float(sFICO))) FICO = int(round((FICO - self.LowFico)/self.StepFico) * self.StepFico + self.LowFico) LTV = max(self.LowLTV, min(self.HighLTV, 100.0 * pLTV)) LTV = int(round((LTV - self.LowLTV)/self.StepLTV) * self.StepLTV + self.LowLTV) Term = int(fixNull(sTerm, cfg.TermWanted)) if (Term < self.LowTerm) or (Term > self.HighTerm) or \ ( (Term - self.LowTerm) % self.StepTerm != 0): return (0, 0, 0) return (FICO, LTV, Term) except ValueError: return (0, 0, 0) except: print "Unexpected error in CleanDeal:" print "sFICO = " + str(sFICO) print "pLTV = " + str(pLTV) print "sTerm = " + str(sTerm) raise
def SQL_FindMonthly(sSellingPrice, sInvoice, iCashCost, sTradeIn, sPayoff, fDownCash, sFico, sTerm): # Find required MonthlyPayments for a given DownCash figure # Logic: LoanAmount = Price - [ DownCash + TradeIn - TradeInPayoff ] # LTV = LoanAmount / Invoice # Use LTV and FICO to find [Monthly%] in the M72 table # The M72 tables incorporates the active APR grid # Monthly% is the Monthly payment as a % of LoanAmount # MonthlyPayment = [Monthly%] * LoanAmount try: Invoice = float(fixZero(sInvoice, fixZero(sSellingPrice, iCashCost))) if Invoice == 0: return "0" TradeInNet = float0(sTradeIn) - float0(sPayoff) DownPayment = float0(fDownCash) + TradeInNet LoanAmount = iCashCost - DownPayment LTV = LoanAmount / Invoice sFico = fixNull(sFico, str(cfg.LowestFicoAnywhere)) Results = MyAPR.GetMonthly(sFico, LTV, sTerm) * LoanAmount return int(round(Results)) except ValueError: return "" except: print "Unexpected error in SQL_FindMonthly:" print "sSellingPrice = " + str(sSellingPrice) print "sInvoice = " + str(sInvoice) print "iCashCost = " + str(iCashCost) print "sTradeIn = " + str(sTradeIn) print "sPayoff = " + str(sPayoff) print "fDownCash = " + str(fDownCash) print "sFico = " + str(sFico) print "sTerm = " + str(sTerm) raise
def SQL_FindAPR(sSellingPrice, sInvoice, iCashCost, sTradeIn, sPayoff, fDownCash, sFico, sTerm): # Find the APR for a given DownCash figure # Logic: LoanAmount = Price - [ DownCash + TradeIn - TradeInPayoff ] # LTV = LoanAmount / Invoice # Use LTV and FICO to find APR in the APR table global GlobalAPR try: Invoice = float(fixZero(sInvoice, fixZero(sSellingPrice, iCashCost))) if Invoice == 0: return "0" TradeInNet = float0(sTradeIn) - float0(sPayoff) DownPayment = float0(fDownCash) + TradeInNet LoanAmount = iCashCost - DownPayment LTV = LoanAmount / Invoice sFico = fixNull(sFico, str(cfg.LowestFicoAnywhere)) Results = MyAPR.GetAPR(sFico, LTV, sTerm) return str(Results) except ValueError: return "" except: print "Unexpected error in SQL_FindAPR:" print "sSellingPrice = " + str(sSellingPrice) print "sInvoice = " + str(sInvoice) print "iCashCost = " + str(iCashCost) print "sTradeIn = " + str(sTradeIn) print "sPayoff = " + str(sPayoff) print "fDownCash = " + str(fDownCash) print "sFico = " + str(sFico) print "sTerm = " + str(sTerm) raise
def SQL_FindDown(sSellingPrice, sInvoice, iCashCost, sTradeIn, sPayoff, fMonthly, sFico, sTerm): # Find required DownCash for a given MonthlyPayment figure # This is the reverse of SQL_DealUpfront() # Note: This one is tricky, since APR computation requires knowing LTV, # but LTV is driven by DownCash -- which is the solution we seek # It is assumed that APR is monotone increasing with LTV # # Logic: Try each LTV granularity possibility starting with the lowest LTV # The list length is the number of LTV granulations (=17) # For each LTV in the list: # Use FICO and LTV to find [Monthly%] in the M72 Table # LoanAmount = MonthlyPayment / [%Monthly] # ConsequentLTV = LoanAmount / Invoice # If ConsequentLTV > LTV, not a solution; continue to next LTV # If reached highest LTV, and still not a solution; use highest LTV # Once a solution is found (or using highest): # DownCash = Price - LoanAmount - [TradeIn - TradeInPayoff] try: Invoice = float(fixZero(sInvoice, fixZero(sSellingPrice, iCashCost))) if Invoice == 0: return "0" TradeInNet = float0(sTradeIn) - float0(sPayoff) Monthly = float0(fMonthly) sFico = fixNull(sFico, str(cfg.LowestFicoAnywhere)) NeedSolution = True TryLTV = MyAPR.LowLTV while TryLTV <= MyAPR.HighLTV and NeedSolution: LoanAmount = Monthly / MyAPR.GetMonthly(sFico, TryLTV, sTerm) NeedSolution = (LoanAmount / Invoice) > TryLTV TryLTV += MyAPR.StepLTV Results = iCashCost - LoanAmount - TradeInNet return int(round(Results)) except ValueError: return "" except: print "Unexpected error in SQL_FindDown:" print "sSellingPrice = " + str(sSellingPrice) print "sInvoice = " + str(sInvoice) print "iCashCost = " + str(iCashCost) print "sTradeIn = " + str(sTradeIn) print "sPayoff = " + str(sPayoff) print "fMonthly = " + str(fMonthly) print "sFico = " + str(sFico) raise #MySelections = VehicleArray(SessionFilterArray, SessionConsumer, MyAPR) #MySelections0 = MySelections