def test_fd_read_read_assets_div_payout(db_controller):
    dfT = pd.DataFrame([
        {
            "AssetTicker": "RCK",
            "PDate": pd.Timestamp(day=2, month=1, year=2020),
            "Payout": dec.Decimal("12.5"),
        },
        {
            "AssetTicker": "RCK",
            "PDate": pd.Timestamp(day=1, month=1, year=2020),
            "Payout": dec.Decimal("11.5"),
        },
        {
            "AssetTicker": "BRY",
            "PDate": pd.Timestamp(day=12, month=12, year=2020),
            "Payout": dec.Decimal("13.13"),
        },
    ])
    dfT.set_index(["AssetTicker", "PDate"], inplace=True)
    dfR = db_controller["seeded"].read.read_assets_div_payout(["RCK", "BRY"])
    helpers.compare_df(dfT, dfR)
    # test empty
    empty_df = pd.DataFrame(columns=["AssetTicker", "Payout", "PDate"])
    empty_df.set_index(["AssetTicker", "PDate"], inplace=True)
    helpers.compare_df(empty_df,
                       db_controller["seeded"].read.read_assets_div_payout([]))
Esempio n. 2
0
def test_delete_div(db_controller):
    """
    Test if deletediv method works
    """
    dfT = pd.DataFrame([
        {
            "AssetTicker": "RCK",
            "PDate": dt.date(day=2, month=1, year=2020),
            "Payout": dec.Decimal("12.5"),
        },
        {
            "AssetTicker": "RCK",
            "PDate": dt.date(day=1, month=1, year=2020),
            "Payout": dec.Decimal("11.5"),
        },
        {
            "AssetTicker": "BRY",
            "PDate": dt.date(day=12, month=12, year=2020),
            "Payout": dec.Decimal("13.13"),
        },
    ])
    dfT.set_index(["AssetTicker", "PDate"], inplace=True)
    db_controller["seeded"].remove.delete_div_payouts("GLU")
    dfR = db_controller["seeded"].read.read_assets_div_payout(
        ["RCK", "BRY", "GLU"])
    helpers.compare_df(dfT, dfR)
Esempio n. 3
0
def test_delete_values(db_controller):

    dfT = pd.DataFrame([
        {
            "AssetTicker": "RCK",
            "ADate": dt.date(day=2, month=1, year=2020),
            "ALow": dec.Decimal("1.2"),
            "AHigh": dec.Decimal("1.2"),
            "AOpen": dec.Decimal("1.2"),
            "AClose": dec.Decimal("1.2"),
            "IsInterpolated": 1,
        },
        {
            "AssetTicker": "GLU",
            "ADate": dt.date(day=3, month=1, year=2020),
            "ALow": dec.Decimal("5.3"),
            "AHigh": dec.Decimal("5.3"),
            "AOpen": dec.Decimal("5.3"),
            "AClose": dec.Decimal("5.3"),
            "IsInterpolated": 0,
        },
    ])
    dfT.set_index(["AssetTicker", "ADate"], inplace=True)

    db_controller["seeded"].remove.deleteValues("BRY", "2020-01-02")
    db_controller["seeded"].remove.deleteValues("RCK", "2020-01-01")
    dfR = db_controller["seeded"].read.read_asset_values(
        ["RCK", "GLU", "BRY"],
        dt.date(day=1, month=1, year=2020),
        dt.date(day=3, month=1, year=2020),
    )
    helpers.compare_df(dfT, dfR)
Esempio n. 4
0
def test_delete_assetclass(db_controller):
    """
    Test if deleteAssetclass method works
    """
    dfT = pd.DataFrame([{
        "AssetClassName": "PETROLIUM DERIVATIVE"
    }, {
        "AssetClassName": "EMTPTYCLASS"
    }])
    dfT.set_index("AssetClassName", inplace=True)
    db_controller["seeded"].remove.deleteAssetClasses("CRYPTO")
    dfR = db_controller["seeded"].read.read_asset_classes()
    helpers.compare_df(dfT, dfR)
def test_fd_read_read_asset_classes(db_controller):
    dfT = pd.DataFrame([
        {
            "AssetClassName": "CRYPTO"
        },
        {
            "AssetClassName": "PETROLIUM DERIVATIVE"
        },
        {
            "AssetClassName": "EMTPTYCLASS"
        },
    ])
    dfT.set_index("AssetClassName", inplace=True)
    dfR = db_controller["seeded"].read.read_asset_classes()
    helpers.compare_df(dfT, dfR)
