MCPcopy Create free account
hub / github.com/DVampire/FinAgent / plot_kline

Method plot_kline

finagent/plots/interface.py:31–64  ·  view source on GitHub ↗
(self, state, info, save_dir, mode = "train")

Source from the content-addressed store, hash-verified

29 self.echarts_js_path = os.path.join(self.root, "tools", "echarts-5.4.3" , "dist", "echarts.min.js")
30
31 def plot_kline(self, state, info, save_dir, mode = "train"):
32
33 try:
34 price = state["price"]
35
36 kline_dir = init_path(os.path.join(self.kline_plot_path, save_dir))
37
38 if not os.path.exists(os.path.join(kline_dir, "echarts.min.js")):
39 shutil.copy(self.echarts_js_path, kline_dir)
40
41 price = price[["open", "high", "low", "close", "volume"]]
42 price = price.reset_index(drop=False)
43 price = price.dropna(axis=0, how="any")
44 price = price.drop_duplicates(subset=["timestamp"], keep="first")
45 price = price.set_index("timestamp")
46
47 title = "{} kline of {}".format(info["date"], info["symbol"])
48 kline_path = os.path.join(kline_dir, "kline_{}.{}".format(info["date"], self.suffix))
49
50 now_date = pd.to_datetime(info["date"])
51 now_date = min(price.index, key=lambda x: abs(x - now_date)) # find the nearest date before now_date
52 now_date = now_date.strftime("%Y-%m-%d")
53
54 plot_kline(price,
55 title,
56 kline_path,
57 now_date=now_date,
58 path=os.path.join(kline_dir, f"{info['date']}_{self.suffix}_kline_render.html"),
59 mode=mode)
60
61 except Exception as e:
62 print(e)
63 kline_path = None
64 return kline_path
65
66 def plot_trading(self, records, info, save_dir):
67 try:

Callers 5

run_stepFunction · 0.80
run_stepFunction · 0.80
run_stepFunction · 0.80
run_stepFunction · 0.80
run_stepFunction · 0.80

Calls 2

init_pathFunction · 0.90
plot_klineFunction · 0.90

Tested by

no test coverage detected