
    'i                     F    d dl mZmZmZmZ d dlZddlmZ  G d de      Z	y)    )absolute_importdivisionprint_functionunicode_literalsN   )
TimeReturnc                   l     e Zd ZdZdZdZ e ed             ZdZ fdZ	 fdZ
 fdZ fd	Z xZS )
	Benchmarkam  This observer stores the *returns* of the strategy and the *return* of a
    reference asset which is one of the datas passed to the system.

    Params:

      - ``timeframe`` (default: ``None``)
        If ``None`` then the complete return over the entire backtested period
        will be reported

      - ``compression`` (default: ``None``)

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

      - ``data`` (default: ``None``)

        Reference asset to track to allow for comparison.

        .. note:: this data must have been added to a ``cerebro`` instance with
                  ``addata``, ``resampledata`` or ``replaydata``.


      - ``_doprenext`` (default: ``False``)

        Benchmarking will take place from the point at which the strategy kicks
        in (i.e.: when the minimum period of the strategy has been met).

        Setting this to ``True`` will record benchmarking values from the
        starting point of the data feeds

      - ``firstopen`` (default: ``False``)

        Keepint it as ``False`` ensures that the 1st comparison point between
        the value and the benchmark starts at 0%, because the benchmark will
        not use its opening price.

        See the ``TimeReturn`` analyzer reference for a full explanation of the
        meaning of the parameter

      - ``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

    Remember that at any moment of a ``run`` the current values can be checked
    by looking at the *lines* by name at index ``0``.

    T)	benchmark)_name))dataN)
_doprenextF)	firstopenF)fundNc                     t         t        |          }|j                  | j                  j
                  j                         |S N)superr
   
_plotlabelappendpr   r   )selflabels	__class__s     \/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/observers/benchmark.pyr   zBenchmark._plotlabel^   s1    y$24dffkk''(    c                    | j                   j                  | j                  | j                   _        t        t        |           | j                   j                         }|j                  d         | j                  j                  t        j                  j                  fi |}|| j                  c| _        | _        y )N)r   )r   r   data0r   r
   __init__
_getkwargsupdate_owner_addanalyzer_slavebt	analyzersr   treturntbench)r   kwargstr   s      r   r   zBenchmark.__init__c   s    66;;**DFFKi')""$4 *DKK**2<<+B+BMfM %&t||!dkr   c                     t         t        |           | j                  j                  j                  | j                  j                  t        d            | j                  j                  d<   y )NNaNr   )r   r
   nextr&   retsgetr%   dtkeyfloatlinesr   r   r   s    r   r+   zBenchmark.nextp   sM    i#%"&++"2"2"6"6t||7I7I7<U|#E

Qr   c                 X    | j                   j                  rt        t        |           y y r   )r   r   r   r   prenextr1   s    r   r3   zBenchmark.prenextu   s"    66*d+- r   )__name__
__module____qualname____doc___stclockr0   dict	plotlinesparamsr   r   r+   r3   __classcell__)r   s   @r   r
   r
      sE    3h HEt+67IF
4E
. .r   r
   )

__future__r   r   r   r   
backtraderr#    r   r
    r   r   <module>rA      s%   ** *  [.
 [.r   