Trading and Orders
Trade Statistics
Introduction
The TradeBuilder
tracks the trades of your algorithm and calculates some statistics.
Some of these statistics are a function of the risk free interest rate and the number of trading days per year.
You can adjust how the TradeBuilder
defines a trade and how it matches offsetting order fills.
Set Trade Builder
To set the TradeBuilder
, in the Initialize
initialize
method, call the SetTradeBuilder
set_trade_builder
method.
SetTradeBuilder(new TradeBuilder(groupingMethod, matchingMethod));
self.set_trade_builder(TradeBuilder(grouping_method, matching_method))
The following table describes the arguments the TradeBuilder
constructor accepts:
Argument | Data Type | Description | Default Value |
---|---|---|---|
groupingMethod grouping_method | FillGroupingMethod | The method used to group order fills into trades | |
matchingMethod matching_method | FillMatchingMethod | The method used to match offsetting order fills |
The FillGroupingMethod
enumeration has the following members:
The FillMatchingMethod
enumeration has the following members:
Check Open Positions
To check if you have a position open for a security as defined by the FillGroupingMethod
, call the HasOpenPosition
has_open_position
method.
// Check if the trade builder has recorded any active trades (unclosed positions) // for a security. var hasOpenPosition = TradeBuilder.HasOpenPosition(_symbol);
# Check if the trade builder has recorded any active trades (unclosed positions) # for a security. has_open_position = self.trade_builder.has_open_position(self._symbol)