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:
portfolio (Portfolio) –
decision_cycle_frequency (DateOffset) –
- Return type:
None
Methods
__init__
(portfolio[, decision_cycle_frequency])calculate_summary_statistics
([time_bucket, ...])Calculate some statistics how our trades went.
Create a timeline feed how we traded over a course of time.
Return open and closed positions over all traded assets.
get_capital_tied_at_open
(position)Get the opened_at timestamp of the first position in the portfolio.
Get the closed_at timestamp of the last position in the portfolio.
Return open positions over all traded assets.
Attributes
The portfolio we analysed
All taken positions sorted by the position id, or when they were opened
Decision cycle frequency is needed to calculate some performance metrics like sharpe, etc.
- 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_all_positions()[source]#
Return open and closed positions over all traded assets.
Positions are sorted by position_id.
- Return type:
- get_open_positions()[source]#
Return open positions over all traded assets.
Positions are sorted by position_id.
- Return type:
- 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:
- 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:
- __init__(portfolio, decision_cycle_frequency=<factory>)#
- Parameters:
portfolio (Portfolio) –
decision_cycle_frequency (DateOffset) –
- Return type:
None