Add the ability to plot backtest results
This commit is contained in:
parent
186e064f03
commit
6eefb07add
28
backtest_chart.py
Normal file
28
backtest_chart.py
Normal file
@ -0,0 +1,28 @@
|
||||
from chart import Chart
|
||||
from numpy import where
|
||||
from pandas import Series
|
||||
from plotly.graph_objects import Bar
|
||||
from typing import List
|
||||
|
||||
class BacktestChart(Chart):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
dates: Series,
|
||||
profit: Series,
|
||||
title: str = ''
|
||||
):
|
||||
self.x = dates
|
||||
self.profit = profit
|
||||
self.title = title
|
||||
|
||||
def traces(self) -> List[Bar]:
|
||||
color = where(self.profit >= 0, 'limegreen', 'red')
|
||||
return [Bar(
|
||||
x = self.x,
|
||||
y = self.profit,
|
||||
marker = dict(
|
||||
color = color,
|
||||
line = dict(width = 0)
|
||||
)
|
||||
)]
|
8
plot.py
8
plot.py
@ -36,13 +36,15 @@ def figure_with_subplots(subplots: List[List[Chart]]) -> Figure:
|
||||
|
||||
# TODO: Make this configurable.
|
||||
figure.update_layout(
|
||||
bargap = 0,
|
||||
bargroupgap = 0,
|
||||
paper_bgcolor = '#0f0f0f',
|
||||
plot_bgcolor = '#0f0f0f',
|
||||
font_color = '#7a7c7d',
|
||||
showlegend = False,
|
||||
margin = dict(
|
||||
pad = 15
|
||||
)
|
||||
margin = dict(pad = 15),
|
||||
xaxis = dict(zerolinecolor = '#0f0f0f'),
|
||||
yaxis = dict(zerolinecolor = '#0f0f0f')
|
||||
)
|
||||
|
||||
return figure
|
||||
|
@ -1,2 +1,3 @@
|
||||
numpy
|
||||
pandas
|
||||
plotly
|
Loading…
Reference in New Issue
Block a user