def load_product_data(self, data_date, zfile):
        """ Load the daily product data."""
        filename = "%s_product.txt" % data_date
        data_date = timezone.make_aware(
            datetime.strptime(data_date, '%Y%m%d'),
            timezone.get_current_timezone())

        product_reader = reader(StringIO.StringIO(zfile.read(filename)), delimiter='\t')

        #Skip the first row as it contains column documentation
        iterproducts = iter(product_reader)
        next(iterproducts)

        products = []
        total_products = 0
        for row in iterproducts:
            total_products += 1
            p = Product()
            p.plan_id = int(row[0])
            p.institution = row[1]
            p.loan_purpose = row[2]
            p.pmt_type = row[3]
            p.loan_type = row[4]
            p.loan_term = int(row[5])
            p.int_adj_term = self.nullable_int(row[6])
            p.adj_period = self.nullable_int(row[7])
            p.io = self.string_to_boolean(row[8])
            p.arm_index = self.nullable_string(row[9])
            p.int_adj_cap = self.nullable_int(row[10])

            p.annual_cap = self.nullable_int(row[11])
            p.loan_cap = self.nullable_int(row[12])
            p.arm_margin = self.nullable_decimal(row[13])
            p.ai_value = self.nullable_decimal(row[14])

            p.min_ltv = float(row[15])
            p.max_ltv = float(row[16])
            p.min_fico = int(row[17])
            p.max_fico = int(row[18])
            p.min_loan_amt = Decimal(row[19])
            p.max_loan_amt = Decimal(row[20])

            p.data_timestamp = data_date
            products.append(p)

            if len(products) > 1000:
                Product.objects.bulk_create(products)
                products[:] = []

        Product.objects.bulk_create(products)
        if not total_products or Product.objects.count() != total_products:
            raise OaHException("Couldn't load product data from %s" % zfile.filename)
