
    'i                     X    d dl mZmZmZmZ ddlmZmZ  G d de      Z G d de      Z	y)	    )absolute_importdivisionprint_functionunicode_literals   )	IndicatorMovAvc                   F    e Zd ZdZdZdZddej                  fdfZd Z	d Z
y	)
StandardDeviationa  
    Calculates the standard deviation of the passed data for a given period

    Note:
      - If 2 datas are provided as parameters, the 2nd is considered to be the
        mean of the first

      - ``safepow`` (default: False) If this parameter is True, the standard
        deviation will be calculated as pow(abs(meansq - sqmean), 0.5) to safe
        guard for possible negative results of ``meansq - sqmean`` caused by
        the floating point representation.

    Formula:
      - meansquared = SimpleMovingAverage(pow(data, 2), period)
      - squaredmean = pow(SimpleMovingAverage(data, period), 2)
      - stddev = pow(meansquared - squaredmean, 0.5)  # square root

    See:
      - http://en.wikipedia.org/wiki/Standard_deviation
    )StdDev)stddevperiod   movav)safepowTc                     | j                   j                  g}|| j                   j                  g| j                   j                  d      z  z  }|S Nr   pr   r   
notdefaultselfplabelss     ]/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/indicators/deviation.py
_plotlabelzStandardDeviation._plotlabel5   >    66==/DFFLL>DFF$5$5g$>>>    c                    t        | j                        dkD  r| j                  }n;| j                  j	                  | j
                  | j                  j                        }| j                  j	                  t        | j
                  d      | j                  j                        }t        |d      }| j                  j                  r(t        t        ||z
        d      | j                  _        y t        ||z
  d      | j                  _        y )Nr   r      g      ?)lendatasdata1r   r   datar   powr   abslinesr   )r   meanmeansqsqmeans       r   __init__zStandardDeviation.__init__:   s    tzz?Q::D66<<		$&&--<@Dc$))Q/FT166>> #C$8# >DJJ #FVOS 9DJJr   N__name__
__module____qualname____doc__aliasr(   r	   Simpleparamsr   r,    r   r   r   r      s3    ( EEw57HJF
:r   r   c                   D    e Zd ZdZdZdZddej                  ffZd Z	d Z
y)	MeanDeviationa  MeanDeviation (alias MeanDev)

    Calculates the Mean Deviation of the passed data for a given period

    Note:
      - If 2 datas are provided as parameters, the 2nd is considered to be the
        mean of the first

    Formula:
      - mean = MovingAverage(data, period) (or provided mean)
      - absdeviation = abs(data - mean)
      - meandev = MovingAverage(absdeviation, period)

    See:
      - https://en.wikipedia.org/wiki/Average_absolute_deviation
    )MeanDev)meandevr   r   c                     | j                   j                  g}|| j                   j                  g| j                   j                  d      z  z  }|S r   r   r   s     r   r   zMeanDeviation._plotlabel_   r   r   c                 t   t        | j                        dkD  r| j                  }n;| j                  j	                  | j
                  | j                  j                        }t        | j
                  |z
        }| j                  j	                  || j                  j                        | j                  _	        y )Nr   r    )
r"   r#   r$   r   r   r%   r   r'   r(   r9   )r   r)   absdevs      r   r,   zMeanDeviation.__init__d   su    tzz?Q::D66<<		$&&--<@DTYY%&!VV\\&\G

r   Nr-   r5   r   r   r7   r7   I   s1      EEw57F
Hr   r7   N)

__future__r   r   r   r    r   r	   r   r7   r5   r   r   <module>r?      s/   ** * +:	 +:\"HI "Hr   