Statistics#

tradeexecutor.state.statistics.Statistics class.

class Statistics[source]#

Bases: object

Statistics for a trade execution state.

We calculate various statistics on the server-side and make them part of the state, so that JS clients can easily display this information.

Statistics are collected over time and more often than trading ticks. We store historical statistics for each position as the part of the state.

__init__(portfolio=<factory>, positions=<factory>, closed_positions=<factory>)#
Parameters
Return type

None

Methods

__init__([portfolio, positions, ...])

add_positions_stats(position_id, p_stats)

Add a new sample to position stats.

from_dict(kvs, *[, infer_missing])

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

get_latest_portfolio_stats()

get_latest_position_stats(position_id)

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

to_dict([encode_json])

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

Attributes

portfolio

Per portfolio statistics.

positions

Per position statistics.

closed_positions

Per position statistics for closed positions.

portfolio: List[PortfolioStatistics]#

Per portfolio statistics. Contains list of statistics for the portfolio over time. The first timestamp is the first entry in the list. Note that now we have only one portfolio per state.

positions: Dict[int, List[PositionStatistics]]#

Per position statistics. We look them up by position id. Each position contains list of statistics for the position over time. The first timestamp is the first entry in the list.

closed_positions: Dict[int, FinalPositionStatistics]#

Per position statistics for closed positions.

add_positions_stats(position_id, p_stats)[source]#

Add a new sample to position stats.

We cannot use defaultdict() here because we lose defaultdict instance on state serialization.

Parameters
__init__(portfolio=<factory>, positions=<factory>, closed_positions=<factory>)#
Parameters
Return type

None