mlfinlab.sample_weights.attribution
Logic regarding return and time decay attribution for sample weights from chapter 4. And stacked sample weights logic: return and time based sample weights for a multi-asset dataset.
Module Contents
Functions
|
Advances in Financial Machine Learning, Snippet 4.10(part 2), page 69. |
|
Advances in Financial Machine Learning, Snippet 4.11, page 70. |
- get_weights_by_return(triple_barrier_events, close_series, num_threads=5, verbose=True)
-
Advances in Financial Machine Learning, Snippet 4.10(part 2), page 69.
Determination of Sample Weight by Absolute Return Attribution
This function is orchestrator for generating sample weights based on return using mp_pandas_obj.
- Parameters:
-
-
triple_barrier_events – (pd.DataFrame) Events from labeling.get_events().
-
close_series – (pd.Series) Close prices.
-
num_threads – (int) The number of threads concurrently used by the function.
-
verbose – (bool) Flag to report progress on asynch jobs.
-
- Returns:
-
(pd.Series) Sample weights based on number return and concurrency.
- get_weights_by_time_decay(triple_barrier_events, close_series, num_threads=5, decay=1, verbose=True)
-
Advances in Financial Machine Learning, Snippet 4.11, page 70.
Implementation of Time Decay Factors.
- Parameters:
-
-
triple_barrier_events – (pd.DataFrame) Events from labeling.get_events().
-
close_series – (pd.Series) Close prices.
-
num_threads – (int) The number of threads concurrently used by the function.
-
decay – (int) Decay factor - decay = 1 means there is no time decay; - 0 < decay < 1 means that weights decay linearly over time, but every observation still receives a strictly positive weight, regadless of how old; - decay = 0 means that weights converge linearly to zero, as they become older; - decay < 0 means that the old portion c of the observations receive zero weight (i.e they are erased from memory).
-
verbose – (bool) Flag to report progress on asynch jobs.
-
- Returns:
-
(pd.Series) Sample weights based on time decay factors.