macrosynergy.pnl.transaction_costs#

get_fids(df)[source]#
Return type:

list

check_df_for_txn_stats(df, fids, tcost_n, rcost_n, size_n, tcost_l, rcost_l, size_l)[source]#
Return type:

None

get_diff_index(df_wide, freq='D')[source]#
Return type:

Index

extrapolate_cost(trade_size, median_size, median_cost, pct90_size, pct90_cost)[source]#
Return type:

Number

class SparseCosts(df)[source]#

Bases: object

prepare_data()[source]#

Prepares data for use within the class, including setting up the wide DataFrame and fids. This method can be called again to refresh the data and cache.

get_costs(fid, real_date)[source]#

Returns the costs for a given FID and date.

Parameters:
  • fid (str) – The FID (financial contract identifier) to get costs for.

  • real_date (str) – The date to get costs for.

Return type:

Series

class TransactionCosts(df, fids, tcost_n='BIDOFFER_MEDIAN', rcost_n='ROLLCOST_MEDIAN', size_n='SIZE_MEDIAN', tcost_l='BIDOFFER_90PCTL', rcost_l='ROLLCOST_90PCTL', size_l='SIZE_90PCTL')[source]#

Bases: object

Interface to query transaction statistics dataframe.

DEFAULT_ARGS = {'rcost_l': 'ROLLCOST_90PCTL', 'rcost_n': 'ROLLCOST_MEDIAN', 'size_l': 'SIZE_90PCTL', 'size_n': 'SIZE_MEDIAN', 'tcost_l': 'BIDOFFER_90PCTL', 'tcost_n': 'BIDOFFER_MEDIAN'}#
check_init()[source]#
Return type:

bool

property change_index: DatetimeIndex#
Return type:

DatetimeIndex

property df_wide: DataFrame#
Return type:

DataFrame

property qdf: QuantamentalDataFrame#
Return type:

QuantamentalDataFrame

static from_qdf(qdf, fids)[source]#
Return type:

TransactionCosts

classmethod download()[source]#
Return type:

TransactionCosts

get_costs(fid, real_date)[source]#
Return type:

Series

static extrapolate_cost(trade_size, median_size, median_cost, pct90_size, pct90_cost)[source]#
Return type:

Number

bidoffer(fid, trade_size, real_date)[source]#
Return type:

Number

rollcost(fid, trade_size, real_date)[source]#
Return type:

Number

plot_costs(fids=None, cost_type='BIDOFFER', ncol=8, x_axis_label='Trade size (USD, millions)', y_axis_label='Percent of outright forward', title=None, title_fontsize=28, facet_title_fontsize=20, *args, **kwargs)[source]#
class TransactionCostsDictAdapter(cost_dict, fids=None)[source]#

Bases: object

Adapter that exposes the TransactionCosts cost methods (bidoffer and rollcost) from a static, nested cost dictionary.

The dictionary is keyed by financial contract identifier (fid). Each fid carries one entry per cost type - bid_offer and rollcost - and each cost type records two properties, size and cost, at two anchors, median and pct90:

{
    "EUR_FX": {
        "bid_offer": {
            "size": {"median": 35,  "pct90": 90},
            "cost": {"median": 0.2, "pct90": 0.4},
        },
        "rollcost": {
            "size": {"median": 35,  "pct90": 90},
            "cost": {"median": 0.1, "pct90": 0.2},
        },
    },
}

The size and cost anchors feed TransactionCosts.extrapolate_cost exactly as the panel-backed TransactionCosts object does, so the two are interchangeable wherever a cost object is expected.

COST_TYPES = ('bid_offer', 'rollcost')#
PROPERTIES = ('size', 'cost')#
ANCHORS = ('median', 'pct90')#
check_init()[source]#
Return type:

bool

bidoffer(fid, trade_size, real_date=None)[source]#
Return type:

Number

rollcost(fid, trade_size, real_date=None)[source]#
Return type:

Number

bidoffer_heatmap(trade_sizes=(25, 50, 100), title='Implied bidoffer costs by ticket size', xlabel='Fid', ylabel='Ticket size (USD millions)', fid_names=None, figsize=(10, 5), show_as_bps=False, title_fontsize=14)[source]#
Return type:

None

rollcost_heatmap(trade_sizes=(25, 50, 100), title='Implied roll costs by size', xlabel='Fid', ylabel='Roll size (USD millions)', fid_names=None, figsize=(10, 5), show_as_bps=False, title_fontsize=14)[source]#
Return type:

None

class ExampleAdapter(*args, **kwargs)[source]#

Bases: TransactionCosts

static extrapolate_cost(trade_size, median_size, median_cost, pct90_size, pct90_cost)[source]#
Return type:

Number

bidoffer(fid, trade_size, real_date)[source]#
Return type:

Number

somecalc(fid, trade_size, real_date, factor=1)[source]#
Return type:

Number