Esempio n. 2
0
    def setUp(self):

        self.url = '/oah-api/rates/rate-checker'
        REGIONS = [[1, 'DC'], [2, 'VA']]
        PRODUCTS = [
            # plan_id, institution, loan_purpose, pmt_type, loan_type, loan_term, int_adj_term, _, io, _, _, _, _, _, _,
            # min_ltv, max_ltv, minfico, maxfico, min_loan_amt, max_loan_amt, single_family, condo, coop
            [
                11, 'Institution 1', 'PURCH', 'FIXED', 'CONF', 30, None, None,
                0, None, None, None, None, None, None, 1, 95, 680, 700, 90000,
                750000, 1, 0, 0
            ],
            [
                22, 'Institution 2', 'PURCH', 'FIXED', 'CONF', 30, None, None,
                0, None, None, None, None, None, None, 1, 87, 680, 740, 90000,
                550000, 1, 0, 0
            ],
            [
                33, 'Institution 3', 'PURCH', 'ARM', 'CONF', 15, 5, None, 0,
                None, None, None, None, None, None, 1, 95, 680, 740, 90000,
                550000, 1, 0, 0
            ],
            [
                44, 'Institution 4', 'PURCH', 'FIXED', 'CONF', 30, None, None,
                0, None, None, None, None, None, None, 1, 87, 680, 740, 90000,
                550000, 1, 0, 0
            ],
            [
                55, 'Institution 5', 'PURCH', 'ARM', 'CONF', 30, 5, None, 0,
                None, None, None, None, None, None, 1, 87, 680, 740, 90000,
                550000, 1, 0, 0
            ],
            [
                66, 'Institution 6', 'PURCH', 'FIXED', 'CONF', 30, None, None,
                0, None, None, None, None, None, None, 1, 87, 680, 740, 90000,
                550000, 1, 0, 0
            ],
            [
                77, 'Institution 7', 'PURCH', 'FIXED', 'FHA-HB', 15, None,
                None, 0, None, None, None, None, None, None, 1, 87, 680, 740,
                90000, 550000, 1, 0, 0
            ],
            [
                88, 'Institution 8', 'PURCH', 'FIXED', 'FHA', 30, None, None,
                0, None, None, None, None, None, None, 1, 87, 680, 740, 90000,
                550000, 1, 0, 0
            ],
        ]
        RATES = [
            # rate_id, product_id, region_id, lock, base_rate, total_points
            [111, 11, 1, 50, '3.150', '0.5'],
            [112, 11, 2, 60, '4.350', '-0.5'],
            [113, 11, 1, 60, '2.125', '0.125'],
            [221, 22, 1, 60, '3.555', '0.125'],
            [331, 33, 1, 60, '3.250', '0.125'],
            [332, 33, 2, 60, '4.650', '-0.5'],
            [441, 44, 1, 50, '3.125', '1.25'],
            [551, 55, 1, 50, '0.125', '0.125'],
            [661, 66, 1, 60, '3.705', '0.5'],
            [771, 77, 2, 60, '1.705', '0.25'],
            [772, 77, 2, 60, '2.705', '1.25'],
            [881, 88, 1, 60, '3.000', '0.5'],
            [882, 88, 1, 60, '2.005', '0.25'],
            [883, 88, 1, 60, '1.005', '-0.25'],
        ]
        ADJUSTMENTS = [
            # rule_id, product_id, affect_rate_type, adj_value, min_loan_amt, max_loan_amt
            # prop_type, minfico, maxfico, minltv, maxltv, state
            [
                1, 11, 'P', '-0.35', 100000, 500000, 'CONDO', 660, 780, 30, 95,
                'DC'
            ],
            [
                2, 11, 'P', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95,
                'DC'
            ],
            [
                3, 11, 'R', '0.15', 100000, 500000, 'CONDO', 660, 780, 30, 95,
                'DC'
            ],
            [
                4, 22, 'R', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95,
                'VA'
            ],
            [
                5, 22, 'R', '0.15', 100000, 500000, 'CONDO', 660, 780, 30, 95,
                'DC'
            ],
            [
                6, 33, 'R', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95,
                'DC'
            ],
            [
                7, 77, 'P', '0.125', 100000, 500000, 'CONDO', 660, 780, 30, 95,
                'VA'
            ],
        ]
        FEES = [
            # plan_id, product_id, state_id, lender , single_family, condo, coop,
            # origination_dollar, origination_percent, third_party
            [11, 11111, 'DC', 'SMPL', 1, 1, 1, 1608.0000, .000, 587.2700],
            [11, 11111, 'DC', 'SMPL1', 1, 0, 1, 1610.0000, .000, 589.2700],
            [10, 11001, 'DC', 'SMPL1', 0, 1, 0, 1610.0000, .000, 589.2700],
            [11, 11111, 'VA', 'SMPL2', 1, 1, 1, 1610.0000, .000, 589.2700],
        ]
        NOW = timezone.now()

        for region in REGIONS:
            reg = Region(region_id=region[0],
                         state_id=region[1],
                         data_timestamp=NOW)
            reg.save()

        for p in PRODUCTS:
            product = Product(plan_id=p[0],
                              institution=p[1],
                              loan_purpose=p[2],
                              pmt_type=p[3],
                              loan_type=p[4],
                              loan_term=p[5],
                              int_adj_term=p[6],
                              adj_period=p[7],
                              io=p[8],
                              arm_index=p[9],
                              int_adj_cap=p[10],
                              annual_cap=p[11],
                              loan_cap=p[12],
                              arm_margin=p[13],
                              ai_value=p[14],
                              min_ltv=p[15],
                              max_ltv=p[16],
                              min_fico=p[17],
                              max_fico=p[18],
                              min_loan_amt=p[19],
                              max_loan_amt=p[20],
                              single_family=p[21],
                              condo=p[22],
                              coop=p[23],
                              data_timestamp=NOW)
            product.save()

        for r in RATES:
            rate = Rate(rate_id=r[0],
                        product_id=r[1],
                        region_id=r[2],
                        lock=r[3],
                        base_rate=r[4],
                        total_points=r[5],
                        data_timestamp=NOW)
            rate.save()

        for a in ADJUSTMENTS:
            adjustment = Adjustment(rule_id=a[0],
                                    product_id=a[1],
                                    affect_rate_type=a[2],
                                    adj_value=a[3],
                                    min_loan_amt=a[4],
                                    max_loan_amt=a[5],
                                    prop_type=a[6],
                                    min_fico=a[7],
                                    max_fico=a[8],
                                    min_ltv=a[9],
                                    max_ltv=a[10],
                                    state=a[11],
                                    data_timestamp=NOW)
            adjustment.save()

        for f in FEES:
            fee = Fee(plan_id=f[0],
                      product_id=f[1],
                      state_id=f[2],
                      lender=f[3],
                      single_family=f[4],
                      condo=f[5],
                      coop=f[6],
                      origination_dollar=Decimal("%s" % f[7]),
                      origination_percent=Decimal("%s" % f[8]),
                      third_party=Decimal("%s" % f[9]),
                      data_timestamp=NOW)
            fee.save()
 def create_product(self, row):
     """ Helper function to save a product."""
     p = Product()
     p.plan_id = int(row[0])
     p.institution = row[1]
     p.loan_purpose = row[2]
     p.pmt_type = row[3]
     p.loan_type = row[4]
     p.loan_term = int(row[5])
     p.int_adj_term = self.c.nullable_int(row[6])
     p.adj_period = self.c.nullable_int(row[7])
     p.io = self.c.string_to_boolean(row[8])
     p.arm_index = self.c.nullable_string(row[9])
     p.int_adj_cap = self.c.nullable_int(row[10])
     p.annual_cap = self.c.nullable_int(row[11])
     p.loan_cap = self.c.nullable_int(row[12])
     p.arm_margin = self.c.nullable_decimal(row[13])
     p.ai_value = self.c.nullable_decimal(row[14])
     p.min_ltv = float(row[15])
     p.max_ltv = float(row[16])
     p.min_fico = int(row[17])
     p.max_fico = int(row[18])
     p.min_loan_amt = Decimal(row[19])
     p.max_loan_amt = Decimal(row[20])
     p.data_timestamp = datetime.strptime('20140101', '%Y%m%d')
     p.save()
     return p
    def load_product_data(self, data_date, product_filename):
        """ Load the daily product data."""

        with open(product_filename) as product_csv:
            product_reader = reader(product_csv, delimiter="\t")

            # Skip the first row as it contains column documentation
            iterproducts = iter(product_reader)
            next(iterproducts)

            products = []
            for row in iterproducts:

                p = Product()
                p.plan_id = int(row[0])
                p.institution = row[1]
                p.loan_purpose = row[2]
                p.pmt_type = row[3]
                p.loan_type = row[4]
                p.loan_term = int(row[5])
                p.int_adj_term = self.nullable_int(row[6])
                p.adj_period = self.nullable_int(row[7])
                p.io = self.string_to_boolean(row[8])
                p.arm_index = self.nullable_string(row[9])
                p.int_adj_cap = self.nullable_int(row[10])

                p.annual_cap = self.nullable_int(row[11])
                p.loan_cap = self.nullable_int(row[12])
                p.arm_margin = self.nullable_decimal(row[13])
                p.ai_value = self.nullable_decimal(row[14])

                p.min_ltv = float(row[15])
                p.max_ltv = float(row[16])
                p.min_fico = int(row[17])
                p.max_fico = int(row[18])
                p.min_loan_amt = Decimal(row[19])
                p.max_loan_amt = Decimal(row[20])

                p.data_timestamp = data_date
                products.append(p)

                if len(products) > 1000:
                    Product.objects.bulk_create(products)
                    products[:] = []

            Product.objects.bulk_create(products)
