⚙️
事件驱动引擎
行情一次加载进内存,策略按生命周期回调推进;支持订阅、定时任务与成交事件,不依赖框架源码。
安装发行包后,几行代码跑通一个真实回测(完整可运行示例见文档):
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"]) # 绩效摘要继续阅读: