Exemplo n.º 1
0
def get_impact_data():
    # noinspection PyBroadException
    try:
        payload = request.get_json()
        payments = payload['payment']
        lump_sum = payload['lumpsum']
    except:
        payments = 800
        lump_sum = 200

    # Calculate impact on all the debt vehicles and send to FRONT END
    impact_dict = dict()
    average_weighted_rate, principal = weighted_interest_sum()
    debt_table = walk_forward_projection(principal=principal, annual_rate=average_weighted_rate, months=60)

    print('principal: {}'.format(principal))
    print('interest: {}'.format(average_weighted_rate))
    print('$ {}'.format(round(debt_table['payment'].ix[1], 2)))
    time_saved, money_saved = impact_calculator_total(
        present_value=principal,
        annual_rate=average_weighted_rate,
        payments=round(debt_table['payment'].ix[1], 2),
        lump_sum=lump_sum
    )

    impact_dict['time_saved'] = time_saved
    impact_dict['money_saved'] = money_saved

    response_object = {
        'impacts': impact_dict
    }

    print(response_object)
    return response_object
Exemplo n.º 2
0
def get_debt_projection():
    # Get Post body if it exists
    average_weighted_rate, principal = weighted_interest_sum()

    # TODO Test this SHIT
    # F**k off prospector this is a f*****g hackathon!
    # noinspection PyBroadException
    try:
        payload = request.get_json()
        payment = payload['payment']
        projection_data = walk_forward_projection(principal=principal, annual_rate=average_weighted_rate, payment=payment)
    except:
        projection_data = walk_forward_projection(principal=principal, annual_rate=average_weighted_rate, months=60)

    balance_list = projection_data['balance'].as_matrix().tolist()
    balance_dictionaries = []

    for i in range(len(balance_list)):
        balance_dictionaries.append(Balance(week=i, balance=balance_list[i]))

    response_object = {
        'projection': balance_dictionaries,
        'term': len(projection_data) - 1,
        'payment': round(projection_data['payment'].ix[1], 2),
        'principal_segment': round(projection_data['principal_segment'].ix[1], 2),
        'interest_segment': round(projection_data['interest_segment'].ix[1], 2),
        'interest expense': {
            'daily': average_weighted_rate * principal / 365.25,
            'weekly': average_weighted_rate * principal / 52,
            'monthly': average_weighted_rate * principal / 12,
            'yearly': average_weighted_rate * principal
        }
    }

    print(response_object)
    return response_object