-
Notifications
You must be signed in to change notification settings - Fork 5
Description
The goal for adding intraday functionality would be for allowing rebalancing
several times a day. One of the main use cases would be for allowing trading
prices which are different than EOD mark to market prices. The goal is not
to allow intraday rebalances at something like 5 minute frequencies, as this
would require a major rethink in order to be performant at this granularity.
Currently the simulation() suffers from a few hacky workarounds which
would make it difficult to add intraday functionality.
Issues
-
the simulation runs over a set of dates and the weights for generics have
values for each day. However, on a roll day there is actual two weights for
an instrument, the before trade weight and the after trade weight. For example,
the weights for TY1 are:2015-02-24 2015TYH 1.0 2015-02-25 2015TYM 1.0this means that, up until 2015-02-24 TY1 is entirely allocated to the 2015TYH
contract, whereas after 2015-02-24, TY1 is entirely allocated to the 2015TYM.
The implicit assumption here is the the roll is happening at the time
associated the instrument prices for 2015-02-24 (in most examples the settlement price). -
PnL is calculated as
daily_pnl. To allow intraday functionality this should
be disaggregated into mark to market PnL from overnight holdings
(holdings_pnl) and daily PnL from trading (trading_pnl). -
for
simulation()to perform correctly the implementations of
rebalance_datesandinstrument_weightsin the concrete class have to be
consistent in the following sense:rebalance_datesneeds to include every
transition that happens in the weightings for instruments. If the previous
condition is not specified, PnL and holdings will be calculated as if a roll
has happened when in fact it has not. -
the current implementation is difficult to test since the functionality is
quite monolithic and handles trading, updating holdings and calculating PnL all
within the scope of the simulation.
Possible Solutions
Currently the simulation looks at tradeable_dates and rebal_dates. One
solution would be to create mtm_datetimes (a more appropriate name for
tradeable_dates) and rebal_datetimes. Including time aware dates would
also force all pricing data to be timestamped, so if not available from the
source this would have to be added on a best guess basis.
The main loop structure would also have to be changed to allow
rebal_datetimes to account for the possibility of multiple times per day.
Since all instruments would have the same mark-to-market time of day, this
would make using the settlement price problematic since there is asynchronicity
between instrument settlement times. In addition if there were instruments
without any overlapping trading hours this would also be problematic.
The redesigned workflow would look like
1. If a rebalance day calculate the trading PnL
2. Calculate overnight holdings MTM PnL
3. Update EOD holdings
Another possible change is to run the simulation on actual tradeable
instruments and handle the mapping to generics afterword, just for accounting
purposes when doing PnL attribution to generics. This could possibly simplify
the logic within the loop of the simulation.
As an addendum, the trade() and notional_exposure() APIs are currently a
bit messy in the sense that it takes in weights. It is more natural to abstract
these away from the user call however this leads to a less performant
implementation which has ramifications for simulate()