statistics#

tradeexecutor.state.statistics module.

Module description#

Various statistics calculated across portfolios and positions.

Statistics are calculated/refreshed on the server-side and exported as a part of the state. This way the clients (JavaScript) do not need to reconstruct this information.

Any statistics are optional: they are not needed to make any state transitions, they are purely there for profit and loss calculations.

Classes#

FinalPositionStatistics

When position is closed, its final statistics are calculated.

PortfolioStatistics

If backtesting, only calculated_at and total_equity are necessary for later visualisations and metrics If livetrading, then all attributes should be specified so that for displaying updated metrics after each trade

PositionStatistics

PositionStatistics(calculated_at: datetime.datetime, last_valuation_at: datetime.datetime, profitability: float, profit_usd: tradingstrategy.types.USDollarAmount, quantity: float, value: tradingstrategy.types.USDollarAmount)

Statistics

Statistics for a trade execution state.

Functions#

calculate_naive_profitability(...[, ...])

Calculate the profitability as value at end - value at start.