Exemple #1
0
def test_to_generics_two_generics_key_error():
    wts1 = pd.DataFrame([[0.5, 0], [0.5, 0.5], [0, 0.5]],
                        index=['CLX16', 'CLZ16', 'CLF17'],
                        columns=[0, 1])
    # COZ16 is mistyped as CLO16 resulting in no weights for the instrument
    # COZ16
    wts2 = pd.DataFrame([[0.5, 0], [0.5, 0.5], [0, 0.5]],
                        index=['COX16', 'CLO16', 'COF17'],
                        columns=[0, 1])
    wts = {"CL": wts1, "CO": wts2}
    instrs = pd.Series(
        [10, 20, 10, 10, 20, 10],
        index=["CLX16", "CLZ16", "CLF17", "COX16", "COZ16", "COF17"])
    with pytest.raises(KeyError):
        mappings.to_generics(instrs, wts)
Exemple #2
0
def test_to_generics_two_generics_minimize_error_integer_soln():
    wts = pd.DataFrame([[0.5, 0], [0.5, 0.5], [0, 0.5]],
                       index=['CLX16', 'CLZ16', 'CLF17'],
                       columns=[0, 1])
    instrs = pd.Series([10, 25, 11], index=["CLX16", "CLZ16", "CLF17"])
    generics = mappings.to_generics(instrs, wts)
    exp_generics = pd.Series([22.0, 24.0], index=[0, 1])
    assert_series_equal(generics, exp_generics)
Exemple #3
0
def test_to_generics_two_generics_zero_generics_weight():
    # scenario where one generic has 0 weight, tests for bug where result
    # has epsilon weight on CL1
    wts = pd.DataFrame([[0, 1]], index=["CLZ16"], columns=["CL1", "CL2"])
    notional = pd.Series([-13900.0], index=["CLZ16"])
    generics = mappings.to_generics(notional, wts)
    exp_generics = pd.Series([-13900.0], index=["CL2"])
    assert_series_equal(generics, exp_generics)
Exemple #4
0
def test_to_generics_two_generics_exact_soln_negative():
    wts = pd.DataFrame([[0.5, 0], [0.5, 0.5], [0, 0.5]],
                       index=['CLX16', 'CLZ16', 'CLF17'],
                       columns=[0, 1])
    instrs = pd.Series([10, 0, -10], index=["CLX16", "CLZ16", "CLF17"])
    generics = mappings.to_generics(instrs, wts)
    exp_generics = pd.Series([20.0, -20.0], index=[0, 1])
    assert_series_equal(generics, exp_generics)
Exemple #5
0
def test_to_generics_three_generics_non_exact_soln():
    wts = pd.DataFrame(
        [[0.5, 0, 0], [0.5, 0.5, 0], [0, 0.5, 0.5], [0, 0, 0.5]],
        index=['CLX16', 'CLZ16', 'CLF17', 'CLG17'],
        columns=[0, 1, 2])
    instrs = pd.Series([10, 21, 20, 13],
                       index=["CLX16", "CLZ16", "CLF17", "CLG17"])
    generics = mappings.to_generics(instrs, wts)
    exp_generics = pd.Series([22.0, 18.0, 24.0], index=[0, 1, 2])
    assert_series_equal(generics, exp_generics)
Exemple #6
0
def test_to_generics_two_generics_multi_asset():
    wts1 = pd.DataFrame([[0.5, 0], [0.5, 0.5], [0, 0.5]],
                        index=['CLX16', 'CLZ16', 'CLF17'],
                        columns=["CL0", "CL1"])
    wts2 = pd.DataFrame([[0.5, 0], [0.5, 0.5], [0, 0.5]],
                        index=['COX16', 'COZ16', 'COF17'],
                        columns=["CO0", "CO1"])
    wts = {"CL": wts1, "CO": wts2}
    instrs = pd.Series(
        [10, 20, 10, 10, 20, 10],
        index=["CLX16", "CLZ16", "CLF17", "COX16", "COZ16", "COF17"])
    generics = mappings.to_generics(instrs, wts)
    exp_generics = pd.Series([20.0, 20.0, 20.0, 20.0],
                             index=["CL0", "CL1", "CO0", "CO1"])
    assert_series_equal(generics, exp_generics)