KeyMetric#

API documentation for tradeexecutor.strategy.summary.KeyMetric Python class in Trading Strategy framework.

class KeyMetric[source]#

Bases: object

One of available key metrics on the summary card.

__init__(kind, source, value, calculation_window_start_at=None, calculation_window_end_at=None, calculation_method=None, unavailability_reason=None, help_link=None, name=None)#
Parameters:
Return type:

None

Methods

__init__(kind, source, value[, ...])

create_metric(kind, source, value, ...)

Create a metric value.

create_na(kind, reason)

Create missing value placeholder.

from_dict(kvs, *[, infer_missing])

from_json(s, *[, parse_float, parse_int, ...])

schema(*[, infer_missing, only, exclude, ...])

to_dict([encode_json])

to_json(*[, skipkeys, ensure_ascii, ...])

Attributes

kind

What is this metric

source

Did we calculate this metric based on live trading or backtesting data

value

What's the time period for which this metric was calculated.

calculation_window_start_at

What's the time period for which this metric was calculated

calculation_window_end_at

What's the time period for which this metric was calculated

calculation_method

How this key metric is calculated

unavailability_reason

Unavaiability reason.

help_link

Help link

name

Name of the metric

kind: KeyMetricKind#

What is this metric

source: KeyMetricSource#

Did we calculate this metric based on live trading or backtesting data

value: float | datetime.datetime | datetime.timedelta | None#

What’s the time period for which this metric was calculated.

Different Python value types supported, but everything is serialised to JavaScript Number type in for JSON.

Set to None when unavailable. In this case this should be presented as “N/A” in the frontend.

calculation_window_start_at: datetime.datetime | None#

What’s the time period for which this metric was calculated

calculation_window_end_at: datetime.timedelta | None#

What’s the time period for which this metric was calculated

calculation_method: tradeexecutor.strategy.summary.KeyMetricCalculationMethod | None#

How this key metric is calculated

Hint for the frontend

unavailability_reason: str | None#

Unavaiability reason.

Human readable error message why this metric is not available. Useful for tooltips.

Help link

Read more link.

Does not need to be part of the state, but we make the frontend dev life easy.

name: str | None#

Name of the metric

Should be in human readable format

static create_na(kind, reason)[source]#

Create missing value placeholder.

Parameters:
Return type:

KeyMetric

static create_metric(kind, source, value, calculation_window_start_at, calculation_window_end_at, method)[source]#

Create a metric value.

Automatically fill in the help text link from our hardcoded mapping.

Parameters:
Return type:

KeyMetric

__init__(kind, source, value, calculation_window_start_at=None, calculation_window_end_at=None, calculation_method=None, unavailability_reason=None, help_link=None, name=None)#
Parameters:
Return type:

None