TradeAnalysis#

tradeexecutor.analysis.trade_analyser.TradeAnalysis Python class in Trading Strategy framework.

class TradeAnalysis[source]#

Bases: object

Analysis of trades in a portfolio.

__init__(portfolio, decision_cycle_frequency=<factory>)#
Parameters:
Return type:

None

Methods

__init__(portfolio[, decision_cycle_frequency])

calculate_summary_statistics([time_bucket, ...])

Calculate some statistics how our trades went.

create_timeline()

Create a timeline feed how we traded over a course of time.

get_all_positions()

Return open and closed positions over all traded assets.

get_capital_tied_at_open(position)

get_first_opened_at()

Get the opened_at timestamp of the first position in the portfolio.

get_last_closed_at()

Get the closed_at timestamp of the last position in the portfolio.

get_open_positions()

Return open positions over all traded assets.

Attributes

portfolio

The portfolio we analysed

filtered_sorted_positions

All taken positions sorted by the position id, or when they were opened

decision_cycle_frequency

Decision cycle frequency is needed to calculate some performance metrics like sharpe, etc.

portfolio: Portfolio#

The portfolio we analysed

filtered_sorted_positions: list[tradeexecutor.state.position.TradingPosition]#

All taken positions sorted by the position id, or when they were opened

decision_cycle_frequency: DateOffset#

Decision cycle frequency is needed to calculate some performance metrics like sharpe, etc.

If not given assume daily for the legacy compatibilty

get_first_opened_at()[source]#

Get the opened_at timestamp of the first position in the portfolio.

Return type:

Optional[Timestamp]

get_last_closed_at()[source]#

Get the closed_at timestamp of the last position in the portfolio.

Return type:

Optional[Timestamp]

get_all_positions()[source]#

Return open and closed positions over all traded assets.

Positions are sorted by position_id.

Return type:

Iterable[Tuple[int, TradingPosition]]

get_open_positions()[source]#

Return open positions over all traded assets.

Positions are sorted by position_id.

Return type:

Iterable[Tuple[int, TradingPosition]]

calculate_summary_statistics(time_bucket=None, state=None)[source]#

Calculate some statistics how our trades went.

Parameters:
  • time_bucket (Optional[TimeBucket]) – Optional, used to display average duration as ‘number of bars’ instead of ‘number of days’.

  • state – Optional, should be specified if user would like to see advanced statistics

Returns:

TradeSummary instance

Return type:

TradeSummary

create_timeline()[source]#

Create a timeline feed how we traded over a course of time.

Note: We assume each position has only one enter and exit event, not position increases over the lifetime.

Returns:

DataFrame with timestamp and timeline_event columns

Return type:

DataFrame

__init__(portfolio, decision_cycle_frequency=<factory>)#
Parameters:
Return type:

None