Esempio n. 5
0
    def setUp(self):

        self.url = "/oah-api/rates/rate-checker"
        REGIONS = [[1, "DC"], [2, "VA"]]
        PRODUCTS = [
            # plan_id, institution, loan_purpose, pmt_type, loan_type, loan_term, int_adj_term, _, io, _, _, _, _, _, _,  # noqa
            # min_ltv, max_ltv, minfico, maxfico, min_loan_amt, max_loan_amt, single_family, condo, coop  # noqa
            [
                11,
                "Institution 1",
                "PURCH",
                "FIXED",
                "CONF",
                30,
                None,
                None,
                0,
                None,
                None,
                None,
                None,
                None,
                None,
                1,
                95,
                680,
                700,
                90000,
                750000,
                1,
                0,
                0,
            ],
            [
                22,
                "Institution 2",
                "PURCH",
                "FIXED",
                "CONF",
                30,
                None,
                None,
                0,
                None,
                None,
                None,
                None,
                None,
                None,
                1,
                87,
                680,
                740,
                90000,
                550000,
                1,
                0,
                0,
            ],
            [
                33,
                "Institution 3",
                "PURCH",
                "ARM",
                "CONF",
                15,
                5,
                None,
                0,
                None,
                None,
                None,
                None,
                None,
                None,
                1,
                95,
                680,
                740,
                90000,
                550000,
                1,
                0,
                0,
            ],
            [
                44,
                "Institution 4",
                "PURCH",
                "FIXED",
                "CONF",
                30,
                None,
                None,
                0,
                None,
                None,
                None,
                None,
                None,
                None,
                1,
                87,
                680,
                740,
                90000,
                550000,
                1,
                0,
                0,
            ],
            [
                55,
                "Institution 5",
                "PURCH",
                "ARM",
                "CONF",
                30,
                5,
                None,
                0,
                None,
                None,
                None,
                None,
                None,
                None,
                1,
                87,
                680,
                740,
                90000,
                550000,
                1,
                0,
                0,
            ],
            [
                66,
                "Institution 6",
                "PURCH",
                "FIXED",
                "CONF",
                30,
                None,
                None,
                0,
                None,
                None,
                None,
                None,
                None,
                None,
                1,
                87,
                680,
                740,
                90000,
                550000,
                1,
                0,
                0,
            ],
            [
                77,
                "Institution 7",
                "PURCH",
                "FIXED",
                "FHA-HB",
                15,
                None,
                None,
                0,
                None,
                None,
                None,
                None,
                None,
                None,
                1,
                87,
                680,
                740,
                90000,
                550000,
                1,
                0,
                0,
            ],
            [
                88,
                "Institution 8",
                "PURCH",
                "FIXED",
                "FHA",
                30,
                None,
                None,
                0,
                None,
                None,
                None,
                None,
                None,
                None,
                1,
                87,
                680,
                740,
                90000,
                550000,
                1,
                0,
                0,
            ],
        ]
        RATES = [
            # rate_id, product_id, region_id, lock, base_rate, total_points
            [111, 11, 1, 50, "3.150", "0.5"],
            [112, 11, 2, 60, "4.350", "-0.5"],
            [113, 11, 1, 60, "2.125", "0.125"],
            [221, 22, 1, 60, "3.555", "0.125"],
            [331, 33, 1, 60, "3.250", "0.125"],
            [332, 33, 2, 60, "4.650", "-0.5"],
            [441, 44, 1, 50, "3.125", "1.25"],
            [551, 55, 1, 50, "0.125", "0.125"],
            [661, 66, 1, 60, "3.705", "0.5"],
            [771, 77, 2, 60, "1.705", "0.25"],
            [772, 77, 2, 60, "2.705", "1.25"],
            [881, 88, 1, 60, "3.000", "0.5"],
            [882, 88, 1, 60, "2.005", "0.25"],
            [883, 88, 1, 60, "1.005", "-0.25"],
        ]
        ADJUSTMENTS = [
            # rule_id, product_id, affect_rate_type, adj_value, min_loan_amt,
            # max_loan_amt, prop_type, minfico, maxfico, minltv, maxltv, state
            [
                1,
                11,
                "P",
                "-0.35",
                100000,
                500000,
                "CONDO",
                660,
                780,
                30,
                95,
                "DC",
            ],
            [
                2,
                11,
                "P",
                "0.25",
                100000,
                500000,
                "CONDO",
                660,
                780,
                30,
                95,
                "DC",
            ],
            [
                3,
                11,
                "R",
                "0.15",
                100000,
                500000,
                "CONDO",
                660,
                780,
                30,
                95,
                "DC",
            ],
            [
                4,
                22,
                "R",
                "0.25",
                100000,
                500000,
                "CONDO",
                660,
                780,
                30,
                95,
                "VA",
            ],
            [
                5,
                22,
                "R",
                "0.15",
                100000,
                500000,
                "CONDO",
                660,
                780,
                30,
                95,
                "DC",
            ],
            [
                6,
                33,
                "R",
                "0.25",
                100000,
                500000,
                "CONDO",
                660,
                780,
                30,
                95,
                "DC",
            ],
            [
                7,
                77,
                "P",
                "0.125",
                100000,
                500000,
                "CONDO",
                660,
                780,
                30,
                95,
                "VA",
            ],
        ]
        NOW = timezone.now()

        for region in REGIONS:
            reg = Region(region_id=region[0],
                         state_id=region[1],
                         data_timestamp=NOW)
            reg.save()

        for p in PRODUCTS:
            product = Product(
                plan_id=p[0],
                institution=p[1],
                loan_purpose=p[2],
                pmt_type=p[3],
                loan_type=p[4],
                loan_term=p[5],
                int_adj_term=p[6],
                adj_period=p[7],
                io=p[8],
                arm_index=p[9],
                int_adj_cap=p[10],
                annual_cap=p[11],
                loan_cap=p[12],
                arm_margin=p[13],
                ai_value=p[14],
                min_ltv=p[15],
                max_ltv=p[16],
                min_fico=p[17],
                max_fico=p[18],
                min_loan_amt=p[19],
                max_loan_amt=p[20],
                single_family=p[21],
                condo=p[22],
                coop=p[23],
                data_timestamp=NOW,
            )
            product.save()

        for r in RATES:
            rate = Rate(
                rate_id=r[0],
                product_id=r[1],
                region_id=r[2],
                lock=r[3],
                base_rate=r[4],
                total_points=r[5],
                data_timestamp=NOW,
            )
            rate.save()

        for a in ADJUSTMENTS:
            adjustment = Adjustment(
                rule_id=a[0],
                product_id=a[1],
                affect_rate_type=a[2],
                adj_value=a[3],
                min_loan_amt=a[4],
                max_loan_amt=a[5],
                prop_type=a[6],
                min_fico=a[7],
                max_fico=a[8],
                min_ltv=a[9],
                max_ltv=a[10],
                state=a[11],
                data_timestamp=NOW,
            )
            adjustment.save()