Esempio n. 6
0
def test_delete_assets(db_controller):
    """
    Test if deleteAsset method works
    """
    dfT = pd.DataFrame([
        {
            "AssetClassName": "CRYPTO",
            "AssetTicker": "RCK",
            "Name": "Rock"
        },
        {
            "AssetClassName": "CRYPTO",
            "AssetTicker": "BRY",
            "Name": "Berry"
        },
    ])
    dfT.set_index("AssetTicker", inplace=True)
    db_controller["seeded"].remove.deleteAssets("GLU")
    dfR = db_controller["seeded"].read.read_assets()
    helpers.compare_df(dfT, dfR)
def test_fd_read_read_assets_in_class(db_controller):
    dfT = pd.DataFrame([
        {
            "AssetClassName": "CRYPTO",
            "AssetTicker": "RCK",
            "Name": "Rock"
        },
        {
            "AssetClassName": "CRYPTO",
            "AssetTicker": "BRY",
            "Name": "Berry"
        },
    ])
    dfT.set_index("AssetTicker", inplace=True)
    dfR = db_controller["seeded"].read.read_assets_in_class("CRYPTO")
    helpers.compare_df(dfT, dfR)
    empty_df = pd.DataFrame(columns=["AssetClassName", "Name", "AssetTicker"])
    empty_df.set_index(["AssetTicker"], inplace=True)
    # testing reading wierd asset names returns empty df
    helpers.compare_df(
        empty_df,
        db_controller["seeded"].read.read_assets_in_class("WiErAsSeT"))
def test_fd_read_read_assets(db_controller):
    # after updating functionality no longer expects assets with
    # no stored values to be returned (in this case empty asset)
    dfT = pd.DataFrame([
        {
            "AssetClassName": "CRYPTO",
            "AssetTicker": "RCK",
            "Name": "Rock"
        },
        {
            "AssetClassName": "CRYPTO",
            "AssetTicker": "BRY",
            "Name": "Berry"
        },
        {
            "AssetClassName": "PETROLIUM DERIVATIVE",
            "AssetTicker": "GLU",
            "Name": "Glue",
        },
    ])
    dfT.set_index("AssetTicker", inplace=True)
    dfR = db_controller["seeded"].read.read_assets()
    helpers.compare_df(dfT, dfR)
def test_fd_write_write_asset_classes(db_controller):
    ac = db_controller["seeded"].read.read_asset_classes()
    db_controller["empty"].write.write_asset_classes(ac)
    # test replace
    db_controller["empty"].write.write_asset_classes(ac)
    helpers.compare_df(db_controller["empty"].read.read_asset_classes(), ac)
def test_fd_read_read_asset_values(db_controller):
    dfT = pd.DataFrame([
        {
            "AssetTicker": "RCK",
            "ADate": dt.date(day=2, month=1, year=2020),
            "ALow": dec.Decimal("1.2"),
            "AHigh": dec.Decimal("1.2"),
            "AOpen": dec.Decimal("1.2"),
            "AClose": dec.Decimal("1.2"),
            "IsInterpolated": 1,
        },
        {
            "AssetTicker": "GLU",
            "ADate": dt.date(day=3, month=1, year=2020),
            "ALow": dec.Decimal("5.3"),
            "AHigh": dec.Decimal("5.3"),
            "AOpen": dec.Decimal("5.3"),
            "AClose": dec.Decimal("5.3"),
            "IsInterpolated": 0,
        },
    ])
    dfT.set_index(["AssetTicker", "ADate"], inplace=True)
    dfR = db_controller["seeded"].read.read_asset_values(
        ["RCK", "GLU"],
        dt.date(day=2, month=1, year=2020),
        dt.date(day=3, month=1, year=2020),
    )
    helpers.compare_df(dfT, dfR)
    dfT.reset_index(inplace=True)
    dfT = dfT.append(
        {
            "AssetTicker": "RCK",
            "ADate": dt.date(day=1, month=1, year=2020),
            "ALow": dec.Decimal("1.1"),
            "AOpen": dec.Decimal("1.1"),
            "AHigh": dec.Decimal("1.1"),
            "AClose": dec.Decimal("1.1"),
            "IsInterpolated": 0,
        },
        ignore_index=True,
    )
    dfT.set_index(["AssetTicker", "ADate"], inplace=True)
    # test open range
    dfR = db_controller["seeded"].read.read_asset_values(["RCK", "GLU"])
    helpers.compare_df(dfT, dfR)
    # test empty
    empty_df = pd.DataFrame(columns=[
        "ALow",
        "AOpen",
        "AHigh",
        "AClose",
        "IsInterpolated",
        "AssetTicker",
        "ADate",
    ])
    empty_df.set_index(["AssetTicker", "ADate"], inplace=True)
    helpers.compare_df(empty_df,
                       db_controller["seeded"].read.read_asset_values([]))
    # test wierd
    helpers.compare_df(
        empty_df,
        db_controller["seeded"].read.read_asset_values(["WiErDtIcKeR"]))