Exemplo n.º 1
0
def test_income(p_name, p_id, from_dt, to_dt, wm_api, expect):
    flags = {
        'aggregated': True,
        'all': False,
        'specific': False,
        'interval': None
    }
    income_in = calculate_income(p_name, from_dt, to_dt, **flags)[to_dt]
    # get income
    body = {
        "portfolioId": p_id,
        "period": {
            "from": str(from_dt),
            'to': str(to_dt)
        }
    }

    api_data = wm_api['portfolio'].post(json.dumps(body), url_param='.profit')
    income_out = defaultdict(int, {v[0]: v[1] for v in api_data[1]['data']})
    for asset_class in income_in:
        i_in, i_out = round(income_in[asset_class],
                            2), round(income_out[asset_class], 2)
        expect(
            i_in == i_out, 'Fail: Income: period %s-%s: %s: api %s != %s db' %
            (from_dt, to_dt, asset_class, i_out, i_in))
Exemplo n.º 2
0
def test_distributions_yield(p_name, p_id, from_dt, to_dt, tense, wm_api):
    # calculate income yield
    flags = {'income': True, 'credit': True, 'aggregated': True}
    income_in = calculate_income(p_name, from_dt, to_dt, **flags)
    current_nav = db_wealth_per_asset(p_name, RECENT_DATE)[class_name]
    y_in = calculate_yield(income_in[to_dt], current_nav)

    # get income yield
    body = {
        "portfolioId": p_id,
        "asset": {
            "id": class_id,
            "type": "AssetSubClass"
        }
    }
    api_data = wm_api['common'].post(json.dumps(body),
                                     url_param='dashboard.info')

    # check if a float number returned from BE
    y_out = api_data[tense]['diff'] * 100 if type(
        api_data[tense]['diff']) == float else 0.0
    assert round(y_out, 1) == round(
        y_in,
        1), 'Fail: Coupons yield: period %s: api %s != %s db' % (tense, y_out,
                                                                 y_in)
Exemplo n.º 3
0
def test_report_income_past_next(p_name, p_id, from_dt, to_dt, tense, wm_api):
    flags = {'interval': None}
    income_in = calculate_income(p_name, from_dt, to_dt, **flags)
    # get income
    body = {"portfolioId": p_id}

    api_data = wm_api['report'].post(json.dumps(body), url_param='.portfolio')
    income_out = api_data[tense]['value']
    assert round(income_out) == round(income_in[to_dt]), 'Fail: Income: period %s: api %s != %s db' % \
                                                         (tense, income_out, income_in[to_dt])
Exemplo n.º 4
0
def test_pi(wm_api, p_name, p_id):
    # calculate income for next 12 month
    to_ = RECENT_DATE.replace(year=RECENT_DATE.year + 1)
    pi_in = calculate_income(p_name, RECENT_DATE + timedelta(days=1), to_, aggregated=True, all=True)[to_]

    # get income
    body = {"portfolioId": p_id}
    api_data = wm_api['portfolio'].post(json.dumps(body), url_param='.wealth')
    pi_out = api_data['income']['value']
    assert round(pi_out, 2) == round(pi_in, 2), 'Fail: Projected income: api %s != %s db' % (pi_out, pi_in)
Exemplo n.º 5
0
def test_coupons_past_next(p_name, p_id, from_dt, to_dt, tense, wm_api):
    flags = {'income': True, class_name.lower(): True, 'aggregated': True, 'specific': True}
    income_in = calculate_income(p_name, from_dt, to_dt, **flags)
    # get income
    body = {"portfolioId": p_id, "asset": {"id": class_id, "type": "AssetClass"}}

    api_data = wm_api['common'].post(json.dumps(body), url_param='dashboard.info')
    income_out = api_data[tense]['value']
    assert round(income_out) == round(income_in[to_dt]), 'Fail: Income: period %s: api %s != %s db' % \
                                                         (tense, income_out, income_in[to_dt])
Exemplo n.º 6
0
def test_pi_yield(wm_api, p_name, p_id):
    # calculate income for next 12 month
    to_ = RECENT_DATE.replace(year=RECENT_DATE.year + 1)
    pi_in = calculate_income(p_name, RECENT_DATE + timedelta(days=1), to_, aggregated=True, detailed=False)[to_]
    tw_in = db_total_wealth(p_name, RECENT_DATE)
    y_in = calculate_yield(pi_in, tw_in)

    # get yield
    body = {"portfolioId": p_id}
    api_data = wm_api['portfolio'].post(json.dumps(body), url_param='.wealth')
    y_out = api_data['income']['diff'] * 100
    assert round(y_out, 2) == round(y_in, 2), 'Fail: Projected income: api %s != %s db' % (100 * y_out, y_in)
Exemplo n.º 7
0
def test_report_income_yield(p_name, p_id, from_dt, to_dt, tense, wm_api):
    # calculate income yield
    flags = {'interval': None}
    nav_date = [from_dt, to_dt][tense == 'past']
    income_in = calculate_income(p_name, from_dt, to_dt, **flags)
    current_nav = calculate_nav(p_name, end_date=nav_date)
    y_in = calculate_yield(income_in[to_dt], current_nav[nav_date])

    # get income yield
    body = {"portfolioId": p_id}
    api_data = wm_api['report'].post(json.dumps(body), url_param='.portfolio')

    y_out = api_data[tense]['diff'] * 100
    assert round(y_out, 1) == round(
        y_in,
        1), 'Fail: Income yield: period %s: api %s != %s db' % (tense, y_out,
                                                                y_in)