+
    ;j  c                   N   R t ^ RIt^ RIHu Ht ^ RIt^ RIt^ RI	t	]P                  P                  ]P                  P                  ]P                  P                  ]4      R4      4      t]P                  P!                  ^ ]4       ^ RIHtHtHt R tR tR tR tR tR	 tR
 tR# )a  
Commission-awareness of tools/compare_tv_trades.py
===================================================

Guards the parity comparator's P&L against the "no commission" footgun: TV's
per-trade Net PnL % is commission-inclusive, so the Python side must pay the
same 0.5%/side commission or the constant ~1%/trade offset compounds into a
misleading multi-x cumulative gap (BTC 6H once read 7,649% gross vs 2,553% TV).

The model must stay identical to strategies/validate_strategy.py.
Nz..)COMMISSION_RATEnet_pnl_pctextract_python_tradesc                n    V ^V,           ,          pV^V,
          ,          pWC,
          V,          ^d,          # )zGRe-implementation of the exact formula in validate_strategy.py:210-213. )entry_pxexit_pxrate	eff_entryeff_exits   &&&  K/Users/jameslopez/projects/TradingBot25/tests/test_compare_tv_commission.py_validate_strategy_modelr      s1    AH%I!d(#H I-33    c                     R p \         V 8H  q'       g   \        P                  ! RV3R\         V 34      RR\        P                  ! 4       9   g!   \        P
                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V 4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;rR# )	g{Gzt?py0r   py3zassert %(py5)spy5N==)z%(py0)s == %(py3)s)	r   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation)@py_assert2@py_assert1@py_format4@py_format6s       r   4test_default_rate_matches_pine_and_validate_strategyr       sd    ##?e#####?e######?####?###e########r   c                     R EF  w  r\        W4      p\        P                  p\        W\        4      qC! V4      qRV8H  qf'       Eg5   \
        P                  ! RV3RW%34      RR\        P                  ! 4       9   g!   \
        P                  ! \         4      '       d   \
        P                  ! \         4      MRRR\        P                  ! 4       9   g   \
        P                  ! V 4      '       d   \
        P                  ! V 4      MRRR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRR\
        P                  ! V4      RR	\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MR	R
\
        P                  ! V4      RR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRRR\        P                  ! 4       9   g   \
        P                  ! V 4      '       d   \
        P                  ! V 4      MRRR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRRR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRR\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;p;p;rEEK  	  R# )      Y@r   r   py1r   py2r   py4py6pytestpy8py9r   py10py11py12r   py14py16zassert %(py18)spy18N))r"        [@)g      i@g     b@)gq=
C@g@r   )z%(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
} == %(py16)s
{%(py16)s = %(py8)s
{%(py8)s = %(py6)s.approx
}(%(py14)s
{%(py14)s = %(py9)s(%(py10)s, %(py11)s, %(py12)s)
})
})r   r'   approxr   r   r   r   r   r   r   r   r   r   )	r   r   @py_assert3@py_assert7@py_assert13@py_assert15@py_assert5@py_format17@py_format19s	            r   .test_net_pnl_matches_validate_strategy_formular9   $   s    T8- 	
 	
$XH	
H2
 	
 2
 
 	
 	
 	
