basana.backtesting.charts¶
- class basana.backtesting.charts.LineCharts(exchange)¶
A set of line charts that show the evolution of pair prices and account balances over time.
- Parameters:
exchange (Exchange) – The backtesting exchange.
- add_balance(symbol)¶
Adds a chart with an account’s balance.
- Parameters:
symbol (str) – The currency symbol.
- add_custom(name, line, get_data_point, marker={})¶
Adds a custom chart.
- Parameters:
name (str) – The name of the chart.
line (str) – The name of the line.
get_data_point (Callable[[datetime], Decimal | None]) – A callable that will be used to get the line data points.
marker (dict) – Forwarded to Plotly when creating a go.Scatter.
- add_pair(pair, include_buys=True, include_sells=True, candlesticks=True)¶
Adds a chart with the pair values.
- Parameters:
pair (Pair) – The pair.
include_buys (bool) – True to include buy prices.
include_sells (bool) – True to include sell prices.
candlesticks (bool) – True to produce a candlestick chart, False to plot only the closing value.
- add_pair_indicator(name, pair, get_data_point, marker={})¶
Adds a technical indicator to a pair’s chart.
- Parameters:
name (str) – The name of the indicator.
pair (Pair) – The pair chart to add the indicator to.
get_data_point (Callable[[datetime], Decimal | None]) – A callable that will be used to get the data point on each bar.
marker (dict) – Forwarded to Plotly when creating a go.Scatter.
- add_portfolio_value(symbol, precision=2)¶
Adds a chart with the portfolio value in a given currency.
- Parameters:
symbol (str) – The currency symbol.
precision (int) – The number of digits after the decimal point.
Note
If the portfolio value can’t be calculated at any given point, for example because there is no price for a given instrument, an error will be logged.
- save(path, width=None, height=None, scale=None, show_legend=True)¶
Saves the chart to a file.
- Parameters:
path (str) – The path to the file to save the image.
width (int | None) – The width of the exported image in layout pixels.
height (int | None) – The height of the exported image in layout pixels.
scale (int | float | None) – The scale factor to use when exporting the figure.
show_legend (bool) – True if legends should be visible, False otherwise.
Note
The supported file formats are png, jpg/jpeg, webp, svg and pdf.
- show(show_legend=True)¶
Shows the chart using either the default renderer(s).
Check https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html#plotly.graph_objects.Figure.show for more information.
- Parameters:
show_legend (bool) – True if legends should be visible, False otherwise.
- class basana.backtesting.charts.DataPointFromSequence(seq)¶
Callable that returns the last value of a sequence if its not empty.
- Parameters:
seq (Sequence[Any]) – The sequence that will be used to get the value.