-
Notifications
You must be signed in to change notification settings - Fork 15
/
backtrader_app.py
44 lines (35 loc) · 1.46 KB
/
backtrader_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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()