Build Trade History¶
Helper for building an algorithm trading and performance history as a dictionary that can be reviewed during or after an algorithm finishes running
-
analysis_engine.build_trade_history_entry.
build_trade_history_entry
(ticker, num_owned, close, balance, commission, date, trade_type, algo_start_price, original_balance, minute=None, high=None, low=None, open_val=None, volume=None, ask=None, bid=None, today_high=None, today_low=None, today_open_val=None, today_close=None, today_volume=None, stop_loss=None, trailing_stop_loss=None, buy_hold_units=None, sell_hold_units=None, spread_exp_date=None, spread_id=None, low_strike=None, low_bid=None, low_ask=None, low_volume=None, low_open_int=None, low_delta=None, low_gamma=None, low_theta=None, low_vega=None, low_rho=None, low_impl_vol=None, low_intrinsic=None, low_extrinsic=None, low_theo_price=None, low_theo_volatility=None, low_max_covered=None, low_exp_date=None, high_strike=None, high_bid=None, high_ask=None, high_volume=None, high_open_int=None, high_delta=None, high_gamma=None, high_theta=None, high_vega=None, high_rho=None, high_impl_vol=None, high_intrinsic=None, high_extrinsic=None, high_theo_price=None, high_theo_volatility=None, high_max_covered=None, high_exp_date=None, prev_balance=None, prev_num_owned=None, total_buys=None, total_sells=None, buy_triggered=None, buy_strength=None, buy_risk=None, sell_triggered=None, sell_strength=None, sell_risk=None, num_indicators_buy=None, num_indicators_sell=None, min_buy_indicators=None, min_sell_indicators=None, net_gain=None, net_value=None, ds_id=None, note=None, err=None, entry_spread_dict=None, version=1, verbose=False)[source]¶ Build a dictionary for tracking an algorithm profitability per ticker and for
TRADE_SHARES
,TRADE_VERTICAL_BULL_SPREAD
, orTRADE_VERTICAL_BEAR_SPREAD
trading types.Note
setting the
minute
is required to build a minute-by-minuteTrading History
Parameters: - ticker – string ticker or symbol
- num_owned – integer current owned
number of
shares
for this asset or number of currently ownedcontracts
for an options spread. - close – float
close
price of the underlying asset - balance – float amount of available capital
- commission – float for commission costs
- date – string trade date for that row usually
COMMON_DATE_FORMAT
(YYYY-MM-DD
) - minute – optional - string for recording the minute
the trade was place, and the format is
COMMON_TICK_DATE_FORMAT
(YYYY-MM-DD HH:MM:SS
) this is optional if the algorithm is set up to trade using aday
value for timeseries. - trade_type – type of the trade - supported values:
TRADE_SHARES
,TRADE_VERTICAL_BULL_SPREAD
,TRADE_VERTICAL_BEAR_SPREAD
- algo_start_price – float starting close/contract price for this algo
- original_balance – float starting original account balance for this algo
- high – optional - float underlying stock asset
high
price - low – optional - float underlying stock asset
low
price - open_val – optional - float underlying stock asset
open
price - volume – optional - integer underlying stock asset
volume
- ask – optional - float
ask
price of the stock (for buyingshares
) - bid – optional - float
bid
price of the stock (for sellingshares
) - today_high – optional - float
high
from the daily dataset (if available) - today_low – optional - float
low
from the daily dataset (if available) - today_open_val – optional - float
open
from the daily dataset (if available) - today_close – optional - float
close
from the daily dataset (if available) - today_volume – optional - float
volume
from the daily dataset (if available) - stop_loss – optional - float
stop_loss
price of the stock/spread (for sellingshares
vscontracts
) - trailing_stop_loss – optional - float
trailing_stop_loss
price of the stock/spread (for sellingshares
vscontracts
) - buy_hold_units – optional - number of units to hold buys - helps with algorithm tuning
- sell_hold_units – optional - number of units to hold sells - helps with algorithm tuning
- spread_exp_date – optional - string spread contract
expiration date (
COMMON_DATE_FORMAT
(YYYY-MM-DD
) - spread_id – optional - spread identifier for reviewing spread performances
- low_strike – optional
- only for vertical bull/bear trade types
low leg strike price
of the spread - low_bid – optional
- only for vertical bull/bear trade types
low leg bid
of the spread - low_ask – optional
- only for vertical bull/bear trade types
low leg ask
of the spread - low_volume – optional
- only for vertical bull/bear trade types
low leg volume
of the spread - low_open_int – optional
- only for vertical bull/bear trade types
low leg open interest
of the spread - low_delta – optional
- only for vertical bull/bear trade types
low leg delta
of the spread - low_gamma – optional
- only for vertical bull/bear trade types
low leg gamma
of the spread - low_theta – optional
- only for vertical bull/bear trade types
low leg theta
of the spread - low_vega – optional
- only for vertical bull/bear trade types
low leg vega
of the spread - low_rho – optional
- only for vertical bull/bear trade types
low leg rho
of the spread - low_impl_vol – optional
- only for vertical bull/bear trade types
low leg implied volatility
of the spread - low_intrinsic – optional
- only for vertical bull/bear trade types
low leg intrinsic
of the spread - low_extrinsic – optional
- only for vertical bull/bear trade types
low leg extrinsic
of the spread - low_theo_price – optional
- only for vertical bull/bear trade types
low leg theoretical price
of the spread - low_theo_volatility – optional
- only for vertical bull/bear trade types
low leg theoretical volatility
of the spread - low_max_covered – optional
- only for vertical bull/bear trade types
low leg max covered returns
of the spread - low_exp_date – optional
- only for vertical bull/bear trade types
low leg expiration date
of the spread - high_strike – optional
- only for vertical bull/bear trade types
high leg strike price
of the spread - high_bid – optional
- only for vertical bull/bear trade types
high leg bid
of the spread - high_ask – optional
- only for vertical bull/bear trade types
high leg ask
of the spread - high_volume – optional
- only for vertical bull/bear trade types
high leg volume
of the spread - high_open_int – optional
- only for vertical bull/bear trade types
high leg open interest
of the spread - high_delta – optional
- only for vertical bull/bear trade types
high leg delta
of the spread - high_gamma – optional
- only for vertical bull/bear trade types
high leg gamma
of the spread - high_theta – optional
- only for vertical bull/bear trade types
high leg theta
of the spread - high_vega – optional
- only for vertical bull/bear trade types
high leg vega
of the spread - high_rho – optional
- only for vertical bull/bear trade types
high leg rho
of the spread - high_impl_vol – optional
- only for vertical bull/bear trade types
high leg implied volatility
of the spread - high_intrinsic – optional
- only for vertical bull/bear trade types
high leg intrinsic
of the spread - high_extrinsic – optional
- only for vertical bull/bear trade types
high leg extrinsic
of the spread - high_theo_price – optional
- only for vertical bull/bear trade types
high leg theoretical price
of the spread - high_theo_volatility – optional
- only for vertical bull/bear trade types
high leg theoretical volatility
of the spread - high_max_covered – optional
- only for vertical bull/bear trade types
high leg max covered returns
of the spread - high_exp_date – optional
- only for vertical bull/bear trade types
high leg expiration date
of the spread - prev_balance – optional - previous balance for this algo
- prev_num_owned – optional - previous num of
shares
orcontracts
- total_buys – optional - total buy orders for this algo
- total_sells – optional - total sell orders for this algo
- buy_triggered – optional - bool
buy
conditions in the algorithm triggered - buy_strength – optional - float custom strength/confidence rating for tuning algorithm performance for desirable sensitivity and specificity
- buy_risk – optional - float custom risk rating for tuning algorithm peformance for avoiding custom risk for buy conditions
- sell_triggered – optional - bool
sell
conditions in the algorithm triggered - sell_strength – optional - float custom strength/confidence rating for tuning algorithm performance for desirable sensitivity and specificity
- sell_risk – optional - float custom risk rating for tuning algorithm peformance for avoiding custom risk for buy conditions
- num_indicators_buy – optional - integer
number of indicators the
IndicatorProcessor
processed and said tobuy
an asset - num_indicators_sell – optional - integer
number of indicators the
IndicatorProcessor
processed and said tosell
an asset - min_buy_indicators – optional - integer
minimum number of indicators required to trigger
a
buy
order - min_sell_indicators – optional - integer
minimum number of indicators required to trigger
a
sell
order net_gain=None, net_value=None, - net_value – optional - float total value the algorithm
has left remaining since starting trading. this includes
the number of
self.num_owned
shares with theself.latest_close
price included - net_gain – optional - float amount the algorithm has
made since starting including owned shares
with the
self.latest_close
price included - ds_id – optional - datset id for debugging
- note – optional - string for tracking high level
testing notes on algorithm indicator ratings and
internal message passing during an algorithms’s
self.process
method - err – optional - string for tracking errors
- entry_spread_dict – optional - on exit spreads the calculation of net gain can use the entry spread to determine specific performance metrics (work in progress)
- version – optional - version tracking order history
- verbose – optional - bool log each history node
(default is
False
)