The repository expands the Triple-Barrier Method proposed by Marcos López de Prado. It introduces specific enhancements:
- Extension to Multiple Barrier Conditions: Dynamically generates multiple barriers through the
n_barriersparameter. - Centering Capability: Includes a
centerparameter to center the returns for improved analysis. - Improved Readability: Utilizes standard data science toolkit with
pandasandnumpyinstead of for-loops for each time-steptto improve readability and efficiency. - Exporting Intermediate Steps: Allows to view intermediate steps as features for model usage (
_check_barrier_crossing()method). - Convenient Properties: Provides useful properties such as
transition_probabilitiesandsignals_pa.
This repository includes two notebooks:
-
example.ipynb: Provides an example showcasing the usage of theBarrierMethodclass. -
study.ipynb: Generates various labels for a range of n and different barriers and tests them for a normal and uniform distribution.For some use cases, the goal might be to have (on average) a new signal each week that is approx. normal distributed (neutral most of the time, rare tails) or uniformly distributed.
The traditional approach to labeling data involves a fixed-time horizon. However, Marcos López de Prado introduced the Triple-Barrier Method in his book Advances in Financial Machine Learning (Wiley, 2018). This method constructs three barriers for each observation:
- Stop-loss Barrier (
-1): Indicates a selling opportunity. - Neutral Signal (
0): Denotes a scenario where the time series doesn't cross any barrier within a maximum holding period ofn. - Profit-taking Barrier (
+1): Signifies a buying opportunity.
pip install git+https://github.com/nkonts/barrier-method.git


