def mortgage_insurance(request): """ Return the monthly and upfront mortgage insurance premiums in percentages (i.e. 1.7% returns 1.7) If no premiums were found, no data will be returned. """ if request.method == 'GET': # Clean the parameters, make sure no leading or trailing spaces, transform them to upper cases fixed_data = dict( map(lambda (k, v): (k, v.strip().upper()), request.QUERY_PARAMS.iteritems())) serializer = ParamsSerializer(data=fixed_data) if serializer.is_valid(): package = {} package['request'] = serializer.data package['data'] = {} monthly = Monthly.get_avg_premium(serializer.data) upfront = Upfront.get_premium(serializer.data) if not math.isnan(monthly): package['data']['monthly'] = monthly if not math.isnan(upfront): package['data']['upfront'] = upfront return Response(package) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def mortgage_insurance(request): """ Return the monthly and upfront mortgage insurance premiums in percentages (i.e. 1.7% returns 1.7) If no premiums were found, no data will be returned. """ if request.method == 'GET': # Clean the parameters, make sure no leading or trailing spaces, transform them to upper cases fixed_data = dict(map(lambda (k, v): (k, v.strip().upper()), request.QUERY_PARAMS.iteritems())) serializer = ParamsSerializer(data=fixed_data) if serializer.is_valid(): package = {} package['request'] = serializer.data package['data'] = {} monthly = Monthly.get_avg_premium(serializer.data) upfront = Upfront.get_premium(serializer.data) if not math.isnan(monthly): package['data']['monthly'] = monthly if not math.isnan(upfront): package['data']['upfront'] = upfront return Response(package) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def mortgage_insurance(request): """ Return the monthly and upfront mortgage insurance premiums in percentages (i.e. 1.7% returns 1.7) If no premiums were found, no data will be returned. """ if request.method == 'GET': loan_type = request.QUERY_PARAMS.get('loan_type') rate_structure = request.QUERY_PARAMS.get('rate_structure') va_status = request.QUERY_PARAMS.get('va_status') va_first_use = request.QUERY_PARAMS.get('va_first_use') arm_type = request.QUERY_PARAMS.get('arm_type') data = { 'price': request.QUERY_PARAMS.get('price'), 'loan_amount': request.QUERY_PARAMS.get('loan_amount'), 'minfico': request.QUERY_PARAMS.get('minfico'), 'maxfico': request.QUERY_PARAMS.get('maxfico'), 'loan_term': request.QUERY_PARAMS.get('loan_term'), 'loan_type': '' if loan_type is None else loan_type.strip().upper(), 'rate_structure': '' if rate_structure is None else rate_structure.strip().upper(), 'va_status': '' if va_status is None else va_status.strip().upper(), 'va_first_use': '' if va_first_use is None else va_first_use.strip().upper(), 'arm_type': '' if arm_type is None else arm_type.strip().upper(), } serializer = ParamsSerializer(data=data) if serializer.is_valid(): package = {} package['request'] = serializer.data package['data'] = {} monthly = Monthly.get_avg_premium(serializer.data) upfront = Upfront.get_premium(serializer.data) if not math.isnan(monthly): package['data']['monthly'] = monthly if not math.isnan(upfront): package['data']['upfront'] = upfront return Response(package) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def mortgage_insurance(request): """ Return the monthly and upfront mortgage insurance premiums in percentages (i.e. 1.7% returns 1.7) If no premiums were found, no data will be returned. """ if request.method == 'GET': loan_type = request.QUERY_PARAMS.get('loan_type') rate_structure = request.QUERY_PARAMS.get('rate_structure') va_status = request.QUERY_PARAMS.get('va_status') va_first_use = request.QUERY_PARAMS.get('va_first_use') arm_type = request.QUERY_PARAMS.get('arm_type') data = { 'price' : request.QUERY_PARAMS.get('price'), 'loan_amount' : request.QUERY_PARAMS.get('loan_amount'), 'minfico' : request.QUERY_PARAMS.get('minfico'), 'maxfico' : request.QUERY_PARAMS.get('maxfico'), 'loan_term' : request.QUERY_PARAMS.get('loan_term'), 'loan_type' : '' if loan_type is None else loan_type.strip().upper(), 'rate_structure' : '' if rate_structure is None else rate_structure.strip().upper(), 'va_status' : '' if va_status is None else va_status.strip().upper(), 'va_first_use' : '' if va_first_use is None else va_first_use.strip().upper(), 'arm_type' : '' if arm_type is None else arm_type.strip().upper(), } serializer = ParamsSerializer(data=data) if serializer.is_valid(): package = {} package['request'] = serializer.data package['data'] = {} monthly = Monthly.get_avg_premium(serializer.data) upfront = Upfront.get_premium(serializer.data) if not math.isnan(monthly): package['data']['monthly'] = monthly if not math.isnan(upfront): package['data']['upfront'] = upfront return Response(package) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def load_monthly(self, filename): with open(filename, 'rU') as csvfile: csvreader = csv.reader(csvfile, delimiter=',', quotechar='"') # Delete all items in tables Monthly.objects.all().delete() # Remove the first line which is the header line csvreader.next() for row in csvreader: insurer, min_ltv, max_ltv, min_fico, max_fico, loan_term, pmt_type, min_loan_amt, max_loan_amt, premium = row m = Monthly() m.insurer = insurer.strip().upper() m.min_ltv = Decimal(min_ltv) m.max_ltv = Decimal(max_ltv) m.min_fico = int(min_fico) m.max_fico = int(max_fico) m.loan_term = int(loan_term) m.pmt_type = pmt_type.strip().upper() m.min_loan_amt = Decimal(min_loan_amt) m.max_loan_amt = Decimal(max_loan_amt) m.premium = Decimal(premium) m.save() self.stdout.write('\nSuccessfully loaded data from %s\n\n' % filename)
def populate_db(self): """ Prepopulate DB with dummy data. """ m_ins1_1 = Monthly(insurer='INS1', min_ltv=Decimal("30.001"), max_ltv=Decimal("70"), min_fico=700, max_fico=740, loan_term=30, pmt_type='FIXED', min_loan_amt=Decimal("400000"), max_loan_amt=Decimal("1000000"), premium=Decimal("1.4")) m_ins1_1.save() m_ins2_1 = Monthly(insurer='INS2', min_ltv=Decimal("30.001"), max_ltv=Decimal("70"), min_fico=700, max_fico=740, loan_term=30, pmt_type='FIXED', min_loan_amt=Decimal("400000"), max_loan_amt=Decimal("1000000"), premium=Decimal("1.6")) m_ins2_1.save() m_ins1_2 = Monthly(insurer='INS1', min_ltv=Decimal("20.001"), max_ltv=Decimal("30"), min_fico=700, max_fico=740, loan_term=30, pmt_type='FIXED', min_loan_amt=Decimal("400000"), max_loan_amt=Decimal("1000000"), premium=Decimal("0.523")) m_ins1_2.save() m_ins2_2 = Monthly(insurer='INS2', min_ltv=Decimal("20.001"), max_ltv=Decimal("30"), min_fico=700, max_fico=740, loan_term=30, pmt_type='FIXED', min_loan_amt=Decimal("400000"), max_loan_amt=Decimal("1000000"), premium=Decimal("0.642")) m_ins2_2.save() m_fha = Monthly(insurer='FHA', min_ltv=Decimal("20.001"), max_ltv=Decimal("70"), min_fico=700, max_fico=740, loan_term=30, pmt_type='FIXED', min_loan_amt=Decimal("400000"), max_loan_amt=Decimal("1000000"), premium=Decimal("0.85")) m_fha.save() u_fha = Upfront(loan_type='FHA', min_ltv=Decimal("0"), max_ltv=Decimal("80"), premium=Decimal("3.75")) u_fha.save() u_va_disabled = Upfront(loan_type='VA', va_status='DISABLED', min_ltv=Decimal("0"), max_ltv=Decimal("80"), premium=Decimal("1.5")) u_va_disabled.save() u_va_regular_y = Upfront(loan_type='VA', va_status='REGULAR', va_first_use='Y', min_ltv=Decimal("0"), max_ltv=Decimal("80"), premium=Decimal("2.0")) u_va_regular_y.save()
def populate_db(self): """ Prepopulate DB with dummy data. """ m_ins1_1 = Monthly(insurer='INS1',min_ltv=Decimal("30.001"),max_ltv=Decimal("70"),min_fico=700,max_fico=740,loan_term=30,pmt_type='FIXED',min_loan_amt=Decimal("400000"),max_loan_amt=Decimal("1000000"),premium=Decimal("1.4")) m_ins1_1.save() m_ins2_1 = Monthly(insurer='INS2',min_ltv=Decimal("30.001"),max_ltv=Decimal("70"),min_fico=700,max_fico=740,loan_term=30,pmt_type='FIXED',min_loan_amt=Decimal("400000"),max_loan_amt=Decimal("1000000"),premium=Decimal("1.6")) m_ins2_1.save() m_ins1_2 = Monthly(insurer='INS1',min_ltv=Decimal("20.001"),max_ltv=Decimal("30"),min_fico=700,max_fico=740,loan_term=30,pmt_type='FIXED',min_loan_amt=Decimal("400000"),max_loan_amt=Decimal("1000000"),premium=Decimal("0.523")) m_ins1_2.save() m_ins2_2 = Monthly(insurer='INS2',min_ltv=Decimal("20.001"),max_ltv=Decimal("30"),min_fico=700,max_fico=740,loan_term=30,pmt_type='FIXED',min_loan_amt=Decimal("400000"),max_loan_amt=Decimal("1000000"),premium=Decimal("0.642")) m_ins2_2.save() m_fha = Monthly(insurer='FHA',min_ltv=Decimal("20.001"),max_ltv=Decimal("70"),min_fico=700,max_fico=740,loan_term=30,pmt_type='FIXED',min_loan_amt=Decimal("400000"),max_loan_amt=Decimal("1000000"),premium=Decimal("0.85")) m_fha.save() u_fha = Upfront(loan_type='FHA',min_ltv=Decimal("0"), max_ltv=Decimal("80"),premium=Decimal("3.75")) u_fha.save() u_va_disabled = Upfront(loan_type='VA',va_status='DISABLED',min_ltv=Decimal("0"), max_ltv=Decimal("80"),premium=Decimal("1.5")) u_va_disabled.save() u_va_regular_y = Upfront(loan_type='VA',va_status='REGULAR',va_first_use='Y',min_ltv=Decimal("0"),max_ltv=Decimal("80"),premium=Decimal("2.0")) u_va_regular_y.save()