How to use the xalpha.trade function in xalpha

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_trade.py View on Github external
def test_policy_buyandhold():
    allin = xa.policy.buyandhold(cm, "2015-06-01")
    cm_t2 = xa.trade(cm, allin.status)
    cm_m2 = xa.mulfix(cm_t2)
    cm_m2.bcmkset(xa.indexinfo("1399971"))
    assert round(cm_m2.correlation_coefficient("2018-07-01"), 3) == 0.980
    assert round(cm_m2.information_ratio("2016-07-01"), 3) == -0.385
    allin.sellout("2018-06-01")
    cm_t2 = xa.trade(cm, allin.status)
    assert round(cm_t2.xirrrate("2019-08-12", guess=-0.9), 2) == -0.33
github refraction-ray / xalpha / tests / test_trade.py View on Github external
def test_weekly_price():
    # see https://github.com/refraction-ray/xalpha/issues/27
    ryjh = xa.fundinfo("008969")
    bah = xa.policy.buyandhold(ryjh, start="2019-01-01", totmoney=100000)
    bah.sellout("2020-05-12")  # 选定日期全部卖出
    jshstrade = xa.trade(ryjh, bah.status)
    assert round(jshstrade.xirrrate("2020-05-01", startdate="2020-02-01"), 1) == 0.2
github refraction-ray / xalpha / tests / test_trade.py View on Github external
def test_policy_indicator_cross():
    cm.bbi()
    techst = xa.policy.indicator_cross(
        cm, col=["netvalue", "BBI"], start="2018-01-01", end="2018-07-07"
    )
    cm_tt = xa.trade(cm, techst.status)
    assert round(cm_tt.dailyreport("2018-07-09").iloc[0].loc["换手率"], 1) == 14.1
github refraction-ray / xalpha / tests / test_trade.py View on Github external
def test_policy_buyandhold():
    allin = xa.policy.buyandhold(cm, "2015-06-01")
    cm_t2 = xa.trade(cm, allin.status)
    cm_m2 = xa.mulfix(cm_t2)
    cm_m2.bcmkset(xa.indexinfo("1399971"))
    assert round(cm_m2.correlation_coefficient("2018-07-01"), 3) == 0.980
    assert round(cm_m2.information_ratio("2016-07-01"), 3) == -0.385
    allin.sellout("2018-06-01")
    cm_t2 = xa.trade(cm, allin.status)
    assert round(cm_t2.xirrrate("2019-08-12", guess=-0.9), 2) == -0.33
github refraction-ray / xalpha / tests / test_trade.py View on Github external
def test_policy_indicator_points():
    zz500 = xa.indexinfo("0000905")
    zz500.psy()
    st = xa.policy.indicator_points(
        zz500,
        col="PSYMA12",
        start="2017-01-01",
        buy=[(0.6, 1), (0.7, 1)],
        sell=[(0.4, 1), (0.3, 1)],
        buylow=False,
    )
    zz500_t = xa.trade(zz500, st.status)
    assert zz500_t.dailyreport("2018-05-01").iloc[0].loc["基金收益总额"] == -6302.26
github refraction-ray / xalpha / tests / test_info.py View on Github external
def test_vinfo():
    hs300 = xa.vinfo("SH000300", start="20190901")
    hs300.info()
    st = pd.DataFrame({"date": ["20200101", "20200203"], "SH000300": [200, -100]})
    st["date"] = pd.to_datetime(st["date"])
    t = xa.trade(hs300, st)
    t.dailyreport()
    assert len(t.cftable) == 2
    yy = xa.vinfo("ZZ931152")
    yy.pct_chg()
github refraction-ray / xalpha / tests / test_trade.py View on Github external
def test_policy_scheduled():
    auto = xa.policy.scheduled(
        cm, 1000, pd.date_range("2015-07-01", "2018-07-01", freq="W-THU")
    )
    cm_t3 = xa.trade(cm, auto.status)
    cm_t3.v_tradevolume(freq="W")
    assert round(cm_t3.dailyreport("2018-08-03").iloc[0]["投资收益率"], 2) == -42.07
    auto2 = xa.policy.scheduled_tune(
        cm,
        1000,
        pd.date_range("2015-07-01", "2018-07-01", freq="M"),
        [(0.9, 2), (1.2, 1)],
    )
github refraction-ray / xalpha / tests / test_trade.py View on Github external
def test_policy_grid():
    gr = xa.policy.grid(cm, [0, 2, 2], [3, 3, 3], "2018-06-23", "2018-08-03")
    tr = xa.trade(cm, gr.status)
    assert round(tr.xirrrate("2018-07-13"), 2) == 11.78