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:
kind (KeyMetricKind) –
source (KeyMetricSource) –
value (float | datetime.datetime | datetime.timedelta | None) –
calculation_window_start_at (datetime.datetime | None) –
calculation_window_end_at (datetime.timedelta | None) –
calculation_method (tradeexecutor.strategy.summary.KeyMetricCalculationMethod | None) –
unavailability_reason (str | None) –
help_link (str | None) –
name (str | None) –
- 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
What is this metric
Did we calculate this metric based on live trading or backtesting data
What's the time period for which this metric was calculated.
What's the time period for which this metric was calculated
What's the time period for which this metric was calculated
How this key metric is calculated
Unavaiability reason.
Help link
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
Unavaiability reason.
Human readable error message why this metric is not available. Useful for tooltips.
- help_link: str | None#
Help link
Read more link.
Does not need to be part of the state, but we make the frontend dev life easy.
- static create_na(kind, reason)[source]#
Create missing value placeholder.
- Parameters:
kind (KeyMetricKind) –
reason (str) –
- Return type:
- 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:
kind (KeyMetricKind) –
source (KeyMetricSource) –
value (Any) –
calculation_window_start_at (datetime) –
calculation_window_end_at (datetime) –
method (KeyMetricCalculationMethod) –
- Return type:
- __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:
kind (KeyMetricKind) –
source (KeyMetricSource) –
value (float | datetime.datetime | datetime.timedelta | None) –
calculation_window_start_at (datetime.datetime | None) –
calculation_window_end_at (datetime.timedelta | None) –
calculation_method (tradeexecutor.strategy.summary.KeyMetricCalculationMethod | None) –
unavailability_reason (str | None) –
help_link (str | None) –
name (str | None) –
- Return type:
None