plotting/backtest_chart.py

28 lines
668 B
Python

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)
)
)]