Visualisation#
tradeexecutor.state.visualisation.Visualisation Python class in Trading Strategy framework.
- class Visualisation[source]#
Bases:
object
This object is returned from the strategy execution cycle. It allows you to plot values, add debug messages, etc. It is not used in any trading, but can help and visualize trade backtesting and execution.
- __init__(messages=<factory>, calculations=<factory>, plots=<factory>)#
Methods
__init__
([messages, calculations, plots])add_calculations
(timestamp, cycle_calculations)Update strategy cycle calculations diagnostics.
add_message
(timestamp, content)Write a debug message.
from_dict
(kvs, *[, infer_missing])from_json
(s, *[, parse_float, parse_int, ...])get_timestamp_range
([plot_name])Get the time range for which we have data.
Get number of data points stored in all plots.
plot_indicator
(timestamp, name, kind, value)Add a value to the output data and diagram.
schema
(*[, infer_missing, only, exclude, ...])to_dict
([encode_json])to_json
(*[, skipkeys, ensure_ascii, ...])Attributes
Messages for each strategy cycle.
Extra calculation diagnostics for each strategy cycle.
Name -> Plot value mappings
- messages: Dict[int, List[str]]#
Messages for each strategy cycle.
Because we cannot use datetime.datetime directly as a key in JSON, we use UNIX timestamp here to keep our state easily serialisable.
- calculations: Dict[int, dict]#
Extra calculation diagnostics for each strategy cycle.
Cycle -> dict of values mappings.
Currently used to record the alpha model state when doing doing portfolio construction modelling.
Because we cannot use datetime.datetime directly as a key in JSON, we use UNIX timestamp here to keep our state easily serialisable.
- add_message(timestamp, content)[source]#
Write a debug message.
Each message is associated to a different timepoint.
- add_calculations(timestamp, cycle_calculations)[source]#
Update strategy cycle calculations diagnostics.
Each strategy cycle can dump whatever intermediate calculations state on the visualisation record keeping, so that it can be later pulled up in the analysis.
Currently this is used to store the alpha model calculations for portfolio construction model.
- plot_indicator(timestamp, name, kind, value, colour=None, plot_shape=PlotShape.linear, detached_overlay_name=None, indicator_size=None, recording_time=RecordingTime.decision_making_time, pair=None)[source]#
Add a value to the output data and diagram.
Plots are stored by their name.
- Parameters:
timestamp (Union[datetime, Timestamp]) – The current strategy cycle timestamp
name (str) – The plot label
kind (PlotKind) – The plot typre
value (float) – Current value e.g. price as USD
plot_shape (Optional[PlotShape]) – PlotShape enum value e.g. Plotshape.linear or Plotshape.horizontal_vertical
detached_overlay_name (Optional[str]) – If this plot is overlayed on top of a detached technical indicator, this is the name of the overlay it should be attached to.
indicator_size (Optional[float]) – Optional indicator to determine the size of the indicator. For a line, this is the width of the line. For a marker, this is the size of the marker.
recording_time (Optional[RecordingTime]) – Optional recording time to determine when the plot should be recorded. For example, if you want to record the plot at the decision making time, you can set this to RecordingTime.decision_making_time. Default is RecordingTime.decision_making_time.
pair (Optional[TradingPairIdentifier]) –