Example #1
0
def test_customize_fee():
    df = pd.DataFrame({
        "date": ["2020-05-28", "2020-06-01"],
        "519732": [500.005, -0.505]
    })
    df["date"] = pd.to_datetime(df["date"])
    dqzf = xa.trade(xa.fundinfo("519732"), df)
    assert dqzf.dailyreport("2020-06-02")["基金分红与赎回"].iloc[0] == 2.22
    assert dqzf.dailyreport("2020-05-31")["持有份额"].iloc[0] == 116.5
    # issue 59
    df = pd.DataFrame({
        "date": ["2020-05-28", "2020-06-01"],
        "519732": [10000.005, -0.505]
    })
    df["date"] = pd.to_datetime(df["date"])
    dqzf = xa.trade(xa.fundinfo("519732"), df)
    assert round(dqzf.dailyreport("2020-05-28").iloc[0]["基金现值"], 0) == 10000.0
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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)])
Example #6
0
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()
Example #7
0
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
Example #8
0
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)],
    )
Example #9
0
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
Example #10
0
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
Example #11
0
import sys

sys.path.insert(0, "../")
import xalpha as xa
import pytest
import pandas as pd

path = "demo.csv"
path1 = "demo1.csv"
cm = xa.fundinfo("164818")
statb = xa.record(path).status
statl = xa.record(path1, format="list").status
cm_t = xa.trade(cm, statb)
ioconf = {"save": True, "fetch": True, "path": "pytest", "form": "csv"}


def test_trade():
    assert cm_t.cftable.loc[2, "share"] == -129.14
    assert round(cm_t.xirrrate("2018-03-03"), 3) == -0.24
    assert cm_t.dailyreport("2018-07-29").iloc[0]["单位成本"] == 1.346
    cm_t.v_tradecost("2018-08-01")
    cm_t.v_totvalue("2018-07-31")
    cm_t.v_tradevolume(freq="M")


def test_mul():
    with pytest.raises(Exception) as excinfo:
        cm_m = xa.mulfix(cm_t, totmoney=200)
    assert str(excinfo.value) == "You cannot sell first when you never buy"
    with pytest.raises(Exception) as excinfo:
        cm_m = xa.mulfix(cm_t, totmoney=300)
Example #12
0
cm = xa.fundinfo("164818")
cm.rate = 0.0
# 工银传媒分级转型后,天天基金显示的申购费率变化为1.0,无折扣,之前的测试数据似乎基于免申购费, 赎回费率信息也发生了变化
feeinfo = [
    "小于7天",
    "1.50%",
    "大于等于7天,小于1年",
    "0.70%",
    "大于等于1年,小于2年",
    "0.25%",
    "大于等于2年",
    "0.00%",
]  # 老赎回信息
cm.set_feeinfo(feeinfo)
cm_t = xa.trade(cm, orc.status)


def test_irecord():
    assert len(ir.filter("SH501018")) == 8


def test_itrade():
    t = xa.itrade("SH512880", ir)
    assert round(t.xirrrate("20200313"), 2) == 12.49
    assert t.dailyreport().iloc[0]["基金名称"] == "证券ETF"


def test_imul():
    c = xa.imul(status=ir)
    assert round(c.combsummary("20200309").iloc[0]["投资收益率"], 2) == -1.39