+
    0.j_  c                   \    R t ^ RIt^ RIHu Ht ^ RIt^ RIt	^ RI
t^ RIHt  ! R R4      tR# )z"Unit tests for statistics service.N)statistics_servicec                   P   a  ] tR t^
t o R tR tR tR tR tR t	R t
R tR	tV tR
# )TestStatisticsServicec                @   \         P                  ! \        P                  P	                  R RR4      4      p\
        P                  ! V4      p\        V\        4      q3'       Eg9   R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                  ! \        4      '       d   \        P                  ! \        4      MR	R
\        P                  ! V4      /,          p\        \        P                  ! V4      4      hRpR# )gMbP?g{Gz?im  z5assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}py0
isinstancepy1sharpepy2floatpy4N)pdSeriesnprandomnormalr   sharpe_ratior   r
   @py_builtinslocals
@pytest_ar_should_repr_global_name	_safereprAssertionError_format_explanation)selfreturnsr   @py_assert3@py_format5s   &    ?C:\xampp\htdocs\tradingbinance\backend\tests\test_statistics.pytest_sharpe_ratio'TestStatisticsService.test_sharpe_ratio   s    ))BII,,UD#>?#009(((((((((((((((((((((((((((((((((((((((((((    c                   \         P                  ! . RO4      p\        P                  ! V4      p^ q2V8  qD'       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\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;rCR# )
d   r   ddpy3assert %(py5)spy5N)r"   n   i   _   r"   x   s   >z%(py0)s > %(py3)s)r   r   r   max_drawdownr   _call_reprcomparer   r   r   r   r   r   )r   equityr#   @py_assert2@py_assert1@py_format4@py_format6s   &      r   test_max_drawdown'TestStatisticsService.test_max_drawdown   sT    =>,,V4r    c                   . ROp\         P                  ! V4      pRq2V8H  qD'       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\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;rCR# )r"   g      N@r   wrr$   r%   r&   N)r"         )==)z%(py0)s == %(py3)s)
r   win_rater   r0   r   r   r   r   r   r   )r   pnlsr9   r2   r3   r4   r5   s   &      r   test_win_rate#TestStatisticsService.test_win_rate   sb    (((.r    c                   . ROp\         P                  ! V4      p^q2V8  qD'       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\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;rCR# )
r"   r   pfr$   r%   r&   N)r"   r:   r;   r<   r,   r.   )
r   profit_factorr   r0   r   r   r   r   r   r   )r   r@   rD   r2   r3   r4   r5   s   &      r   test_profit_factor(TestStatisticsService.test_profit_factor   sJ    #--d3r    c           	        \         P                  ! ^<^d^2RR7      p^ q"V8*  pRqAV8*  qS'       d	   V'       g   \        P                  ! R
W53RW!V34      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;rTR	# )<   g      ?)capr   r   kellypy6zassert %(py8)spy8N)<=rN   )z%(py1)s <= %(py4)sz%(py4)s <= %(py6)s)
r   kelly_criterionr   r0   r   r   r   r   r   r   )r   rK   @py_assert0r2   @py_assert5r   @py_format7@py_format9s   &       r   test_kelly_criterion_capped1TestStatisticsService.test_kelly_criterion_capped   sr    "222sBDI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!r    c                   \         P                  ! . RO4      p\        P                  ! ^
V4      p^ q2V8  qD'       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\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;rCR# )
   r   zr$   r%   r&   N)
rW                        	   
   r,   r.   )r   r   r   z_scorer   r0   r   r   r   r   r   r   )r   seriesrX   r2   r3   r4   r5   s   &      r   test_z_score"TestStatisticsService.test_z_score#   sV    :;&&r62r    c                   \         P                  ! . R
O4      p\        P                  ! VRR7      pVR,          pRqCVJ qU'       gy   \        P
                  ! RV3RW434      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR	;p;rTR	# )rW   g       @)	threshold
is_anomalyTr   r   zassert %(py6)srL   N)
rW   rY   rZ   rY   rZ   rY   rZ   rY   rZ   r"   )is)z%(py1)s is %(py4)s)	r   r   r   detect_anomaliesr   r0   r   r   r   )r   rc   resultrP   r   r2   r   rR   s   &       r   test_anomaly_detection,TestStatisticsService.test_anomaly_detection(   s\    ;<#44VsK+++++++++++++++++++r    c                N   \         P                  ! . RO4      p\         P                  ! . RO4      p\        P                  ! W4      pRqCV,
          p\	        V4      pRqvV8  q'       Eg3   \
        P                  ! RV3RWg3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      R	\
        P                  ! V4      /,          p	R
RV	/,          p
\        \
        P                  ! V
4      4      hR;p;p;p;rR# )rW   g      ?g{Gz?r   absr   corrr$   rL   py9zassert %(py11)spy11N)rW   rY   rZ   r[   r\   )rY   r[   r]   r_   ra   )<)z;%(py6)s
{%(py6)s = %(py0)s((%(py1)s - %(py3)s))
} < %(py9)s)r   r   r   correlationro   r   r0   r   r   r   r   r   r   )r   abrp   r2   @py_assert4rQ   @py_assert8@py_assert7@py_format10@py_format12s   &          r   test_correlation&TestStatisticsService.test_correlation-   s    IIo&II&'!--a3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%r     N)__name__
__module____qualname____firstlineno__r   r6   rA   rF   rT   rd   rl   r|   __static_attributes____classdictcell__)__classdict__s   @r   r   r   
   s2     )



"
,
& &r    r   )__doc__builtinsr   _pytest.assertion.rewrite	assertionrewriter   pytestpandasr   numpyr   app.services.statistics_servicer   r   r~   r    r   <module>r      s"    (      >'& '&r    