def npv_handler()

in financial_functions/lambda_handlers.py [0:0]


def npv_handler(request, context):
    """
    Net Present Value of a cash flow series
    :param request: Dict containing the parameters to pass to the formula.
    :param context: Lambda execution context
    :return: Dict with a 'result' entry containing the result of the calculation
    """
    logger.info("NPV request: {}".format(request))

    validation_result = __validate_arguments('NPV', request, schemas.npv_schema)
    if not validation_result.get('isValid'):
        return {'error': validation_result.get('error')}

    # Need to append a 0 entry to the beginning of the values list for NumPy NPV to align with Excel
    # Excel assumes the investment begins one period before the first value cash flow whereas
    # NumPy assumes they begin at the same time.
    args = [request['rate'], [0] + request['values']]
    return __call_numpy('npv', args)