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

extrapolate_cost_from_dict(cost_dict, fid, trade_size, fids=None)[source]#

Compute transaction costs from a static cost dictionary.

Parameters:
  • cost_dict (Optional[Mapping[str, Mapping[str, Number]]]) – Mapping of fid to extrapolate_cost arguments. If None, returns NaN.

  • fid (str) – Financial contract identifier to query in cost_dict.

  • trade_size (Number) – Trade size in USD mn.

  • fids (Optional[List[str]]) – Optional list of traded fids to validate cost_dict coverage.

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 TransactionCosts-style methods using a static cost dictionary.

check_init()[source]#
Return type:

bool

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

Number

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

Number

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