def account_depreciation(customer_history, row): raw_date = row['datetime'] year = metrics.encode_year(raw_date) price = row['msrp'] price = calculate_real_price(price, year, row) new_row = row.copy() new_row.msrp = price customer_history = customer_history.append(new_row, ignore_index=True) return customer_history
def uniform_decay(customer): prices = make_array() for row in customer.customer_history.iterrows(): date = metrics.encode_year(row['datetime'].values[0]) decay_length = (date - 2006)*2.7+52 for price in row['msrp'].values[0]: per_year = (price/decay_length)*12 #annual "payment" for i in np.arange(decay_length/12) prices.append(per_year) df = pd.DataFrame({'prices':prices}) return df
def lease_conversion_old(customer): """Converts car MSRP to total amount paid by a lease over an average of 36 months.""" leases = 0 for index, row in customer.customer_history.iterrows(): date = metrics.encode_year(row['datetime']) price = row['msrp'] contract = row['contract_type'] if contract == 'Lease': depreciation = (price) / 36 interest = (price) * 0.00109 monthly_pay = depreciation + interest leases += monthly_pay * 36 return leases
def lease_conversion(customer_history, row): raw_date = row['datetime'] year = metrics.encode_year(raw_date) price = row['msrp'] price = calculate_real_price(price, year, row) residual = price * ( 1 - metrics.Customer.depreciation_mapping[row['model_class']]) depreciation = price - residual total_lease = (price + residual) * money_factor * 36 + \ depreciation new_row = row.copy() new_row.msrp = total_lease customer_history = customer_history.append(new_row, ignore_index=True) return customer_history
def uniform_distribution(customer_history, row): raw_date = row['datetime'] year = metrics.encode_year(raw_date) decay_length = mercedes_coeff * ((year - 2006) * 2.7 + 52) price = row['msrp'] price = calculate_real_price(price, year, row) num_years = decay_length // 12 per_year = price / num_years # annual "payment" for i in range(int(num_years)): new_row = row.copy() dummy_year = year + i dummy_year = modify_year(raw_date, dummy_year) new_row.datetime = dummy_year new_row.msrp = per_year customer_history = customer_history.append(new_row, ignore_index=True) return customer_history