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, asset_histories=<factory>)#
- Parameters:
portfolio (Portfolio) –
asset_histories (Dict[object, AssetTradeHistory]) –
- Return type:
None
Methods
__init__
(portfolio[, asset_histories])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_first_opened_at
()get_last_closed_at
()get_max_consective
(positions)May be used in calculate_summary_statistics
Return open and closed positions over all traded assets.
create ordered timeline of trades for stats that need it
Attributes
portfolio
How a particular asset traded.
- asset_histories: Dict[object, AssetTradeHistory]#
How a particular asset traded. Asset id -> Asset history mapping
- 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’.
- 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:
- static get_max_consective(positions)[source]#
May be used in calculate_summary_statistics
- Parameters:
positions (List[TradePosition]) –
- Return type:
An list of trading positions, ordered by opened_at time. Note, must be ordered to be correct.
- __init__(portfolio, asset_histories=<factory>)#
- Parameters:
portfolio (Portfolio) –
asset_histories (Dict[object, AssetTradeHistory]) –
- Return type:
None