
    'i                     F    d dl mZmZmZmZ ddlmZ ddgZ G d de      Zy)    )absolute_importdivisionprint_functionunicode_literals   )PeriodNHurstExponentHurstc                   >     e Zd ZdZdZdZdZdZd Z fdZ	d Z
 xZS )	r	   a  
    References:

      - https://www.quantopian.com/posts/hurst-exponent
      - https://www.quantopian.com/posts/some-code-from-ernie-chans-new-book-implemented-in-python

   Interpretation of the results

      1. Geometric random walk (H=0.5)
      2. Mean-reverting series (H<0.5)
      3. Trending Series (H>0.5)

    Important notes:

      - The default period is ``40``, but experimentation by users has shown
        that it would be advisable to have at least 2000 samples (i.e.: a
        period of at least 2000) to have stable values.

      - The `lag_start` and `lag_end` values will default to be ``2`` and
        ``self.p.period / 2`` unless the parameters are specified.

        Experimentation by users has also shown that values of around ``10``
        and ``500`` produce good results

    The original values (40, 2, self.p.period / 2) are kept for backwards
    compatibility

    ))numpy)asarraylog10polyfitsqrtstdsubtract)r
   )hurst))period(   )	lag_startN)lag_endNc                 t    | j                   j                  g}|| j                  gz  }|| j                  gz  }|S )N)pr   
_lag_start_lag_end)selfplabelss     Y/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/indicators/hurst.py
_plotlabelzHurstExponent._plotlabelG   s7    66==/DOO$$DMM?"    c                 D   t         t        |           | j                  j                  xs dx| _        }| j                  j                  xs | j                  j                  dz  x| _        }t        t        ||            | _        t        | j                        | _        y )N   )superr	   __init__r   r   r   r   r   r   r   rangelagsr   	log10lags)r   r   r   	__class__s      r   r$   zHurstExponent.__init__M   st    mT+-&*ff&6&6&;!;)"&&&.."HTVV]]a5GHE)W56	tyy)r    c                 v   t        | j                  j                  | j                  j                              }| j
                  D cg c]'  }t        t        t        ||d  |d |                    ) }}t        | j                  t        |      d      }|d   dz  | j                  j                  d<   y c c}w )N)sizer   r   g       @)r   datagetr   r   r&   r   r   r   r   r'   r   linesr   )r   tslagtaupolys        r   nextzHurstExponent.nextU   s    TYY]]]67 DH99MCtCCD2et9567MM t~~uSz15 #1gm

 Ns   ,B6)__name__
__module____qualname____doc__frompackagesaliasr-   paramsr   r$   r2   __classcell__)r(   s   @r   r	   r	      s1    8L EEF*,r    N)	
__future__r   r   r   r    r   __all__r	    r    r   <module>r?      s.   ** *  G
$B,G B,r    