def backtest():
    feed = {}

    for code, hist in load_hist("test_code"):
        feed[code] = hist

    if not feed:
        sys.exit("没有没有任何历史数据")

    mytest = MyBackTest(feed)
    return mytest
Beispiel #2
0
#         hist["ma10"] = hist.close.rolling(10).mean()
#         hist["ma20"] = hist.close.rolling(20).mean()
#         feed[code] = hist

#     mytest = MyBackTest(feed)
#     mytest.start()
#     stats = mytest.stat
#     stats.data.to_csv("report/stat.csv")
#     print("最大回彻率: {}% ".format(stats.max_dropdown * 100))
#     print("年化收益: {}% ".format(stats.annual_return * 100))
#     print("夏普比率: {} ".format(stats.sharpe))

if __name__ == '__main__':
    feed = {}

    for code, hist in load_hist("000002.SZ"):
        # hist = hist.iloc[:30]
        hist["ma10"] = hist.close.rolling(10).mean()
        hist["ma20"] = hist.close.rolling(20).mean()
        feed[code] = hist

    if not feed:
        sys.exit("没有没有任何历史数据")
    mytest = MyBackTest(feed)
    mytest.start()
    order_lst = mytest.ctx.broker.order_hist_lst
    if not path.exists("report"):
        os.mkdir("report")
    with open("report/order_hist.json", "w") as wf:
        json.dump(order_lst, wf, indent=4, default=str)
    stats = mytest.stat
Beispiel #3
0
# 设置相关变量
ts = get_ts_client()
pro = ts.pro_api()
start_date = "2015-01-01"
external_stylesheets = [
    'https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css'
]
sh_index_path = path.join("data", "index", "000001.SH.csv")
feed = {}

# 主题样式
main_style = {"margin": "0 5%"}

count = 0
for code, hist in load_hist(start_date="2018-01-01"):
    count += 1
    feed[code] = hist
    if count == 10:
        break

# 获取数据
# 上证指数日线数据
if path.exists(sh_index_path):
    sh_index = pd.read_csv(sh_index_path,
                           parse_dates=["trade_date"],
                           index_col="trade_date")
    sh_index["ma10"] = sh_index.close.rolling(10).mean()
    sh_index["ma20"] = sh_index.close.rolling(20).mean()
    sh_index["ma150"] = sh_index.close.rolling(150).mean()
else: