azapy.Selectors package

Submodules

azapy.Selectors.CorrClusterSelector module

class azapy.Selectors.CorrClusterSelector.CorrClusterSelector(pname='CorrCluster', corr_threshold=0.95, freq='Q', ftype='f13612w', fw=None, col_price='adjusted', hlength=1)

Bases: NullSelector

Selects symbols with lower inter-correlation.

Attributes
  • pname : str - portfolio name

  • mkt : pandas.DataFrame - selection’s market data

  • symb : list - selected symbols

  • symb_omitted : list - unselected symbols

  • capital : float - always set to 1

Methods

getSelection(mktdata, **params)

Computes the selection.

__init__(pname='CorrCluster', corr_threshold=0.95, freq='Q', ftype='f13612w', fw=None, col_price='adjusted', hlength=1)

Constructor

Parameters:
pnamestr, optional

Selector name. The default is ‘DualMomentum’.

corr_thresholdfloat, optional

Cluster correlation threshold (i.e., a cluster contains only symbols with inter-correlation higher than corr_threshold. The default is 0.95.

freqstr, optional

The horizon of rates subject to correlation estimations. It can be either ‘M’ for monthly or ‘Q’ for quarterly rates. The default is ‘Q’.

ftypestr, optional

Inner-cluster filter (i.e., criteria to designate the representative of a cluster with more than one symbol). At this point only ‘f13612w’ is implemented. The default is ‘f13612w’.

fwlist, optional

List of filter wights. For ‘f13612w’ it must be a list of 4 positive (not all zero) numbers. A value of None indicates equal weights. Note: the weights are normalized internally. The default is None.

col_pricestr, optional

The name of the pricing column to be considered in computations. The default is ‘adjusted’.

hlength‘float’, optional

History length in number of years used for calibration. A fractional number will be rounded to an integer number of months. The default is 1 years.

Returns:
The object.
getSelection(mktdata, **params)

Computes the selection.

Parameters:
mktdatapandas.DataFrame

MkT data in the format produced by the azapy function readMkT.

**paramsdict, optional
Other optional parameters:
verboseBoolean, optional

When it is set to True, the selection symbols are printed. The default is ‘False’.

viewBoolean, optional

If set to True, then the dendrogram of hierarchical classification is printed out. The default is False. Note: the tree cutoff is at 1 - corr_threshold level.

Returns:
(capital, mkt)tuple
capitalfloat

Fraction of capital allocated to the selection. For this selector it is always 1.

mktpandas.DataFrame

Selection MkT data in the format produced by the azapy function readMkT.

azapy.Selectors.DualMomentumSelector module

class azapy.Selectors.DualMomentumSelector.DualMomentumSelector(pname='DualMomentum', ftype='f13612w', fw=None, nw=3, threshold=6, col_price='adjusted', **kwargs)

Bases: NullSelector

Dual Momentum Selector.

Given a filter it selects the best candidates among the once with highest moment.

Attributes
  • pname : str - portfolio name

  • mkt : pandas.DataFrame - selection’s market data

  • rank : pandas.Series - filter rank of all symbols

  • symb : list - selected symbols

  • symb_omitted : list - unselected symbols

  • capital : float - capital at risk as a fraction of the total capital

Methods

getSelection(mktdata, **params)

Computes the selection.

__init__(pname='DualMomentum', ftype='f13612w', fw=None, nw=3, threshold=6, col_price='adjusted', **kwargs)

Constructor

Parameters:
pnamestr, optional

Selector name. The default is ‘DualMomentum’.

ftypestr, optional

The filter name (at this point only ‘f13612w’ filter is supported). The default is ‘f13612w’ are equal weights.

fwlist, optional

List of filter wights. For ‘f13612w’ it must be a list of 4 positive (not all zero) numbers. A value of None indicates equal weights. Note: the weights are normalized internally. The default is None.

nwint, optional

Maximum number of selected symbols. The default is 3.

thresholdint, optional

Minimum number of symbols with positive momentum for a full capital allocation. The default is 6.

col_pricestr, optional

Name of the price column in the mktdata to be used in the momentum evaluations. The default is ‘adjusted’.

**kwargsdict, optional

Holder for other args.

Returns:
The object.
getSelection(mktdata, **params)

Computes the selection.

Parameters:
mktdatapandas.DataFrame

MkT data in the format produced by the azapy function readMkT.

**paramsdict, optional
Other optional parameters:
verboseBoolean, optional

When it is set to True, the selection symbols are printed. The default is False.

Returns:
(capital, mkt)tuple
capitalfloat

Fraction of capital allocated to the selection (a positive number <= 1, 1 being full allocation). One minus this value is the fraction of reserved capital invested in cash.

mktpandas.DataFrame

Selection MkT data in the format produced by the azapy function readMkT.

azapy.Selectors.NullSelector module

class azapy.Selectors.NullSelector.NullSelector(pname='NullSelector')

Bases: object

Null Selector - produces no selection.

Its main purpose is to serve as a base class and to provide consistency across the selector family.

Methods

getSelection(mktdata, **params)

Produces the selection.

__init__(pname='NullSelector')

Constructor

Parameters:
pnamestr, optional

Selector name. The default is ‘NullSelector’.

Returns:
The object
getSelection(mktdata, **params)

Produces the selection.

Parameters:
mktdatapandas.DataFrames

Market data in the format produced by the azapy function readMKT.

**paramsdict, optional
Additional optional parameters:
verboseBoolean, optional

When it is set to True, the selection symbols are printed.

Returns:
(capital, mkt)tuple
  • capital : float, always set to 1.

  • mkt : pandas.DataFrame, always the input mktdata

Module contents