def calc(request): eng = LiqEngine() #TODO add LSSpread and PriorDayRateUsed from config eng.setParameters(LSSpread = 1, PriorDayRateUsed = 3.5) eng.setLoans([{'loanId' : '1', 'mortgageOriginator': 'ABC Mortgage', 'loanAmount': 318725.0}, {'loanId' : '2', 'mortgageOriginator': 'ABC Mortgage', 'loanAmount': 375685.0}, {'loanId' : '3', 'mortgageOriginator': 'Prime Lending', 'loanAmount': 479875.0}, {'loanId' : '4', 'mortgageOriginator': 'Prime Lending', 'loanAmount': 525400.0}, {'loanId' : '5', 'mortgageOriginator': 'Best Loans Inc', 'loanAmount': 515425.0}, {'loanId' : '6', 'mortgageOriginator': 'Integrity Lending', 'loanAmount': 485000.0}]) eng.setUsers([{'userId' : '*****@*****.**', 'fundsAvailable': 187500.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 500000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 185000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 1500000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 860000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 300000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 250000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 74000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 285000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 532000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 292000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 752000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 418000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 47000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 283000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 598000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 639000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 274000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 629000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 562000.0}]) eng.setBids([{'date' : '15:00:00', 'bidId' : '1104134', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 500000.0, 'Participation' : 10, 'orderType' : 'Noncompetitive', 'bidRate' : 3.000, 'orderTiming' : 'Auto'}, {'date' : '15:00:00', 'bidId' : '1104143', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 500000.0, 'Participation' : 20, 'assetSubset' : 'Loan', 'loanId' : '1', 'orderType' : 'Noncompetitive', 'bidRate' : 2.875, 'orderTiming' : 'Auto'}, {'date' : '15:00:00', 'bidId' : '1104154', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 100000.0, 'Participation' : 10, 'orderType' : 'Noncompetitive', 'bidRate' : 2.000, 'orderTiming' : 'Auto'}, {'date' : '15:00:00', 'bidId' : '1104152', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 100000.0, 'Participation' : 30, 'assetSubset' : 'Loan', 'loanId' : '3', 'orderType' : 'Noncompetitive', 'bidRate' : 2.500, 'orderTiming' : 'Auto'}, {'date' : '17:06:12', 'bidId' : '1104136', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 500000.0, 'Participation' : 10, 'orderType' : 'Noncompetitive', 'bidRate' : 2.750, 'orderTiming' : 'Day Trade'}, {'date' : '18:32:36', 'bidId' : '1104138', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 500000.0, 'Participation' : 10, 'assetSubset' : 'Loan', 'loanId' : '5', 'orderType' : 'Noncompetitive', 'bidRate' : 2.625, 'orderTiming' : 'Day Trade'}, {'date' : '19:15:48', 'bidId' : '1104139', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 100000.0, 'Participation' : 20, 'orderType' : 'Noncompetitive', 'bidRate' : 2.250, 'orderTiming' : 'Day Trade'}, {'date' : '19:59:00', 'bidId' : '1104140', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 100000.0, 'Participation' : 20, 'assetSubset' : 'MO', 'mortgageOriginator' : 'ABC Mortgage', 'orderType' : 'Noncompetitive', 'bidRate' : 2.875, 'orderTiming' : 'Day Trade'}, {'date' : '20:42:12', 'bidId' : '1104141', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 500000.0, 'Participation' : 30, 'orderType' : 'Noncompetitive', 'bidRate' : 3.000, 'orderTiming' : 'Day Trade'}, {'date' : '21:39:48', 'bidId' : '1104159', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 500000.0, 'Participation' : 30, 'assetSubset' : 'Loan', 'loanId' : '3', 'orderType' : 'Noncompetitive', 'bidRate' : 3.125, 'orderTiming' : 'Day Trade'}, {'date' : '23:06:12', 'bidId' : '1104161', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 100000.0, 'Participation' : 40, 'orderType' : 'Noncompetitive', 'bidRate' : 2.500, 'orderTiming' : 'Day Trade'}, {'date' : '23:35:00', 'bidId' : '1104145', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 100000.0, 'Participation' : 30, 'assetSubset' : 'Loan', 'loanId' : '1', 'orderType' : 'Noncompetitive', 'bidRate' : 2.375, 'orderTiming' : 'Day Trade'}, {'date' : '2:23:00', 'bidId' : '1104133', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 500000.0, 'Participation' : 20, 'orderType' : 'Noncompetitive', 'bidRate' : 3.500, 'orderTiming' : 'Day Trade'}, {'date' : '2:27:48', 'bidId' : '1104149', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 500000.0, 'Participation' : 10, 'assetSubset' : 'Loan', 'loanId' : '1', 'orderType' : 'Noncompetitive', 'bidRate' : 3.375, 'orderTiming' : 'Day Trade'}, {'date' : '3:54:12', 'bidId' : '1104151', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 100000.0, 'Participation' : 20, 'orderType' : 'Noncompetitive', 'bidRate' : 2.125, 'orderTiming' : 'Day Trade'}, {'date' : '4:37:24', 'bidId' : '1104131', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 100000.0, 'Participation' : 30, 'assetSubset' : 'MO', 'mortgageOriginator' : 'Prime Lending', 'orderType' : 'Noncompetitive', 'bidRate' : 2.500, 'orderTiming' : 'Day Trade'}, {'date' : '6:47:00', 'bidId' : '1104155', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 500000.0, 'Participation' : 20, 'orderType' : 'Noncompetitive', 'bidRate' : 2.875, 'orderTiming' : 'Day Trade'}, {'date' : '7:30:12', 'bidId' : '1104156', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 500000.0, 'Participation' : 10, 'assetSubset' : 'Loan', 'loanId' : '1', 'orderType' : 'Noncompetitive', 'bidRate' : 2.500, 'orderTiming' : 'Day Trade'}, {'date' : '8:13:24', 'bidId' : '1104157', 'userId' : '*****@*****.**', 'bidType' : 'General', 'Aggregate' : 100000.0, 'Participation' : 10, 'orderType' : 'Noncompetitive', 'bidRate' : 2.000, 'orderTiming' : 'Day Trade'}, {'date' : '8:56:36', 'bidId' : '1104158', 'userId' : '*****@*****.**', 'bidType' : 'Specified', 'Aggregate' : 100000.0, 'Participation' : 10, 'assetSubset' : 'Loan', 'loanId' : '3', 'orderType' : 'Noncompetitive', 'bidRate' : 2.125, 'orderTiming' : 'Day Trade'}]) try: context = eng.Calc() Context = UserContext(request) Context['loans'] = [] for c in context['loans'].iteritems(): Context['loans'].append(c[0]) Context['bids'] = [] for b in context['bids'].iteritems(): c = [{'bid': b[0]}] for l in Context['loans']: if l in b[1]['allocatedAmounts']: c.append(({"key": l, "val": '%.2f' % b[1]['allocatedAmounts'][l]})) else: c.append(({"key": l, "val": 0})) Context['bids'].append(c) return render_to_response("engine/results.html", Context, context_instance=RequestContext(request)) except: return render_to_response("500.html", context_instance=RequestContext(request))
def CallEngine(): eng = LiqEngine() # TODO add LSSpread and PriorDayRateUsed from config eng.setParameters(LSSpread=1, PriorDayRateUsed=3.5) mortop = db.GqlQuery("SELECT * " "FROM User Where group = 'MO'") mo = [] for m in mortop: mo.append(m.key().name()) eng.setMortgageOriginator(mo) # TODO only set loans who are involved in the calc loans = db.GqlQuery("SELECT * " "FROM Loan") s = [] for l in loans: s.append({"loanId": l.key().name(), "mortgageOriginator": l.customer_account_key, "loanAmount": l.curr_upb}) eng.setLoans(s) users = db.GqlQuery("SELECT * " "FROM User Where group = 'Broker'") usr = [] for u in users: usr.append({"userId": u.key().name(), "fundsAvailable": u.fundsAvailable}) eng.setUsers(usr) bids = db.GqlQuery("SELECT * " "FROM Bid") s = [] for b in bids: d = {"date": b.createdAt, "bidId": b.key().name()} d["userId"] = b.user.key().name() d["bidType"] = b.bidtype if b.bidtype == "Specified": d["assetSubset"] = b.lorm d["Participation"] = b.participation d["Aggregate"] = b.aggregated if b.lorm == "Loan": d["loanId"] = b.loan.key().name() elif b.lorm == "MO": d["mortgageOriginator"] = b.mo.key().name() d["orderTiming"] = b.ordertiming d["orderType"] = b.ordertype if b.ordertype == "Competitive": d["bidRate"] = b.bidrate # if b.ordertiming == 'Auto': # d[''] = b.orderAt s.append(d) eng.setBids(s) return eng.Calc()
#!/usr/bin/python from pprint import pprint from LiqSpot import LiqEngine eng = LiqEngine() eng.setParameters(LSSpread = 1, PriorDayRateUsed = 3.5) eng.setMortgageOriginator(['ABC Mortgage', 'Prime Lending', 'Best Loans Inc', 'Integrity Lending']) eng.setLoans([{'loanId' : '1', 'mortgageOriginator': 'ABC Mortgage', 'loanAmount': 318725.0}, {'loanId' : '2', 'mortgageOriginator': 'ABC Mortgage', 'loanAmount': 375685.0}, {'loanId' : '3', 'mortgageOriginator': 'Prime Lending', 'loanAmount': 479875.0}, {'loanId' : '4', 'mortgageOriginator': 'Prime Lending', 'loanAmount': 525400.0}, {'loanId' : '5', 'mortgageOriginator': 'Best Loans Inc', 'loanAmount': 515425.0}, {'loanId' : '6', 'mortgageOriginator': 'Integrity Lending', 'loanAmount': 485000.0}]) eng.setUsers([{'userId' : '*****@*****.**', 'fundsAvailable': 187500.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 500000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 185000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 1500000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 860000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 300000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 250000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 74000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 285000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 532000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 292000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 752000.0}, {'userId' : '*****@*****.**', 'fundsAvailable': 418000.0},
#!/usr/bin/python from pprint import pprint from LiqSpot import LiqEngine import datetime #TODO pilas los fondos de 4157 se van a negativo eng = LiqEngine() eng.setParameters(LSSpread = 1, PriorDayRateUsed = 3.5) #TODO add MortgageOriginator eng.setMortgageOriginator([u'ABCD', u'BCDE', u'EFGH', u'HIJK']) eng.setLoans([{'loanAmount': 408378L, 'mortgageOriginator': u'HIJK', 'loanId': u'201144387'}, {'loanAmount': 360000L, 'mortgageOriginator': u'BCDE', 'loanId': u'201144944'}, {'loanAmount': 260000L, 'mortgageOriginator': u'BCDE', 'loanId': u'201145114'}, {'loanAmount': 625500L, 'mortgageOriginator': u'BCDE', 'loanId': u'201145234'}, {'loanAmount': 280000L, 'mortgageOriginator': u'ABCD', 'loanId': u'201145359'}, {'loanAmount': 255000L, 'mortgageOriginator': u'EFGH', 'loanId': u'201145735'}, {'loanAmount': 417000L, 'mortgageOriginator': u'EFGH', 'loanId': u'201145759'}, {'loanAmount': 458000L, 'mortgageOriginator': u'EFGH', 'loanId': u'201146570'}, {'loanAmount': 250000L, 'mortgageOriginator': u'BCDE', 'loanId': u'201146741'}, {'loanAmount': 147250L, 'mortgageOriginator': u'BCDE', 'loanId': u'201147140'}, {'loanAmount': 478507L, 'mortgageOriginator': u'EFGH', 'loanId': u'201147282'}, {'loanAmount': 301000L, 'mortgageOriginator': u'HIJK', 'loanId': u'201147471'}, {'loanAmount': 417000L, 'mortgageOriginator': u'HIJK', 'loanId': u'201147482'}, {'loanAmount': 290700L, 'mortgageOriginator': u'BCDE', 'loanId': u'201147544'}, {'loanAmount': 314000L, 'mortgageOriginator': u'BCDE', 'loanId': u'201147653'}, {'loanAmount': 327200L, 'mortgageOriginator': u'HIJK', 'loanId': u'201147776'}, {'loanAmount': 350000L, 'mortgageOriginator': u'ABCD', 'loanId': u'201148009'},