- 	
 	
	6	
 	
 	
{ 	
 	
 			
{ 	
 	
	6	
 	
 	
8 	
 	
 			
8 	
 	
	6	
 	
 	
W 	
 	
 			
W 	
 	
 			
- 	
 	
	6	
 	
 	
 	
 	
 			
 	
 	
 			
 	
 	
	6	
 	
 	
$	
 	
 			
$	
 	
	6	
 	
 	
%-	
 	
 			
%-	
 	
	6	
 	
 	
/6	
 	
 			
/6	
 	
	6	
 	
 	
8G	
 	
 			
8G	
 	
 			
H	
 	
 			
 2
 	
 	
 	
 	
 	
 	
 	
 	
 Tr   c                     R RrW,
          V ,          ^d,          p\        W4      pW28  qD'       g   \        P                  ! RV3RW234      RR\        P                  ! 4       9   g   \        P
                  ! V4      '       d   \        P                  ! V4      MRRR\        P                  ! 4       9   g   \        P
                  ! V4      '       d   \        P                  ! V4      MR/,          pRRV/,          p\        \        P                  ! V4      4      hRpW#,
          p\        P                  pR	p	R
q! WR7      qV8H  q'       Eg   \        P                  ! RV3RW{34      RR\        P                  ! 4       9   g   \        P
                  ! V4      '       d   \        P                  ! V4      MRRR\        P                  ! 4       9   g   \        P
                  ! V4      '       d   \        P                  ! V4      MRRR\        P                  ! 4       9   g!   \        P
                  ! \        4      '       d   \        P                  ! \        4      MRR\        P                  ! V4      R\        P                  ! V	4      R\        P                  ! V
4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;p;p	;rR# )r"   r0   r   netr$   grosszassert %(py4)sr%   NgQ?g?absr#   r'   r&   r(   r*   r,   zassert %(py14)sr-   <)z%(py0)s < %(py2)sr   )zh(%(py0)s - %(py1)s) == %(py12)s
{%(py12)s = %(py6)s
{%(py6)s = %(py4)s.approx
}(%(py8)s, abs=%(py10)s)
})r   r   r   r   r   r   r   r   r   r'   r1   )r   r   r<   r;   r   @py_format3@py_format5r   r6   r3   @py_assert9@py_assert11r2   @py_format13@py_format15s                  r   8test_net_is_below_gross_by_roughly_round_trip_commissionrG   .   s   ug8+c1E
h
(C;333K:FMM:%:T:M%::::::::K::::::E::::E:::::::C::::C:::::::F::::F:::M:::%:::T:::::::::::::r   c                     \        R R 4      p \        P                  pRq") pRqA! W4R7      qPV8H  qf'       EgI   \        P                  ! RV3RW34      RR\
        P                  ! 4       9   g   \        P                  ! V 4      '       d   \        P                  ! V 4      MRRR\
        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRR\        P                  ! V4      R	\        P                  ! V4      R
\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;p;p;rER# )r"   gףp=
?g{Gz?r=   r   r;   r$   r'   r%   r&   r)   r+   zassert %(py13)spy13Nr   )z\%(py0)s == %(py11)s
{%(py11)s = %(py4)s
{%(py4)s = %(py2)s.approx
}(-%(py6)s, abs=%(py9)s)
}r   r'   r1   r   r   r   r   r   r   r   r   )	r;   r2   r6   r3   @py_assert8@py_assert10r   @py_format12@py_format14s	            r   +test_flat_trade_loses_round_trip_commissionrO   7   s    
eU
#C--111D1-1111111131111113111131111111&1111&111-111111D1111111111111r   c                  "   R RrW,
          V ,          ^d,          pRp\        WVR7      p\        P                  qU! V4      qdV8H  qw'       Eg;   \        P                  ! RV3RWF34      RR\
        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRRR\
        P                  ! 4       9   g   \        P                  ! V 4      '       d   \        P                  ! V 4      MRRR	\
        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR	R
\        P                  ! V4      R\        P                  ! V4      RR\
        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRR\        P                  ! V4      RR\
        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      /	,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;p;p;rVR# )r"   g     0a@g        )commission_rater   r   r#   r   r$   r   r%   r&   r(   r'   r*   r+   r<   rI   zassert %(py15)spy15Nr   )z%(py6)s
{%(py6)s = %(py0)s(%(py1)s, %(py2)s, commission_rate=%(py4)s)
} == %(py13)s
{%(py13)s = %(py10)s
{%(py10)s = %(py8)s.approx
}(%(py11)s)
}rJ   )
r   r   r<   r2   r6   rC   @py_assert12r3   rN   @py_format16s
             r   !test_zero_commission_equals_grossrU   =   sQ   ug8+c1E:=V;x#>V&--V-PUBVVBVVVVVV>VVVVVV;VVVV;VVVVVVVxVVVVxVVVVVVVVVVVVVV#VVV>VVVVVV&VVVV&VVV-VVVVVVPUVVVVPUVVVBVVVVVVVVVVr   c                  2
   ^ RI p V P                  RV P                  . R!O4      R. R"OR. R#OR. R$O/4      p\        V4      p\	        V4      p^qCV8H  qU'       Eg   \
        P                  ! R%V3R&W434      RR	\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MR	R
R\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRR\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;rTV^ ,          pVR,          p	\        P                  pRq! V
4      qV8H  q3'       g   \
        P                  ! R%V3R'W34      R
\
        P                  ! V	4      RR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRR\
        P                  ! V4      R\
        P                  ! V
4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p	;p;p;rVR,          p	\        P                  pRpRp\        W4      pV! V4      pV	V8H  q3'       Eg~   \
        P                  ! R%V3R(V	V34      R
\
        P                  ! V	4      RR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRR\
        P                  ! V4      RR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRR\
        P                  ! V4      R\
        P                  ! V4      R\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p	;p;p;p;p;ppVR,          qR,          pV	V8  q3'       gz   \
        P                  ! R)V3R*V	V34      R
\
        P                  ! V	4      R\
        P                  ! V4      /,          pR RV/,          p\        \
        P                  ! V4      4      hR;p	;ppR# )+    Ntimecloser"   r0   execute_entryexecute_exitr   lenr#   tradesr   r&   zassert %(py8)sr(   gross_pnl_pctg      $@r'   r   py7r)   zassert %(py11)sr+   pnl_pctr   r*   r,   r-   zassert %(py16)sr.   r%   zassert %(py6)s)z
2020-01-01z
2020-01-02z
2020-01-03)r"   g     @Z@r0   )TFF)FFTr   )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)s)zL%(py1)s == %(py9)s
{%(py9)s = %(py5)s
{%(py5)s = %(py3)s.approx
}(%(py7)s)
})zx%(py1)s == %(py14)s
{%(py14)s = %(py5)s
{%(py5)s = %(py3)s.approx
}(%(py12)s
{%(py12)s = %(py6)s(%(py8)s, %(py10)s)
})
}r?   )z%(py1)s < %(py4)s)pandas	DataFrameto_datetimer   r\   r   r   r   r   r   r   r   r   r'   r1   r   )pdsignalsr]   r   r6   @py_assert4@py_format7@py_format9t@py_assert0@py_assert6rK   @py_format10rM   r3   rC   rD   r4   rF   r7   r2   rB   s                         r   /test_extract_python_trades_stores_net_and_grossrm   C   s    llIJ&--	 G #7+Fv;!!;33vv;!q	A_44t4t!44!4444444444444444444444444t444!444444444Y<C6==CUCECU)BC=)BCC<CCCCCC<CCCC<CCCCCC6CCCC6CCC=CCCCCCCCCCCCCUCCCECCC)BCCCCCCCCCCCCCY<,O,,<,,,,,,<,,,,<,,,,,,,,,,,,r   )__doc__builtinsr   _pytest.assertion.rewrite	assertionrewriter   ossysr'   pathabspathjoindirname__file__REPOinserttools.compare_tv_tradesr   r   r   r   r    r9   rG   rO   rU   rm   r   r   r   <module>r}      s   
  	 
 	wwrww||BGGOOH$=tDE 4  W W4$

;2W-r   