investos.portfolio.strategy package

Submodules

investos.portfolio.strategy.base_strategy module

class investos.portfolio.strategy.base_strategy.BaseStrategy(actual_returns: ~pandas.core.frame.DataFrame, costs: [<class 'investos.portfolio.cost_model.base_cost.BaseCost'>] = [], constraints: [<class 'investos.portfolio.constraint_model.base_constraint.BaseConstraint'>] = [], **kwargs)

Bases: object

Base class for an optimization strategy.

Must implement generate_trade_list() as per below.

costs

Cost models evaluated during optimization strategy. Defaults to empty list. See BaseCost for cost model base class.

Type:

list

constraints

Constraints applied for optimization strategy. Defaults to empty list. See [TBU] for optimization model base class.

Type:

list

generate_trade_list(holdings: Series, t: datetime) Series

Calculates and returns trade list (in units of currency passed in), given (added) optimization logic.

Parameters:
  • holdings (pandas.Series) – Holdings at beginning of period t.

  • t (datetime.datetime) – The datetime for associated holdings holdings.

get_actual_positions_for_t(h: Series, u: Series, t: datetime) Series

Calculates and returns actual positions, after accounting for trades and costs during period t.

metadata_dict()

investos.portfolio.strategy.rank_long_short module

class investos.portfolio.strategy.rank_long_short.RankLongShort(actual_returns: ~pandas.core.frame.DataFrame, metric_to_rank: ~pandas.core.frame.DataFrame, n_periods_held: int = 1, leverage: float = 1, ratio_long: float = 1, ratio_short: float = 1, percent_short: float = 0.25, percent_long: float = 0.25, costs: [<class 'investos.portfolio.cost_model.base_cost.BaseCost'>] = [], **kwargs)

Bases: BaseStrategy

Optimization strategy that builds trade list by going long assets with best return forecasts and short stocks with worst return forecasts.

costs

Cost models evaluated during optimization strategy.

Type:

list[BaseCost]

percent_short

Percent of assets in forecast returns to go short.

Type:

float

percent_long

Percent of assets in forecast returns to go long.

Type:

float

leverage

Absolute value of exposure / AUM. Used to calculate holdings.

Type:

float

n_periods_held

Number of periods positions held. After n number of periods, positions unwound.

Type:

integer

generate_trade_list(holdings: Series, t: datetime) Series

Calculates and returns trade list (in units of currency passed in) by going long top percent_long assets and short bottom percent_short assets.

Parameters:
  • holdings (pandas.Series) – Holdings at beginning of period t.

  • t (datetime.datetime) – The datetime for associated holdings holdings.