Files
AlphaFlow-MT5-ML-DL-Trading…/features/__pycache__/labeling_schemes.cpython-312.pyc
T

56 lines
5.5 KiB
Plaintext
Raw Normal View History

2025-03-02 22:25:33 +01:00
Ë
óI¸g0ãórddlZddlZd
dejdedejfdZd dZd dZd dZd
d „Z y)édfÚhorizonÚreturncóx|dj|¬«j| «|d<|jdg¬«S)
Calculates future returns for a given horizon. By default, horizon=1
means next-bar returns. The function appends a new column 'future_returns'.
Úclose©ÚperiodsÚfuture_returns)Úsubset)Ú
pct_changeÚshiftÚdropna)rrs úJc:\Users\moham\OneDrive\AlphaFlow Trading Bot\features\labeling_schemes.pyÚcalculate_future_returnsrsCð
˜g™;×1¸B×HÈ'ÈÓR€BÐÑØ
9‰9Ð.ˆ có|j«}|dj|¬«j| «|d<d|d<d|j|d|k\df<d|j|d| kdf<|j dgd¬ «|S)
aq
Creates classification labels for a multi-bar horizon.
+1 if future return >= +threshold
-1 if future return <= -threshold
0 otherwise (could keep as neutral or drop).
df must have a 'close' column.
Returns a new DataFrame with:
- 'future_return_h' (the h-bar future return)
- 'multi_bar_label' (the classification label)
rrÚfuture_return_hrÚmulti_bar_labelééÿÿÿÿT©r Úinplace)Úcopyr r
Úlocr)rrÚ thresholdÚdf_copys rÚcreate_labels_multi_barr
ðg‰gi€Gð")¨Ñ!1×!<Ñ!<ÀWÐ!<Ó!M×!SÑ!SÐU\ÐT\Ó!]€GÐ Ñð"#€GÐ ÑØNO€G‡KKÐ*¨iÑ7Ð9JÐKØOQ€G‡KKÐ*¨y¨jÑ8Ð:KÐ ‡N-°t€NÔ
€NrcóÔ|j«}|dj}tjt |«tj
«}t
t |««D]}||}|d|zz} |d|z
z}
t||zt |««} t
|dz| «D] } || | k\rd||<n|| |
ksŒd||<ntj||«sŒ{d||<Œ||d<|S)
Double-barrier labeling:
- For each index i, define:
upper_barrier = close_i * (1 + up)
lower_barrier = close_i * (1 - down)
- Look ahead up to 'horizon' bars to see which barrier is touched first.
- Label = +1 if upper barrier touched first,
-1 if lower barrier touched first,
0 if neither is touched within horizon.
df must have a 'close' column.
Returns a new DataFrame with a 'barrier_label' in {-1, 0, +1}.
rrrrÚ
barrier_label© rÚvaluesÚnpÚfullÚlenÚnanÚrangeÚminÚisnan©
rÚupÚdownrrÚclosesÚlabelsÚ
current_priceÚ
upper_barrierÚ
lower_barrierÚendÚfwd_is
rÚcreate_labels_double_barrierr4,ðg‰g‹i€GØ

×
$€Fä
W‰W”S˜“[¤"§&¡&Ó
)€Fä
”3v“;Ö
ˆØ˜q™ ˆ
بR©Ñ0ˆ