Ë
    '�±j}  ã                   ó\   — d Z ddlZddlmc mZ ddlZddl	Z
ddlmZ ddlmZ d„ Zd„ Zd„ Zy)z<Execution sensitivity is different from raw-score proximity.é    N)Ú_score_to_signals)Ú	evaluatorc                  ó€  ‡— t        «       } t        j                  t        g d¢g d¢g d¢¬«      «      Št        ddddd¬	«      }| j                  }‰j
                  }d
} ||||«      }d}||k(  }|�skt        j                  d|fd||f«      dt        j                  «       v st        j                  | «      rt        j                  | «      ndt        j                  |«      dt        j                  «       v st        j                  ‰«      rt        j                  ‰«      ndt        j                  |«      dt        j                  «       v st        j                  |«      rt        j                  |«      ndt        j                  |«      t        j                  |«      t        j                  |«      dœz  }dd|iz  }	t        t        j                  |	«      «      ‚d x}x}x}x}x}}ˆfd„}
 |
|«      }dD ]E  } |
t        |d|z   ¬«      «      }dD ](  }t        j                  j!                  ||   ||   «       Œ* ŒG y )N)g      i@g      I@g\�Âõ(@pÀg     €k@g      D@)g      Y@ç     @Y@g     €Y@r   g      Z@)Úactivation_scoreÚcloseÚhighg     €V@g     @j@g     @pÀFg      4@)Ú!i_long_entry_activation_thresholdÚ i_long_exit_activation_thresholdÚ-i_long_exit_activation_confirmation_thresholdÚi_use_long_exit_confirmationÚi_trailing_stop_thresholdçš™™™™™©?é   ©ú==)zŽ%(py10)s
{%(py10)s = %(py2)s
{%(py2)s = %(py0)s.fragile_count
}(%(py5)s
{%(py5)s = %(py3)s.activation_score
}, %(py6)s, %(py8)s)
} == %(py13)sÚmoduleÚframeÚparams)Úpy0Úpy2Úpy3Úpy5Úpy6Úpy8Úpy10Úpy13zassert %(py15)sÚpy15c                 óÄ   •— t        ‰j                  «       | t        j                  d«      ‰j                  j                  «       ‰j                  j                  «       «      S )Né   )r   ÚcopyÚnpÚonesr   Úto_numpyr	   )Úpr   s    €úA/Users/jameslopez/projects/TradingBot25/tests/test_mlp_revisit.pyÚreplayzQtest_disabled_confirmation_can_be_flagged_without_changing_trades.<locals>.replay   sA   ø€ Ü  §¡£¨q´"·'±'¸!³*¸e¿k¹k×>RÑ>RÓ>TÐV[×V`ÑV`×ViÑViÓVkÓlÐló    )g      ð¿gš™™™™™©¿r   g      ð?)r   ©ÚpositionÚexecute_entryÚexecute_exit)r   ÚpdÚ	DataFrameÚdictÚfragile_countr   Ú
@pytest_arÚ_call_reprcompareÚ@py_builtinsÚlocalsÚ_should_repr_global_nameÚ	_safereprÚAssertionErrorÚ_format_explanationr"   ÚtestingÚassert_array_equal)r   r   Ú@py_assert1Ú@py_assert4Ú@py_assert7Ú@py_assert9Ú@py_assert12Ú@py_assert11Ú@py_format14Ú@py_format16r'   ÚbaseÚdeltaÚ	candidateÚkeyr   s                  @r&   ÚAtest_disabled_confirmation_can_be_flagged_without_changing_tradesrG   	   s•  ø€ Ü‹[€FÜ�L‰LœÒ/NÚ$BÚ#AôCó D€Eô °CØ37Ø@EØ/4ÐPSôU€Fð ×ÑÐJ × 6Ñ 6ÐJÀÐJÑÐ 6¸ÀÓEÐJÈÐJÐEÈÑJ×J×JÖJÐEÈ×J×J×J×J×JÑJˆ6×J×JÓJˆ6×J×JÔJÐ×J×J×J×J×JÐJ ×J×JÓJ ×J×JÔJÐ 6×J×J×J×J×JÐJ¸×J×JÓJ¸×J×JÔJÀ×J×JÒJÐE×J×JÒJÈ×J×J×J×J×J×J×JÑJômá�&‹>€DÛ%ˆÙœ4 ÐV[Ð\aÑVaÔbÓcˆ	Û@ˆCÜ�J‰J×)Ñ)¨$¨s©)°Y¸s±^ÕDñ Añ &r(   c                  ó€  — ddl m}  dD ��cg c]%  }t        d«      D ]  }t        d||dœd|dz  i¤Ž‘Œ Œ' }}} | ||d   gdd	g«      }|d   g}dd	g} | |||«      }||k(  }|�sCt	        j
                  d
