How to use xalpha - 10 common examples

To help you get started, we’ve selected a few xalpha examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github refraction-ray / xalpha / tests / test_toolbox.py View on Github external
def test_qdii_predict():
    hb = xa.QDIIPredict(
        "SZ162411",
        t1dict={".SPSIOP": 91},
        t0dict={"commodities/brent-oil": 40 * 0.9, "commodities/crude-oil": 60 * 0.9,},
        positions=True,
    )
    hb.get_t1()
    hb.get_t0(percent=True)
    hb.benchmark_test("20200202", "20200302")
    hb.analyse()
github refraction-ray / xalpha / tests / test_universal.py View on Github external
def test_get_ycharts():
    # ycharts 可能有时也需要代理了。。。。
    d = xa.get_daily(code="yc-companies/DBP", start="20200401", end="20200402")
    assert d.iloc[0]["close"] == 41.04

    d = xa.get_daily(
        code="yc-companies/DBP/net_asset_value", start="20200401", end="20200402"
    )
    assert d.iloc[0]["close"] == 40.7144

    d = xa.get_daily(code="yc-indices/^SPGSCICO", start="20200401", end="20200402")
    assert d.iloc[0]["close"] == 111.312

    d = xa.get_daily(
        code="yc-indices/^SPGSCICO/total_return_forward_adjusted_price",
        start="20200401",
        end="20200402",
    )
    assert d.iloc[0]["close"] == 169.821

    assert xa.get_rt("yc-companies/DBO")["currency"] == "USD"
github refraction-ray / xalpha / tests / test_toolbox.py View on Github external
def test_set_display():
    xa.set_display("notebook")
    df = xa.get_daily("PDD", prev=30)
    df._repr_javascript_()
    xa.set_display()
    assert getattr(df, "_repre_javascript_", None) is None
github refraction-ray / xalpha / tests / test_universal.py View on Github external
def test_get_rmb():
    df = xa.get_daily(start="20180101", end="2020-03-07", code="USD/CNY")
    assert len(df) == 528
    df = xa.get_daily(code="EUR/CNY", end="20200306")
    assert round(df.iloc[-1]["close"], 4) == 7.7747
    df = xa.get_daily("CNY/EUR", end="20200306", prev=5)
    assert round(df.iloc[-1]["close"], 3) == round(1 / 7.7747, 3)
github refraction-ray / xalpha / tests / test_universal.py View on Github external
def test_cache_mm():
    df = xa.get_daily("SH501018", prev=100)
    l1 = len(df)
    # xa.set_backend(backend="memory", prefix="pytestm-")
    xa.get_daily("SH501018", prev=50)
    df = xa.get_daily("SH501018", prev=100)
    l2 = len(df)
    assert l1 == l2
    xa.universal.check_cache("SH501018", start="2018/09/01", omit_lines=1)
github refraction-ray / xalpha / tests / test_universal.py View on Github external
def test_get_zzindex():
    assert len(xa.get_daily("ZZH30533")) > 100
github refraction-ray / xalpha / tests / test_universal.py View on Github external
def test_get_sp_daily():
    df = xa.get_daily("SP5475707.2", start="20200202", end="20200303")
    assert round(df.iloc[-1]["close"], 3) == 1349.31
    df = xa.get_daily("SP5475707.2", prev=100, end="20200303")
    assert round(df.iloc[-1]["close"], 3) == 1349.31
github refraction-ray / xalpha / tests / test_universal.py View on Github external
def test_get_investing():
    df1 = xa.get_daily(code="indices/germany-30")
    df2 = xa.get_daily(code="172")
    assert (
        df1.iloc[-2]["close"] == df2.iloc[-2]["close"]
    )  ## never try -1, today's data is unpredictable
    df = xa.get_daily(code="/currencies/usd-cny", end="20200307", prev=20)
    assert round(df.iloc[-1]["close"], 4) == 6.9321
    df.v_kline()
github refraction-ray / xalpha / tests / test_universal.py View on Github external
def test_get_bb_daily(proxy):
    df = xa.get_daily("BB-FGERBIU:ID", prev=10)
github refraction-ray / xalpha / tests / test_universal.py View on Github external
def test_get_xueqiu():
    df = xa.get_daily(start="20200302", end="2020-03-07", code="HK01810")
    assert round(df.iloc[-1]["close"], 2) == 12.98
    df = xa.get_daily(start="2020/03/02", end="20200307", code="PDD")
    assert round(df.iloc[0]["close"], 2) == 37.51
    df = xa.get_daily(start="20200301", end="20200307", code="SZ112517")
    # note how this test would fail when the bond is matured
    assert round(df.iloc[0]["close"], 2) == 98
    df = xa.get_daily(start="20200222", end="20200301", code="SH501018")
    assert round(df.iloc[-1]["close"], 3) == 0.965
    df = xa.get_daily("SH600000.A", end="20200428")
    assert round(df.iloc[-1]["close"], 2) == 131.34