How to use the xalpha.fundinfo 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_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
github refraction-ray / xalpha / tests / test_info.py View on Github external
import sys

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

ioconf = {"save": True, "fetch": True, "path": "pytest", "form": "csv"}
ca = xa.cashinfo(interest=0.0002, start="2015-01-01")
zzhb = xa.indexinfo("0000827", **ioconf)
hs300 = xa.fundinfo("000311")
zogqb = xa.mfundinfo("001211", **ioconf)


def test_fundreport():
    # somehow fragile, to be checked
    r = xa.FundReport("000827")
    assert r.get_report()[0][:2] == "广发"
    assert r.analyse_report(1)["bank"][:2] == "兴业"
    assert r.show_report_list(type_=0)[0]["FUNDCODE"] == "000827"
    assert r.get_report(id_="AN202003171376532533")[0][:2] == "广发"


def test_cash():
    assert (
        round(ca.price[ca.price["date"] == "2018-01-02"].iloc[0].netvalue, 4) == 1.2453
    )
github refraction-ray / xalpha / tests / test_info.py View on Github external
)
    assert str(excinfo.value) == "One cannot move share before the lastest operation"
    assert (
        hs300.shuhui(
            320,
            "2018-01-01",
            [[pd.Timestamp("2011-01-03"), 200], [pd.Timestamp("2017-12-29"), 200]],
        )[1]
        == 685.72
    )
    assert hs300.shengou(200, "2018-07-20")[2] == 105.24
    with pytest.raises(FundTypeError) as excinfo:
        xa.mfundinfo("000311")
    assert str(excinfo.value) == "This code seems to be a fund, use fundinfo instead"
    hs300.info()
    dax = xa.fundinfo("510030")  # test empty shuhuifei and shengoufei case
    assert dax.feeinfo == ["小于7天", "1.50%", "大于等于7天", "0.00%"]
github refraction-ray / xalpha / tests / test_info.py View on Github external
def test_csvio():
    hs300 = xa.fundinfo("000311", **ioconf)
    len1 = len(hs300.price)
    hs300 = xa.fundinfo("000311", **ioconf)
    len2 = len(hs300.price)
    delete_csvlines(path=ioconf["path"] + "000311.csv")
    hs300 = xa.fundinfo("000311", **ioconf)
    len3 = len(hs300.price)
    assert (len1 == len2) or (len1 - len2 == -1)  # temp fixup
    # there may be time lag for update of .js API, i.e. 天天基金的该 API 不一定能保证更新昨天的净值,即使不是 QDII
    assert (len1 == len3) or (len1 - len3 == -1)
    delete_csvlines(path=ioconf["path"] + "001211.csv")
    zogqb2 = xa.mfundinfo("001211", **ioconf)
    assert round(zogqb.price.iloc[-1].netvalue, 5) in [
        round(zogqb2.price.iloc[-1].netvalue, 5),
        round(zogqb2.price.iloc[-2].netvalue, 5),
    ]
    delete_csvlines(path=ioconf["path"] + "0000827.csv")
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
import sys

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


path = "demo.csv"
path1 = "demo1.csv"
path2 = "demo2.csv"
cm = xa.fundinfo("164818")
statb = xa.record(path).status
statl = xa.record(path1, format="list").status
statnb = xa.record(path2)
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")
github refraction-ray / xalpha / tests / test_info.py View on Github external
def test_mfundinfo():
    zogqb.bcmkset(xa.cashinfo())
    assert round(zogqb.total_annualized_returns("2018-08-01"), 3) == 0.036
    with pytest.raises(FundTypeError) as excinfo:
        xa.fundinfo("001211")
    assert str(excinfo.value) == "This code seems to be a mfund, use mfundinfo instead"
github refraction-ray / xalpha / tests / test_info.py View on Github external
def test_csvio():
    hs300 = xa.fundinfo("000311", **ioconf)
    len1 = len(hs300.price)
    hs300 = xa.fundinfo("000311", **ioconf)
    len2 = len(hs300.price)
    delete_csvlines(path=ioconf["path"] + "000311.csv")
    hs300 = xa.fundinfo("000311", **ioconf)
    len3 = len(hs300.price)
    assert (len1 == len2) or (len1 - len2 == -1)  # temp fixup
    # there may be time lag for update of .js API, i.e. 天天基金的该 API 不一定能保证更新昨天的净值,即使不是 QDII
    assert (len1 == len3) or (len1 - len3 == -1)
    delete_csvlines(path=ioconf["path"] + "001211.csv")
    zogqb2 = xa.mfundinfo("001211", **ioconf)
    assert round(zogqb.price.iloc[-1].netvalue, 5) in [
        round(zogqb2.price.iloc[-1].netvalue, 5),
        round(zogqb2.price.iloc[-2].netvalue, 5),
    ]
    delete_csvlines(path=ioconf["path"] + "0000827.csv")
    zzhb2 = xa.indexinfo("0000827", **ioconf)
    assert (len(zzhb2.price) == len(zzhb.price)) or (
github refraction-ray / xalpha / tests / test_info.py View on Github external
def test_fund_update():
    zghl = xa.fundinfo(
        "501029", **ioconf
    )  # 164906 maybe possible remainning issue for qdii?
    len1 = len(zghl.price)
    delete_csvlines(path=ioconf["path"] + "501029.csv", lines=83)
    zghl = xa.fundinfo("501029", **ioconf)
    len2 = len(zghl.price)
    assert (len1 == len2) or (len1 - len2 == -1)  # similar fix up
    jxzl = xa.mfundinfo("002758", **ioconf)
    netvalue = jxzl.price.iloc[-1]["netvalue"]
    len3 = len(jxzl.price)
    delete_csvlines(path=ioconf["path"] + "002758.csv", lines=9)
    jxzl = xa.mfundinfo("002758", **ioconf)
    netvaluel = [
        round(jxzl.price.iloc[-1]["netvalue"], 4),
        round(jxzl.price.iloc[-2]["netvalue"], 4),
    ]
    len4 = len(jxzl.price)
    assert (len3 == len4) or (len3 - len4 == -1)
    assert round(netvalue, 4) in netvaluel  ##天天基金的总量 API 更新越来越慢了。。。