1 Star 0 Fork 4

redbreast/stock-backtrader-web-app

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backtrader_app.py 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
chenwanrui 提交于 2022-02-18 11:53 . restructure code
import streamlit as st
from streamlit_echarts import st_pyecharts
from charts import draw_pro_kline, draw_result_bar
from frames import akshare_selector_ui, backtrader_selector_ui, params_selector_ui
from utils.logs import LOGGER
from utils.processing import gen_stock_df, load_strategy, run_backtrader
from utils.schemas import StrategyBase
st.set_page_config(page_title="backtrader")
def main():
ak_params = akshare_selector_ui()
backtrader_params = backtrader_selector_ui()
if ak_params["symbol"]:
stock_df = gen_stock_df(ak_params)
st.subheader("Kline")
kline = draw_pro_kline(stock_df)
st_pyecharts(kline, height="500px")
st.subheader("Strategy")
name = st.selectbox("strategy", list(strategy.keys()))
submitted, params = params_selector_ui(strategy[name])
if submitted:
LOGGER.info(f"akshare: {ak_params}")
LOGGER.info(f"backtrader: {backtrader_params}")
backtrader_params.update(
{
"stock_df": stock_df.iloc[:, :6],
"strategy": StrategyBase(name=name, params=params),
}
)
par_df = run_backtrader(**backtrader_params)
st.dataframe(par_df.style.highlight_max(subset=par_df.columns[-3:]))
bar = draw_result_bar(par_df)
st_pyecharts(bar, height="500px")
strategy = load_strategy("./config/strategy.yaml")
if __name__ == "__main__":
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xujianjun99/stock-backtrader-web-app.git
[email protected]:xujianjun99/stock-backtrader-web-app.git
xujianjun99
stock-backtrader-web-app
stock-backtrader-web-app
master

搜索帮助