|fd||f«      dt        j                  «       v st	        j                  |«      rt	        j                  |«      nddt        j                  «       v st	        j                  | «      rt	        j                  | «      nddt        j                  «       v st	        j                  |«      rt	        j                  |«      ndt	        j                  |«      t	        j                  |«      t	        j                  |«      dœz  }	dd|	iz  }
t        t	        j                  |
«      «      ‚d x}x}x}}d„ |D «       }t        |«      }d}||k(  }|sÉt	        j
                  d
|fd||f«      dt        j                  «       v st	        j                  t        «      rt	        j                  t        «      ndt	        j                  |«      t	        j                  |«      t	        j                  |«      dœz  }dd|iz  }	t        t	        j                  |	«      «      ‚d x}x}x}}|D �ch c]  }|d   d   |d   d	   f’Œ }}t        |«      }t        |«      }||k(  }|�sSt	        j
                  d
|fd||f«      dt        j                  «       v st	        j                  t        «      rt	        j                  t        «      ndt	        j                  |«      t	        j                  |«      dt        j                  «       v st	        j                  t        «      rt	        j                  t        «      nddt        j                  «       v st	        j                  |«      rt	        j                  |«      ndt	        j                  |«      dœz  }	dd|	iz  }
t        t	        j                  |
«      «      ‚d x}x}x}}y c c}}w c c}w )Nr   )Úselect_centers)ÚaÚbé   )Úmlp_weights_fileÚxzFragile_0.05é   rM   rN   r   )zB%(py0)s == %(py9)s
{%(py9)s = %(py2)s(%(py3)s, %(py5)s, %(py7)s)
}ÚselectedrI   Úrows)r   r   r   r   Úpy7Úpy9zassert %(py11)sÚpy11c              3   ó&   K  — | ]	  }|d    –— Œ y­w)ÚsampleN© )Ú.0rN   s     r&   Ú	<genexpr>zItest_sample_is_balanced_deterministic_and_deduplicated.<locals>.<genexpr>"   s   è ø€ Ð-¡H˜qˆq��{¡Hùs   ‚é(   )z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)sÚsum)r   r   Úpy4rR   zassert %(py9)srS   r   )zN%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py9)s
{%(py9)s = %(py6)s(%(py7)s)
}Úlen)r   r   r\   r   rR   rS   rW   )Útools.run_mlp_revisitrI   Úranger/   r1   r2   r3   r4   r5   r6   r7   r8   r[   r]   )rI   ÚmodelÚirQ   rP   r<   Ú@py_assert6Ú@py_assert8r;   Ú@py_format10Ú@py_format12Ú@py_assert3Ú@py_assert5Ú@py_format8rN   s                  r&   Ú6test_sample_is_balanced_deterministic_and_deduplicatedri      sÂ  € Ý4á#ô8Ù#�¬U°2®Y¨ô ÐH %¨1ÑH°ÀÀQÁÐ0GÓHØ-6ð IØ#ð 	ñ 8á˜d T¨!¡W IÐ0BÀCÐ/HÓI€HØ-1°!©W¨IÐQÐ8JÈCÐ7PÐQ‘~ d¨IÐ7PÓQÐQˆ8ÐQÑQ×Q×QÖQˆ8ÐQ×Q×Q×Q×Q×QÑQˆ8×Q×QÓQˆ8×Q×Q×Q×Q×QÒQ�~×Q×QÓQ�~×Q×Q×Q×Q×QÒQ d×Q×QÓQ d×Q×QÔQ¨I×Q×QÒQÐ7P×Q×QÒQÐQ×Q×Q×Q×Q×Q×QÕQÙ-¡HÓ-Ð3Œ3Ð-Ó-Ð3°Ð3Ð-°Ñ3×3×3Õ3Ð-°×3×3×3×3×3Ñ3Œ3×3×3Ó3Œ3×3×3Ô3Ð-×3×3Ò3Ð-×3×3Ò3°×3×3×3×3×3×3Õ3ÙMUÓVÉXÈ��8‘Ð/Ñ0°!°H±+¸cÑ2BÒCÈXÐhÐVŒ3ÐVÓWÐhÔ[^Ð_gÓ[hÐhÐWÐ[hÑh×h×hÖhÐWÐ[h×h×h×h×h×hÑhŒ3×h×hÓhŒ3×h×hÔhÐV×h×hÒhÐW×h×h×h×h×hÐhÔ[^×h×hÓhÔ[^×h×h×h×h×hÒhÐ_g×h×hÓhÐ_g×h×hÔhÐ[h×h×h×h×h×h×hÖhùó8ùò
 Ws   Œ*P5Ê"P;c                  óê  — ddl m}  t        j                  j	                  d«      }t        j                  t        |j                  ddd«      t        j                  |j                  ddd«      j                  «       «      dz  ¬«      «      }|j                  d	z  |d
