跳转到正文

LocalQuant本地量化回测框架

事件驱动 · A 股 / 场内基金 / 国内期货 · 真实撮合约束 · 全流程本地运行

快速开始 ​

安装发行包后,几行代码跑通一个真实回测(完整可运行示例见文档):

python
from localquant import run_func
from localquant.apis import order_shares, update_universe
from localquant.mod.localquant_mod_seeddata_source import (
    load_framework_data, register_bundle,
)

# 从数据网关加载行情,注册后全程内存使用
bundle = load_framework_data(
    ["600000.SH"], start="2024-05-27", end="2024-06-07",
    base_url="http://127.0.0.1:28637",
)
key = register_bundle(bundle)

def init(context):
    update_universe(["600000.SH"])

def open_auction(context, bar_dict):
    order_shares("600000.SH", 100)  # 开盘竞价买入 100 股

result = run_func(
    config={
        "base": {
            "start_date": "2024-06-03", "end_date": "2024-06-07",
            "frequency": "1d", "accounts": {"stock": 100_000},
            "capital_gain_tax_rate": 0,
        },
        "mod": {
            "seeddata_source": {
                "enabled": True, "priority": 0, "bundle_key": key,
                "lib": "localquant.mod.localquant_mod_seeddata_source",
            }
        },
    },
    init=init, open_auction=open_auction,
)

print(result["sys_analyser"]["summary"])  # 绩效摘要

继续阅读:

localquant front-end portal