Esempio n. 6
0
    def load_product_data(self, data_date, zfile):
        """ Load the daily product data."""
        filename = "%s_product.txt" % data_date
        data_date = timezone.make_aware(datetime.strptime(data_date, '%Y%m%d'),
                                        timezone.get_current_timezone())

        product_reader = reader(StringIO.StringIO(zfile.read(filename)),
                                delimiter='\t')

        #Skip the first row as it contains column documentation
        iterproducts = iter(product_reader)
        next(iterproducts)

        products = []
        total_products = 0
        for row in iterproducts:
            total_products += 1
            p = Product()
            p.plan_id = int(row[0])
            p.institution = row[1]
            p.loan_purpose = row[2]
            p.pmt_type = row[3]
            p.loan_type = row[4]
            p.loan_term = int(row[5])
            p.int_adj_term = self.nullable_int(row[6])
            p.adj_period = self.nullable_int(row[7])
            p.io = self.string_to_boolean(row[8])
            p.arm_index = self.nullable_string(row[9])
            p.int_adj_cap = self.nullable_int(row[10])

            p.annual_cap = self.nullable_int(row[11])
            p.loan_cap = self.nullable_int(row[12])
            p.arm_margin = self.nullable_decimal(row[13])
            p.ai_value = self.nullable_decimal(row[14])

            p.min_ltv = Decimal(row[15]).quantize(Decimal('.001'))
            p.max_ltv = Decimal(row[16]).quantize(Decimal('.001'))
            p.min_fico = int(row[17])
            p.max_fico = int(row[18])
            p.min_loan_amt = Decimal(row[19])
            p.max_loan_amt = Decimal(row[20])

            p.data_timestamp = data_date
            products.append(p)

            if len(products) > 1000:
                Product.objects.bulk_create(products)
                products[:] = []

        Product.objects.bulk_create(products)
        if not total_products or Product.objects.count() != total_products:
            raise OaHException("Couldn't load product data from %s" %
                               zfile.filename)
