import sigtech.framework as sigfrom sigtech.framework.infra.objects.dtypes import FloatTypeimport datetime as dtmimport pandas as pdimport numpy as npimport seaborn as snssns.set(rc={'figure.figsize':(18,6)})sig.config.init()
In this example the strategy will buy initially as many future contracts as possible as set by the initial_cash . We will start with a simple example to buy 100 contracts of Crude Oil Futures.
Note: if no initial_cash is set the strategy assumes that 1000 currency units are available.
# start date of the strategystart_date = dtm.date(2017, 3, 2)# contract to enter into (front)co = sig.obj.get('COK17 COMDTY')# number of contractsn_contracts =100# price of the future at inception price_t = co.history()[start_date]# initial_cash required for this strategyinitial_cash = co.contract_size * n_contracts * price_tprint(initial_cash)
5508000.0
We want to purely look at the mark-to-market P&L isolating trading costs and cash interest accrual.
To verify your position and size use the interactive_portfolio_table.
Note: as we are using previous day price to calculate initial_cash there could be some differences from our calculation and final allocation as the usage is relative to the execution day price. The output below shows 100.785% exposure of our AUM equivalent to 100 contracts.
Since the size is relative to the cash available and the futures price, in the next roll our 100 contracts initial exposure could vary up or down. This is illustrated in the output below. From the available cash the strategy rolls from 100 to 101 trade units, or contracts:
co_strat.interactive_portfolio_table(
'TOP_ORDER_PTS',
start_dt=start_date,
end_dt=start_date+dtm.timedelta(days=30),
unit_type='TRADE') # shows the portfolio in number of contracts
Fixed number of contracts sizing
The default sizing explained above can be overwritten so that a fixed number of contracts is always traded independent of the initial_cash amount.
The argument fixed_contracts in the RollingFuturesStrategy allows to modify the roll behaviour without affecting any other property.
Comparing the two strategies we can quantify the impact of sizing in our strategies.