Example #1
0
def test_cache_mm():
    df = xa.get_daily("SH501018", prev=100)
    l1 = len(df)
    xa.set_backend(backend="memory")
    xa.get_daily("SH501018", prev=50)
    df = xa.get_daily("SH501018", prev=100)
    l2 = len(df)
    assert l1 == l2
Example #2
0
def test_iw():
    xa.set_backend(backend="csv", path="./")
    df = xa.get_daily("iw-399006.XSHE", end="20200226")
    assert (
        df[(df["date"] == "2019-04-01") & (df["code"] == "300271.XSHE")].iloc[0].weight
        == 0.9835
    )
    df = xa.universal.get_index_weight_range(
        "399006.XSHE", start="2018-01-01", end="2020-02-01"
    )
    assert (
        df[(df["date"] == "2019-04-01") & (df["code"] == "300271.XSHE")].iloc[0].weight
        == 0.9835
    )
Example #3
0
def main():
    xa.set_backend(backend="memory", precached="20200301")
    render_github(
        "SH501018",
        "SZ160216",
        "SZ162411",
        "SZ160723",
        "SZ161129",
        "SZ162719",
        "SH513030",
        "SH513500",
        "SZ161130",
        "SZ163208",
        "SZ160416",
        "SZ161125",
        "SH513100",
        "SZ165513",
        "SZ161815",
        "SZ161128",
    )
    render_github("SZ164906", "SH513050", cols="3c")
    render_github("SH513880", "SH513520", "SH513000", "SH501021", cols="3crt")
Example #4
0
"""
一个简单展示 qdii 实时净值预测的例子,最大限度的利用缓存而减少网络请求
"""

import pandas as pd
import xalpha as xa
import logging

xa.set_backend(backend="csv", path="../../../lof/data", precached="20200103")
# xa.set_proxy("socks5://127.0.0.1:1080")

logger = logging.getLogger("xalpha")
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)


@xa.universal.lru_cache_time(ttl=60)
def cached_get_rt(code, **kws):
    return xa.get_rt(code, handler=False)


@xa.universal.lru_cache_time(ttl=1800)
def cached_get_bar(code, *args, **kws):
    if code.startswith("commodities/"):
        kws["handler"] = False
        return xa.get_bar(code, *args, **kws)
    return None

Example #5
0
import sys
import pytest

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

xa.set_backend(backend="memory", prefix="pytest-")


def test_compare():
    c = xa.Compare(("37450", "USD"), "SH501018", start="20200101")
    c.corr()
    c.v()


def test_get_currency():
    assert (xa.toolbox.get_currency_code("indices/india-50-futures") ==
            "currencies/inr-cny")
    assert xa.toolbox._get_currency_code("JPY") == "100JPY/CNY"


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,
    )
Example #6
0
def test_peb_range():
    xa.set_backend(backend="csv", path="./")
    df = xa.get_daily("peb-000807.XSHG", prev=100, end="20200202")
    assert round(df[df["date"] == "2020-01-03"].iloc[0]["pe"], 2) == 30.09
Example #7
0
def test_peb_history():
    xa.set_backend(backend="csv", path="./")
    h = xa.universal.PEBHistory("SH000807", end="20200302")
    h.summary()
    h.v()  # matplotlib is required for this
    assert round(h.df.iloc[0]["pe"], 2) == 19.67
Example #8
0
def csv_cache():
    xa.set_backend(backend="csv", path="./")
    yield
    xa.set_backend(backend="memory", path="pytest-")