Esempio n. 7
0
    def setUp(self):

        self.url = '/oah-api/rates/rate-checker'
        REGIONS = [[1, 'DC'], [2, 'VA']]
        PRODUCTS = [
            # plan_id, institution, loan_purpose, pmt_type, loan_type, loan_term, int_adj_term, _, io, _, _, _, _, _, _,
            # min_ltv, max_ltv, minfico, maxfico, min_loan_amt, max_loan_amt, single_family, condo, coop
            [11, 'Institution 1', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 95, 680, 700, 90000, 750000, 1, 0, 0],
            [22, 'Institution 2', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [33, 'Institution 3', 'PURCH', 'ARM', 'CONF', 15, 5, None, 0, None, None, None, None, None, None, 1, 95, 680, 740, 90000, 550000, 1, 0, 0],
            [44, 'Institution 4', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [55, 'Institution 5', 'PURCH', 'ARM', 'CONF', 30, 5, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [66, 'Institution 6', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [77, 'Institution 7', 'PURCH', 'FIXED', 'FHA-HB', 15, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [88, 'Institution 8', 'PURCH', 'FIXED', 'FHA', 30, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
        ]
        RATES = [
            # rate_id, product_id, region_id, lock, base_rate, total_points
            [111, 11, 1, 50, '3.150', '0.5'],
            [112, 11, 2, 60, '4.350', '-0.5'],
            [113, 11, 1, 60, '2.125', '0.125'],
            [221, 22, 1, 60, '3.555', '0.125'],
            [331, 33, 1, 60, '3.250', '0.125'],
            [332, 33, 2, 60, '4.650', '-0.5'],
            [441, 44, 1, 50, '3.125', '1.25'],
            [551, 55, 1, 50, '0.125', '0.125'],
            [661, 66, 1, 60, '3.705', '0.5'],
            [771, 77, 2, 60, '1.705', '0.25'],
            [772, 77, 2, 60, '2.705', '1.25'],
            [881, 88, 1, 60, '3.000', '0.5'],
            [882, 88, 1, 60, '2.005', '0.25'],
            [883, 88, 1, 60, '1.005', '-0.25'],
        ]
        ADJUSTMENTS = [
            # rule_id, product_id, affect_rate_type, adj_value, min_loan_amt, max_loan_amt
            # prop_type, minfico, maxfico, minltv, maxltv, state
            [1, 11, 'P', '-0.35', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [2, 11, 'P', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [3, 11, 'R', '0.15', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [4, 22, 'R', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'VA'],
            [5, 22, 'R', '0.15', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [6, 33, 'R', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [7, 77, 'P', '0.125', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'VA'],
        ]
        NOW = timezone.now()

        for region in REGIONS:
            reg = Region(region_id=region[0], state_id=region[1], data_timestamp=NOW)
            reg.save()

        for p in PRODUCTS:
            product = Product(
                plan_id=p[0], institution=p[1], loan_purpose=p[2], pmt_type=p[3],
                loan_type=p[4], loan_term=p[5], int_adj_term=p[6], adj_period=p[7], io=p[8],
                arm_index=p[9], int_adj_cap=p[10], annual_cap=p[11], loan_cap=p[12], arm_margin=p[13],
                ai_value=p[14], min_ltv=p[15], max_ltv=p[16], min_fico=p[17], max_fico=p[18],
                min_loan_amt=p[19], max_loan_amt=p[20], single_family=p[21], condo=p[22],
                coop=p[23], data_timestamp=NOW
            )
            product.save()

        for r in RATES:
            rate = Rate(
                rate_id=r[0], product_id=r[1], region_id=r[2], lock=r[3], base_rate=r[4],
                total_points=r[5], data_timestamp=NOW
            )
            rate.save()

        for a in ADJUSTMENTS:
            adjustment = Adjustment(
                rule_id=a[0], product_id=a[1], affect_rate_type=a[2],
                adj_value=a[3], min_loan_amt=a[4], max_loan_amt=a[5], prop_type=a[6],
                min_fico=a[7], max_fico=a[8], min_ltv=a[9], max_ltv=a[10], state=a[11],
                data_timestamp=NOW
            )
            adjustment.save()
Esempio n. 8
0
 def create_product(self, row):
     """ Helper function to save a product."""
     p = Product()
     p.plan_id = int(row[0])
     p.institution = row[1]
     p.loan_purpose = row[2]
     p.pmt_type = row[3]
     p.loan_type = row[4]
     p.loan_term = int(row[5])
     p.int_adj_term = self.c.nullable_int(row[6])
     p.adj_period = self.c.nullable_int(row[7])
     p.io = self.c.string_to_boolean(row[8])
     p.arm_index = self.c.nullable_string(row[9])
     p.int_adj_cap = self.c.nullable_int(row[10])
     p.annual_cap = self.c.nullable_int(row[11])
     p.loan_cap = self.c.nullable_int(row[12])
     p.arm_margin = self.c.nullable_decimal(row[13])
     p.ai_value = self.c.nullable_decimal(row[14])
     p.min_ltv = Decimal(row[15]).quantize(Decimal('.001'))
     p.max_ltv = Decimal(row[16]).quantize(Decimal('.001'))
     p.min_fico = int(row[17])
     p.max_fico = int(row[18])
     p.min_loan_amt = Decimal(row[19])
     p.max_loan_amt = Decimal(row[20])
     p.data_timestamp = datetime.strptime('20140101', '%Y%m%d')
     p.save()
     return p
    def setUp(self):
        REGIONS = [[1, 'DC'], [2, 'VA'], [3, 'MD']]
        PRODUCTS = [
            # plan_id, institution, loan_purpose, pmt_type, loan_type, loan_term, int_adj_term, _, io, _, _, _, _, _, _,
            # min_ltv, max_ltv, minfico, maxfico, min_loan_amt, max_loan_amt, single_family, condo, coop
            [11, 'Institution 1', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 95, 680, 700, 90000, 750000, 1, 0, 0],
            [22, 'Institution 2', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [33, 'Institution 3', 'PURCH', 'ARM', 'CONF', 15, 5, None, 0, None, None, None, None, None, None, 1, 95, 680, 740, 90000, 550000, 1, 0, 0],
            [44, 'Institution 4', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [55, 'Institution 5', 'PURCH', 'ARM', 'CONF', 30, 5, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [66, 'Institution 6', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [77, 'Institution 7', 'PURCH', 'FIXED', 'FHA-HB', 15, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [88, 'Institution 8', 'PURCH', 'FIXED', 'FHA', 30, None, None, 0, None, None, None, None, None, None, 1, 87, 680, 740, 90000, 550000, 1, 0, 0],
            [98, 'Institution 8', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 95, 680, 740, 90000, 550000, 1, 1, 0],
            [99, 'Institution 8', 'PURCH', 'FIXED', 'CONF', 30, None, None, 0, None, None, None, None, None, None, 1, 90, 680, 740, 90000, 550000, 1, 1, 0],
        ]
        RATES = [
            # rate_id, product_id, region_id, lock, base_rate, total_points
            [111, 11, 1, 50, '3.150', '0.5'],
            [112, 11, 2, 60, '4.350', '-0.5'],
            [113, 11, 1, 60, '2.125', '0.125'],
            [221, 22, 1, 60, '3.555', '0.125'],
            [331, 33, 1, 60, '3.250', '0.125'],
            [332, 33, 2, 60, '4.650', '-0.5'],
            [441, 44, 1, 50, '3.125', '1.25'],
            [551, 55, 1, 50, '0.125', '0.125'],
            [661, 66, 1, 60, '3.705', '0.5'],
            [771, 77, 2, 60, '1.705', '0.25'],
            [772, 77, 2, 60, '2.705', '1.25'],
            [881, 88, 1, 60, '3.000', '0.5'],
            [882, 88, 1, 60, '2.005', '0.25'],
            [883, 88, 1, 60, '1.005', '-0.25'],
            [884, 98, 3, 60, '3.000', '0.5'],
            [885, 98, 3, 60, '2.985', '0'],
            [886, 98, 3, 60, '1.985', '-0.25'],
            [887, 99, 3, 60, '3.000', '0.5'],
            [888, 99, 3, 60, '2.995', '0'],
            [889, 99, 3, 60, '1.995', '-0.25'],
        ]
        ADJUSTMENTS = [
            # rule_id, product_id, affect_rate_type, adj_value, min_loan_amt, max_loan_amt
            # prop_type, minfico, maxfico, minltv, maxltv, state
            [1, 11, 'P', '-0.35', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [2, 11, 'P', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [3, 11, 'R', '0.15', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [4, 22, 'R', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'VA'],
            [5, 22, 'R', '0.15', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [6, 33, 'R', '0.25', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'DC'],
            [7, 77, 'P', '0.125', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'VA'],
            [8, 98, 'P', '0.125', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'MD'],
            [9, 99, 'P', '0.125', 100000, 500000, 'CONDO', 660, 780, 30, 95, 'MD'],
        ]
        FEES = [
            # plan_id, product_id, state_id, lender , single_family, condo, coop,
            # origination_dollar, origination_percent, third_party
            [11, 88, 'DC', 'Institution 8', 1, 1, 1, 1608.0000, .000, 587.2700],
            [11, 88, 'DC', 'Institution 8', 1, 0, 1, 1612.0000, .000, 591.2700],
            [10, 88, 'DC', 'Institution 8', 0, 1, 0, 1610.0000, .000, 589.2700],
            [11, 87, 'VA', 'Institution 7', 1, 1, 1, 1610.0000, .000, 589.2700],
        ]
        self.NOW = timezone.now()
        NOW = self.NOW

        for region in REGIONS:
            reg = Region(region_id=region[0], state_id=region[1], data_timestamp=NOW)
            reg.save()

        for p in PRODUCTS:
            product = Product(
                plan_id=p[0], institution=p[1], loan_purpose=p[2], pmt_type=p[3],
                loan_type=p[4], loan_term=p[5], int_adj_term=p[6], adj_period=p[7], io=p[8],
                arm_index=p[9], int_adj_cap=p[10], annual_cap=p[11], loan_cap=p[12], arm_margin=p[13],
                ai_value=p[14], min_ltv=p[15], max_ltv=p[16], min_fico=p[17], max_fico=p[18],
                min_loan_amt=p[19], max_loan_amt=p[20], single_family=p[21], condo=p[22],
                coop=p[23], data_timestamp=NOW
            )
            product.save()

        for r in RATES:
            rate = Rate(
                rate_id=r[0], product_id=r[1], region_id=r[2], lock=r[3], base_rate=r[4],
                total_points=r[5], data_timestamp=NOW
            )
            rate.save()

        for a in ADJUSTMENTS:
            adjustment = Adjustment(
                rule_id=a[0], product_id=a[1], affect_rate_type=a[2],
                adj_value=a[3], min_loan_amt=a[4], max_loan_amt=a[5], prop_type=a[6],
                min_fico=a[7], max_fico=a[8], min_ltv=a[9], max_ltv=a[10], state=a[11],
                data_timestamp=NOW
            )
            adjustment.save()

        for f in FEES:
            fee = Fee(
                plan_id=f[0], product_id=f[1], state_id=f[2], lender=f[3], single_family=f[4],
                condo=f[5], coop=f[6], origination_dollar=Decimal("%s" % f[7]),
                origination_percent=Decimal("%s" % f[8]), third_party=Decimal("%s" % f[9]),
                data_timestamp=NOW
            )
            fee.save()