<   ddit        j                  d«      |j                  j                  «       |j                  j                  «       f}t        |j!                  «       g|¢­Ž }  | d«      |j!                  «       g|¢­Ž }dD ](  }t        j"                  j%                  ||   ||   «       Œ* dD ]¢  }  | |«      |j!                  «       g|¢­Ž }dD ]~  }	  | |«      |j&                  d |	 j!                  «       |d   |d   d |	 |d   d |	 |d   d |	 «      }
dD ]5  }t        j"                  j%                  ||   j&                  d |	 |
|   «       Œ7 Œ€ Œ¤ y )Nr   )Úgate_signalé   i,  é–   g¸…ëQ¸ž?éd   )r   r   g)\�Âõ(ð?r	   r   g      @r)   )rO   é   é   )é   é9   rn   r   rO   ro   )r^   rk   r"   ÚrandomÚdefault_rngr-   r.   r/   ÚnormalÚexpÚcumsumr   Úzerosr$   r	   r   r!   r9   r:   Úiloc)rk   Úrngr   ÚargsÚ	canonicalÚdisabledrF   ÚwidthÚwholeÚendÚprefixs              r&   Ú@test_gate_replay_is_prefix_causal_and_disabled_gate_is_identicalr‚   &   sÃ  € Ý1Ü
�)‰)×
Ñ
 Ó
#€CÜ�L‰Lœ¨s¯z©z¸!¸SÀ#Ó/FÜ�f‰f�S—Z‘Z  3¨Ó,×3Ñ3Ó5Ó6°sÑ:ô<ó =€Eà—K‘K $Ñ&€Eˆ&�MØ(¨"Ð-¬r¯x©x¸«}¸e¿k¹k×>RÑ>RÓ>TÐV[×V`ÑV`×ViÑViÓVkÐl€DÜ! %§*¡*£,Ð6°Ò6€IØ‰{˜1‹~˜eŸj™j›lÐ2¨TÒ2€HÛ<ˆÜ
�
‰
×%Ñ% i°¡n°h¸s±mÕDð =ãˆØ"‘˜EÓ" 5§:¡:£<Ð7°$Ò7ˆÛ ˆCØ'‘[ Ó'¨¯
©
°4°CÐ(8×(=Ñ(=Ó(?ÀÀaÁÈ$ÈqÉ'ÐRVÐSVÈ-ÐY]Ð^_ÑY`ÐaeÐbeÐYfÐhlÐmnÑhoÐptÐqtÐhuÓvˆFÛD�Ü—
‘
×-Ñ-¨e°C©j¯o©o¸d¸sÐ.CÀVÈCÁ[ÕQñ Eñ !ñ r(   )Ú__doc__Úbuiltinsr3   Ú_pytest.assertion.rewriteÚ	assertionÚrewriter1   Únumpyr"   Úpandasr-   Ústrategies.strategy_mlp_scoresr   Ú#tools.run_mlp_entry_loss_experimentr   rG   ri   r‚   rW   r(   r&   Ú<module>rŒ      s+   ðÙ Bß  „ Ó Û å <Ý 9òEò&ióRr(   