investos.util module

investos.util.deep_dict_merge(default_d, update_d)

Deep copies update_d onto default_d recursively

investos.util.get_max_key_lt_or_eq_value(dictionary, value)

Returns the maximum key in the dictionary that is less than or equal to the given value. If no such key exists, returns None.

Useful for looking up values by datetime.

investos.util.remove_excluded_columns_np(np_arr, holdings_cols, exclude_assets=None, include_assets=None)
investos.util.remove_excluded_columns_pd(arg, exclude_assets=None, include_assets=None)
investos.util.values_in_time(obj, t, tau=None, lookback_for_closest=False)

From CVXPortfolio:

Obtain value(s) of object at time t, or right before.

Optionally specify time tau>=t for which we want a prediction, otherwise it is assumed tau = t.

obj: callable, pd.Series, pd.DataFrame, or something else.

If a callable, we return obj(t,tau).

If obj has an index attribute, we try to return obj.loc[t], or obj.loc[t, tau], if the index is a MultiIndex. If not available, we return obj.

Otherwise, we return obj.

t: np.Timestamp (or similar). Time at which we want

the value.

tau: np.Timestamp (or similar), or None. Time tau >= t

of the prediction, e.g., tau could be tomorrow, t today, and we ask for prediction of market volume tomorrow, made today. If None, then it is assumed tau = t.