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>)#
Parameters:
Return type:

None

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_total_points()

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

Messages for each strategy cycle.

calculations

Extra calculation diagnostics for each strategy cycle.

plots

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.

plots: Dict[str, Plot]#

Name -> Plot value mappings

add_message(timestamp, content)[source]#

Write a debug message.

  • Each message is associated to a different timepoint.

Parameters:
  • timestamp (datetime) – The current strategy cycle timestamp

  • content (str) – The contents of the message

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.

Parameters:
  • timestamp (datetime) – The current strategy cycle timestamp

  • cycle_calculations (dict) –

    The contents of the calculations.

    Must be JSON serialisable dict.

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

  • colour (Optional[str]) – Optional colour

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

get_timestamp_range(plot_name=None)[source]#

Get the time range for which we have data.

Parameters:

plot_name (Optional[str]) –

Use range from a specific plot.

If not given use the first plot.

Returns:

UTC started at, ended at.

Return None, None if no data.

Return type:

Tuple[Optional[datetime], Optional[datetime]]

get_total_points()[source]#

Get number of data points stored in all plots.

Return type:

int

__init__(messages=<factory>, calculations=<factory>, plots=<factory>)#
Parameters:
Return type:

None