Ë
    '†¼iã  ã                   ó|   — d dl mZmZmZmZ d dlZd dlmZ d dl	m
Z
mZ ddlmZ dgZ G d„ dej                  «      Zy)	é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsN)Ú
itervalues)ÚaverageÚstandarddevé   )Ú
TimeReturnÚPeriodStatsc                   óT   — e Zd ZdZdej
                  j                  fdddfZd„ Zd„ Z	y)	r   aê  Calculates basic statistics for given timeframe

    Params:

      - ``timeframe`` (default: ``Years``)
        If ``None`` the ``timeframe`` of the 1st data in the system will be
        used

        Pass ``TimeFrame.NoTimeFrame`` to consider the entire dataset with no
        time constraints

      - ``compression`` (default: ``1``)

        Only used for sub-day timeframes to for example work on an hourly
        timeframe by specifying "TimeFrame.Minutes" and 60 as compression

        If ``None`` then the compression of the 1st data of the system will be
        used

      - ``fund`` (default: ``None``)

        If ``None`` the actual mode of the broker (fundmode - True/False) will
        be autodetected to decide if the returns are based on the total net
        asset value or on the fund value. See ``set_fundmode`` in the broker
        documentation

        Set it to ``True`` or ``False`` for a specific behavior


    ``get_analysis`` returns a dictionary containing the keys:

      - ``average``
      - ``stddev``
      - ``positive``
      - ``negative``
      - ``nochange``
      - ``best``
      - ``worst``

    If the parameter ``zeroispos`` is set to ``True``, periods with no change
    will be counted as positive
    Ú	timeframe)Úcompressionr
   )Ú	zeroisposF)ÚfundNc                 ó¢   — t        | j                  j                  | j                  j                  | j                  j                  ¬«      | _        y )N)r   r   r   )r   Úpr   r   r   Ú_tr)Úselfs    ú^/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/analyzers/periodstats.pyÚ__init__zPeriodStats.__init__U   s2   € Ü¨¯©×(8Ñ(8Ø*.¯&©&×*<Ñ*<À4Ç6Á6Ç;Á;ôPˆó    c                 ó  — | j                   j                  «       }dx}x}}t        t        |«      «      }|D ]?  }|dkD  r|dz  }Œ|dk  r|dz  }Œ| j                  j
                  r	||dk(  z  }Œ8||dk(  z  }ŒA t        |«      x| j                  d<   }t        ||«      | j                  d<   || j                  d<   || j                  d<   || j                  d<   t        |«      | j                  d	<   t        |«      | j                  d
<   y )Nr   g        r
   r   ÚstddevÚpositiveÚnegativeÚnochangeÚbestÚworst)r   Úget_analysisÚlistr   r   r   r   Úretsr	   ÚmaxÚmin)r   ÚtretsÚposÚnulÚnegÚtretÚavgs          r   ÚstopzPeriodStats.stopY   s  € Ø—‘×%Ñ%Ó'ˆØÐˆÐˆcCÜ”Z Ó&Ó'ˆØò 		'ˆDØcŠzØq‘‘Ø˜’Øq‘‘à—6‘6×#Ò#Ø˜4 3™;Ñ&‘Cà˜4 3™;Ñ&‘Cð		'ô &-¨U£^Ð3ˆ	‰	)Ñ˜sÜ)¨%°Ó5ˆ	‰	(Ñà #ˆ	‰	*ÑØ #ˆ	‰	*ÑØ #ˆ	‰	*Ñä ›Jˆ	‰	&ÑÜ  ›Zˆ	‰	'Òr   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚbtÚ	TimeFrameÚYearsÚparamsr   r+   © r   r   r   r   "   s7   „ ñ)ðX 
b—l‘l×(Ñ(Ð)ØØØð	€FòPó(r   )Ú
__future__r   r   r   r   Ú
backtraderr0   Úbacktrader.utils.py3r   Úbacktrader.mathsupportr   r	   Ú r   Ú__all__ÚAnalyzerr   r4   r   r   ú<module>r<      s8   ð÷**ó *ó Ý +ß 7Ý ð ˆ/€ôN("—+‘+õ N(r   