Ë
    ¤ehv‰  ã                  óð  — d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	Z
d dlmZ d dlmc mc mZ d dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z"m#Z#m$Z$ d dl%m&Z&m'Z' d dl(m)Z) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z:m;Z; erd dl<m=Z=m>Z>m?Z? d dl@mAZAmBZB d dlCmDZD 	 	 	 	 	 	 	 	 	 	 d d„ZE	 	 	 	 	 	 d!d„ZF G d„ de:«      ZG G d„ de;eG«      ZH G d„ deG«      ZIy)"é    )ÚannotationsN)Úpartial)Údedent)ÚTYPE_CHECKING)Ú	Timedelta)Údoc)Úis_datetime64_dtypeÚis_numeric_dtype)ÚDatetimeTZDtype)Ú	ABCSeries)Úisna)Úcommon)Údtype_to_unit)ÚBaseIndexerÚExponentialMovingWindowIndexerÚGroupbyIndexer)Úget_jit_argumentsÚmaybe_use_numba)Úzsqrt)Ú_shared_docsÚcreate_section_headerÚkwargs_numeric_onlyÚnumba_notesÚtemplate_headerÚtemplate_returnsÚtemplate_see_alsoÚwindow_agg_numba_parameters)Úgenerate_numba_ewm_funcÚgenerate_numba_ewm_table_func)ÚEWMMeanStateÚgenerate_online_numba_ewma_func)Ú
BaseWindowÚBaseWindowGroupby)ÚAxisÚTimedeltaConvertibleTypesÚnpt)Ú	DataFrameÚSeries)ÚNDFramec                óæ  — t        j                  | |||«      }|dkD  rt        d«      ‚| �| dk  r¸t        d«      ‚|�#|dk  rt        d«      ‚|dz
  dz  } t        | «      S |�Q|dk  rt        d«      ‚dt        j                  t        j
                  d«      |z  «      z
  }d|z  dz
  } t        | «      S |�(|dk  s|dkD  rt        d	«      ‚d|z
  |z  } t        | «      S t        d
«      ‚t        | «      S )Né   z8comass, span, halflife, and alpha are mutually exclusiver   z comass must satisfy: comass >= 0zspan must satisfy: span >= 1é   z#halflife must satisfy: halflife > 0g      à?z"alpha must satisfy: 0 < alpha <= 1z1Must pass one of comass, span, halflife, or alpha)r   Úcount_not_noneÚ
ValueErrorÚnpÚexpÚlogÚfloat)ÚcomassÚspanÚhalflifeÚalphaÚvalid_countÚdecays         úT/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/pandas/core/window/ewm.pyÚget_center_of_massr:   G   s!  € ô ×'Ñ'¨°°hÀÓF€KØ�Q‚ÜÐSÓTÐTð ÐØ�AŠ:ÜÐ?Ó@Ð@Ø	Ð	Ø�!Š8ÜÐ;Ó<Ð<Ø˜‘(˜a‘ˆô �‹=Ðð 
Ð	Ø�qŠ=ÜÐBÓCÐCØ”B—F‘Fœ2Ÿ6™6 #›;¨Ñ1Ó2Ñ2ˆØ�U‘˜Q‘ˆô �‹=Ðð 
Ð	Ø�AŠ:˜ šÜÐAÓBÐBØ�e‘)˜uÑ$ˆô �‹=Ðô ÐLÓMÐMä�‹=Ðó    c                ór  — t        | j                  «      }t        | t        «      r| j                  } t        j                  | j                  t
        j                  «      t
        j                  ¬«      }t        t        |«      j                  |«      j                  «      }t        j                  |«      |z  S )aå  
    Return the diff of the times divided by the half-life. These values are used in
    the calculation of the ewm mean.

    Parameters
    ----------
    times : np.ndarray, Series
        Times corresponding to the observations. Must be monotonically increasing
        and ``datetime64[ns]`` dtype.
    halflife : float, str, timedelta, optional
        Half-life specifying the decay

    Returns
    -------
    np.ndarray
        Diff of the times divided by the half-life
    ©Údtype)r   r>   Ú
isinstancer   Ú_valuesr/   ÚasarrayÚviewÚint64Úfloat64r2   r   Úas_unitÚ_valueÚdiff)Útimesr5   ÚunitÚ_timesÚ	_halflifes        r9   Ú_calculate_deltasrL   h   sy   € ô* ˜Ÿ™Ó%€DÜ�%œÔ#Ø—‘ˆÜ�Z‰Z˜Ÿ
™
¤2§8¡8Ó,´B·J±JÔ?€FÜ”i Ó)×1Ñ1°$Ó7×>Ñ>Ó?€IÜ�7‰7�6‹?˜YÑ&Ð&r;   c                  óR  ‡ — e Zd ZdZg d¢Z	 	 	 	 	 	 	 	 	 	 d2ddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3ˆ fd„Z	 	 	 	 	 	 	 	 d4d„Zd5d„Z	 d6	 	 	 d7d„Z e	e
d	    ed
«       ed«      dd¬«      ˆ fd„«       ZeZ e	e ed«      e e«        ed«      e ed«      e ed«      e ed«       ed«      ddd¬«      	 	 	 d8	 d9d„«       Z e	e ed«      e e«        ed«      e ed«      e ed«      e ed«       ed«      ddd¬«      	 	 	 d8	 d9d„«       Z e	e ed«       ed«      e ed«      e ed«      e ed«       ed «      dd!d"¬«      d:d;d#„«       Z e	e ed«       ed«      e ed«      e ed«      e ed«       ed$«      dd%d&¬«      d:d;d'„«       Z e	e ed«       ed(«      e ed«      e ed«      e ed«       ed)«      dd*d+¬«      	 	 	 	 d<	 	 	 	 	 	 	 d=d,„«       Z e	e ed«       ed-«      e ed«      e ed«      e ed«       ed.«      dd/d0¬«      	 	 	 d>	 	 	 	 	 d?d1„«       Zˆ xZS )@ÚExponentialMovingWindowaé  
    Provide exponentially weighted (EW) calculations.

    Exactly one of ``com``, ``span``, ``halflife``, or ``alpha`` must be
    provided if ``times`` is not provided. If ``times`` is provided,
    ``halflife`` and one of ``com``, ``span`` or ``alpha`` may be provided.

    Parameters
    ----------
    com : float, optional
        Specify decay in terms of center of mass

        :math:`\alpha = 1 / (1 + com)`, for :math:`com \geq 0`.

    span : float, optional
        Specify decay in terms of span

        :math:`\alpha = 2 / (span + 1)`, for :math:`span \geq 1`.

    halflife : float, str, timedelta, optional
        Specify decay in terms of half-life

        :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, for
        :math:`halflife > 0`.

        If ``times`` is specified, a timedelta convertible unit over which an
        observation decays to half its value. Only applicable to ``mean()``,
        and halflife value will not apply to the other functions.

    alpha : float, optional
        Specify smoothing factor :math:`\alpha` directly

        :math:`0 < \alpha \leq 1`.

    min_periods : int, default 0
        Minimum number of observations in window required to have a value;
        otherwise, result is ``np.nan``.

    adjust : bool, default True
        Divide by decaying adjustment factor in beginning periods to account
        for imbalance in relative weightings (viewing EWMA as a moving average).

        - When ``adjust=True`` (default), the EW function is calculated using weights
          :math:`w_i = (1 - \alpha)^i`. For example, the EW moving average of the series
          [:math:`x_0, x_1, ..., x_t`] would be:

        .. math::
            y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + (1 -
            \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t}

        - When ``adjust=False``, the exponentially weighted function is calculated
          recursively:

        .. math::
            \begin{split}
                y_0 &= x_0\\
                y_t &= (1 - \alpha) y_{t-1} + \alpha x_t,
            \end{split}
    ignore_na : bool, default False
        Ignore missing values when calculating weights.

        - When ``ignore_na=False`` (default), weights are based on absolute positions.
          For example, the weights of :math:`x_0` and :math:`x_2` used in calculating
          the final weighted average of [:math:`x_0`, None, :math:`x_2`] are
          :math:`(1-\alpha)^2` and :math:`1` if ``adjust=True``, and
          :math:`(1-\alpha)^2` and :math:`\alpha` if ``adjust=False``.

        - When ``ignore_na=True``, weights are based
          on relative positions. For example, the weights of :math:`x_0` and :math:`x_2`
          used in calculating the final weighted average of
          [:math:`x_0`, None, :math:`x_2`] are :math:`1-\alpha` and :math:`1` if
          ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``.

    axis : {0, 1}, default 0
        If ``0`` or ``'index'``, calculate across the rows.

        If ``1`` or ``'columns'``, calculate across the columns.

        For `Series` this parameter is unused and defaults to 0.

    times : np.ndarray, Series, default None

        Only applicable to ``mean()``.

        Times corresponding to the observations. Must be monotonically increasing and
        ``datetime64[ns]`` dtype.

        If 1-D array like, a sequence with the same shape as the observations.

    method : str {'single', 'table'}, default 'single'
        .. versionadded:: 1.4.0

        Execute the rolling operation per single column or row (``'single'``)
        or over the entire object (``'table'``).

        This argument is only implemented when specifying ``engine='numba'``
        in the method call.

        Only applicable to ``mean()``

    Returns
    -------
    pandas.api.typing.ExponentialMovingWindow

    See Also
    --------
    rolling : Provides rolling window calculations.
    expanding : Provides expanding transformations.

    Notes
    -----
    See :ref:`Windowing Operations <window.exponentially_weighted>`
    for further usage details and examples.

    Examples
    --------
    >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]})
    >>> df
         B
    0  0.0
    1  1.0
    2  2.0
    3  NaN
    4  4.0

    >>> df.ewm(com=0.5).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.670213
    >>> df.ewm(alpha=2 / 3).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.670213

    **adjust**

    >>> df.ewm(com=0.5, adjust=True).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.670213
    >>> df.ewm(com=0.5, adjust=False).mean()
              B
    0  0.000000
    1  0.666667
    2  1.555556
    3  1.555556
    4  3.650794

    **ignore_na**

    >>> df.ewm(com=0.5, ignore_na=True).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.225000
    >>> df.ewm(com=0.5, ignore_na=False).mean()
              B
    0  0.000000
    1  0.750000
    2  1.615385
    3  1.615385
    4  3.670213

    **times**

    Exponentially weighted mean with weights calculated with a timedelta ``halflife``
    relative to ``times``.

    >>> times = ['2020-01-01', '2020-01-03', '2020-01-10', '2020-01-15', '2020-01-17']
    >>> df.ewm(halflife='4 days', times=pd.DatetimeIndex(times)).mean()
              B
    0  0.000000
    1  0.585786
    2  1.523889
    3  1.523889
    4  3.233686
    )
Úcomr4   r5   r6   Úmin_periodsÚadjustÚ	ignore_naÚaxisrH   ÚmethodN©Ú	selectionc          
     ó¶  •— t         ‰| �  ||€dnt        t        |«      d«      d dd ||	|¬«       || _        || _        || _        || _        || _        || _	        |
| _
        | j                  ��‰| j                  st        d«      ‚t        | j                  dd «      }t        |«      st        |t        «      st!        d«      ‚t#        | j                  «      t#        |«      k7  rt!        d«      ‚t        | j                  t$        t&        j(                  t*        j,                  f«      st!        d«      ‚t/        | j                  «      j1                  «       rt!        d	«      ‚t3        | j                  | j                  «      | _        t7        j8                  | j                  | j
                  | j                  «      d
kD  r2t;        | j                  | j
                  d | j                  «      | _        y d| _        y | j                  �Dt        | j                  t$        t&        j(                  t*        j,                  f«      rt!        d«      ‚t+        j>                  t        | j@                  jB                  | jD                     dz
  d
«      t*        jF                  ¬«      | _        t;        | j                  | j
                  | j                  | j                  «      | _        y )Nr+   F)ÚobjrP   ÚonÚcenterÚclosedrT   rS   rV   z)times is not supported with adjust=False.r>   ztimes must be datetime64 dtype.z,times must be the same length as the object.z/halflife must be a timedelta convertible objectz$Cannot convert NaT values to integerr   g      ð?zKhalflife can only be a timedelta convertible argument if times is not None.r=   )$ÚsuperÚ__init__ÚmaxÚintrO   r4   r5   r6   rQ   rR   rH   ÚNotImplementedErrorÚgetattrr	   r?   r   r.   ÚlenÚstrÚdatetimeÚ	timedeltar/   Útimedelta64r   ÚanyrL   Ú_deltasr   r-   r:   Ú_comÚonesrX   ÚshaperS   rD   )ÚselfrX   rO   r4   r5   r6   rP   rQ   rR   rS   rH   rT   rV   Útimes_dtypeÚ	__class__s                 €r9   r]   z ExponentialMovingWindow.__init__P  s1  ø€ ô  	‰ÑØØ(Ð0™´c¼#¸kÓ:JÈAÓ6NØØØØØØð 	ô 		
ð ˆŒØˆŒ	Ø ˆŒØˆŒ
ØˆŒØ"ˆŒØˆŒ
Ø�:‰:Ñ!Ø—;’;Ü)Ð*UÓVÐVÜ! $§*¡*¨g°tÓ<ˆKä# KÔ0Ü˜k¬?Ô;ä Ð!BÓCÐCÜ�4—:‘:‹¤# c£(Ò*Ü Ð!OÓPÐPÜ˜dŸm™m¬c´8×3EÑ3EÄrÇ~Á~Ð-VÔWÜ Ð!RÓSÐSÜ�D—J‘JÓ×#Ñ#Ô%Ü Ð!GÓHÐHÜ,¨T¯Z©Z¸¿¹ÓGˆDŒLô ×$Ñ$ T§X¡X¨t¯y©y¸$¿*¹*ÓEÈÒIÜ.¨t¯x©x¸¿¹ÀDÈ$Ï*É*ÓU�•	à�•	à�}‰}Ð(¬ZØ—‘¤¤X×%7Ñ%7¼¿¹ÐHô.ô !ð)óð ô
 Ÿ7™7Ü�D—H‘H—N‘N 4§9¡9Ñ-°Ñ1°1Ó5¼R¿Z¹ZôˆDŒLô +ð —‘Ø—	‘	Ø—‘Ø—
‘
óˆD�Ir;   c                 ó   — y ©N© )rl   ÚstartÚendÚnum_valss       r9   Ú_check_window_boundsz,ExponentialMovingWindow._check_window_bounds�  s   € ð
 	r;   c                ó   — t        «       S )z[
        Return an indexer class that will compute the window start and end bounds
        )r   ©rl   s    r9   Ú_get_window_indexerz+ExponentialMovingWindow._get_window_indexer¤  s   € ô .Ó/Ð/r;   c                ó  — t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  ||| j                  ¬«      S )aª  
        Return an ``OnlineExponentialMovingWindow`` object to calculate
        exponentially moving window aggregations in an online method.

        .. versionadded:: 1.3.0

        Parameters
        ----------
        engine: str, default ``'numba'``
            Execution engine to calculate online aggregations.
            Applies to all supported aggregation methods.

        engine_kwargs : dict, default None
            Applies to all supported aggregation methods.

            * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
              and ``parallel`` dictionary keys. The values must either be ``True`` or
              ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
              ``{{'nopython': True, 'nogil': False, 'parallel': False}}`` and will be
              applied to the function

        Returns
        -------
        OnlineExponentialMovingWindow
        )rX   rO   r4   r5   r6   rP   rQ   rR   rS   rH   ÚengineÚengine_kwargsrV   )ÚOnlineExponentialMovingWindowrX   rO   r4   r5   r6   rP   rQ   rR   rS   rH   Ú
_selection)rl   rz   r{   s      r9   ÚonlinezExponentialMovingWindow.onlineª  sf   € ô8 -Ø—‘Ø—‘Ø—‘Ø—]‘]Ø—*‘*Ø×(Ñ(Ø—;‘;Ø—n‘nØ—‘Ø—*‘*ØØ'Ø—o‘oô
ð 	
r;   Ú	aggregatezV
        See Also
        --------
        pandas.DataFrame.rolling.aggregate
        aœ  
        Examples
        --------
        >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
        >>> df
           A  B  C
        0  1  4  7
        1  2  5  8
        2  3  6  9

        >>> df.ewm(alpha=0.5).mean()
                  A         B         C
        0  1.000000  4.000000  7.000000
        1  1.666667  4.666667  7.666667
        2  2.428571  5.428571  8.428571
        zSeries/DataframeÚ )Úsee_alsoÚexamplesÚklassrS   c                ó*   •— t        ‰| �  |g|¢­i |¤ŽS rp   )r\   r   )rl   ÚfuncÚargsÚkwargsrn   s       €r9   r   z!ExponentialMovingWindow.aggregateÖ  s   ø€ ô> ‰wÑ  Ð7¨Ò7°Ñ7Ð7r;   Ú
ParametersÚReturnszSee AlsoÚNotesÚExampleszÆ        >>> ser = pd.Series([1, 2, 3, 4])
        >>> ser.ewm(alpha=.2).mean()
        0    1.000000
        1    1.555556
        2    2.147541
        3    2.775068
        dtype: float64
        Úewmz"(exponential weighted moment) meanÚmean)Úwindow_methodÚaggregation_descriptionÚ
agg_methodc           
     ó  — t        |«      ry| j                  dk(  rt        }nt        } |d
i t	        |«      ¤| j
                  | j                  | j                  t        | j                  «      ddœ¤Ž}| j                  |d¬«      S |dv rx|�t        d«      ‚| j                  €d n| j                  }t        t        j                  | j
                  | j                  | j                  |d¬«      }| j                  |d|¬«      S t        d	«      ‚)NÚsingleT©rO   rQ   rR   ÚdeltasÚ	normalizer�   ©Úname©ÚcythonNú+cython engine does not accept engine_kwargs©r—   Únumeric_onlyú)engine must be either 'numba' or 'cython'rq   )r   rT   r   r   r   ri   rQ   rR   Útuplerh   Ú_applyr.   rH   r   Úwindow_aggregationsrŒ   ©rl   rœ   rz   r{   r…   Úewm_funcr”   Úwindow_funcs           r9   r�   zExponentialMovingWindow.meanù  sø   € ôB ˜6Ô"Ø�{‰{˜hÒ&Ü.‘ä4�Ùñ Ü# MÓ2ðà—I‘IØ—{‘{ØŸ.™.Ü˜TŸ\™\Ó*ØóˆHð —;‘;˜x¨f�;Ó5Ð5ØÐ'Ñ'ØÐ(Ü Ð!NÓOÐOà!ŸZ™ZÐ/‘T°T·\±\ˆFÜ!Ü#×'Ñ'Ø—I‘IØ—{‘{ØŸ.™.ØØôˆKð —;‘;˜{°Àl�;ÓSÐSäÐHÓIÐIr;   z¹        >>> ser = pd.Series([1, 2, 3, 4])
        >>> ser.ewm(alpha=.2).sum()
        0    1.000
        1    2.800
        2    5.240
        3    8.192
        dtype: float64
        z!(exponential weighted moment) sumÚsumc           
     óF  — | j                   st        d«      ‚t        |«      ry| j                  dk(  rt        }nt
        } |di t        |«      ¤| j                  | j                   | j                  t        | j                  «      ddœ¤Ž}| j                  |d¬«      S |dv rx|�t        d«      ‚| j                  €d n| j                  }t        t        j                   | j                  | j                   | j                  |d¬«      }| j                  |d|¬	«      S t        d
«      ‚)Nz(sum is not implemented with adjust=Falser’   Fr“   r¤   r–   r˜   rš   r›   r�   rq   )rQ   r`   r   rT   r   r   r   ri   rR   rž   rh   rŸ   r.   rH   r   r    rŒ   r¡   s           r9   r¤   zExponentialMovingWindow.sum9  s  € ðB �{Š{Ü%Ð&PÓQÐQÜ˜6Ô"Ø�{‰{˜hÒ&Ü.‘ä4�Ùñ Ü# MÓ2ðà—I‘IØ—{‘{ØŸ.™.Ü˜TŸ\™\Ó*ØóˆHð —;‘;˜x¨e�;Ó4Ð4ØÐ'Ñ'ØÐ(Ü Ð!NÓOÐOà!ŸZ™ZÐ/‘T°T·\±\ˆFÜ!Ü#×'Ñ'Ø—I‘IØ—{‘{ØŸ.™.ØØôˆKð —;‘;˜{°À\�;ÓRÐRäÐHÓIÐIr;   zb        bias : bool, default False
            Use a standard estimation bias correction.
        zÅ        >>> ser = pd.Series([1, 2, 3, 4])
        >>> ser.ewm(alpha=.2).std()
        0         NaN
        1    0.707107
        2    0.995893
        3    1.277320
        dtype: float64
        z0(exponential weighted moment) standard deviationÚstdc                óð   — |rY| j                   j                  dk(  r@t        | j                   j                  «      s!t	        t        | «      j                  › d�«      ‚t        | j                  ||¬«      «      S )Nr+   z$.std does not implement numeric_only)Úbiasrœ   )	Ú_selected_objÚndimr
   r>   r`   ÚtypeÚ__name__r   Úvar©rl   r¨   rœ   s      r9   r¦   zExponentialMovingWindow.std{  so   € ñ@ Ø×"Ñ"×'Ñ'¨1Ò,Ü$ T×%7Ñ%7×%=Ñ%=Ô>ô &Ü˜“:×&Ñ&Ð'Ð'KÐLóð ô �T—X‘X 4°l�XÓCÓDÐDr;   zÅ        >>> ser = pd.Series([1, 2, 3, 4])
        >>> ser.ewm(alpha=.2).var()
        0         NaN
        1    0.500000
        2    0.991803
        3    1.631547
        dtype: float64
        z&(exponential weighted moment) variancer­   c                ó²   ‡— t         j                  }t        || j                  | j                  | j
                  |¬«      Šˆfd„}| j                  |d|¬«      S )N)rO   rQ   rR   r¨   c                ó   •—  ‰| |||| «      S rp   rq   )ÚvaluesÚbeginrs   rP   Úwfuncs       €r9   Úvar_funcz-ExponentialMovingWindow.var.<locals>.var_funcÍ  s   ø€ Ù˜ ¨¨[¸&ÓAÐAr;   r­   r›   )r    Úewmcovr   ri   rQ   rR   rŸ   )rl   r¨   rœ   r£   r´   r³   s        @r9   r­   zExponentialMovingWindow.var¥  sR   ø€ ô> *×0Ñ0ˆÜØØ—	‘	Ø—;‘;Ø—n‘nØô
ˆô	Bð �{‰{˜8¨%¸lˆ{ÓKÐKr;   a¦          other : Series or DataFrame , optional
            If not supplied then will default to self and produce pairwise
            output.
        pairwise : bool, default None
            If False then only matching columns between self and other will be
            used and the output will be a DataFrame.
            If True then all pairwise combinations will be calculated and the
            output will be a MultiIndex DataFrame in the case of DataFrame
            inputs. In the case of missing elements, only complete pairwise
            observations will be used.
        bias : bool, default False
            Use a standard estimation bias correction.
        zú        >>> ser1 = pd.Series([1, 2, 3, 4])
        >>> ser2 = pd.Series([10, 11, 13, 16])
        >>> ser1.ewm(alpha=.2).cov(ser2)
        0         NaN
        1    0.500000
        2    1.524590
        3    3.408836
        dtype: float64
        z/(exponential weighted moment) sample covarianceÚcovc                ó„   ‡ ‡‡— ddl mŠ ‰ j                  d|«       ˆˆˆ fd„}‰ j                  ‰ j                  ||||«      S )Nr   ©r(   r¶   c                óú  •— ‰j                  | «      }‰j                  |«      }‰j                  «       }‰j                  �‰j                  n|j                  }|j	                  t        |«      |‰j                  ‰j                  ‰j                  ¬«      \  }}t        j                  |||‰j                  |‰j                  ‰j                  ‰j                  ‰
«	      } ‰	|| j                  | j                  d¬«      S )N©Ú
num_valuesrP   rZ   r[   ÚstepF©Úindexr—   Úcopy)Ú_prep_valuesrx   rP   Úwindow_sizeÚget_window_boundsrb   rZ   r[   r¼   r    rµ   ri   rQ   rR   r¾   r—   )ÚxÚyÚx_arrayÚy_arrayÚwindow_indexerrP   rr   rs   Úresultr(   r¨   rl   s            €€€r9   Úcov_funcz-ExponentialMovingWindow.cov.<locals>.cov_func  sî   ø€ Ø×'Ñ'¨Ó*ˆGØ×'Ñ'¨Ó*ˆGØ!×5Ñ5Ó7ˆNð ×#Ñ#Ð/ð × Ò à#×/Ñ/ð ð
 (×9Ñ9Ü˜w›<Ø'Ø—{‘{Ø—{‘{Ø—Y‘Yð :ó ‰JˆE�3ô )×/Ñ/ØØØð × Ñ ØØ—	‘	Ø—‘Ø—‘ØóˆFñ ˜&¨¯©°a·f±fÀ5ÔIÐIr;   ©Úpandasr(   Ú_validate_numeric_onlyÚ_apply_pairwiser©   )rl   ÚotherÚpairwiser¨   rœ   rÉ   r(   s   `  `  @r9   r¶   zExponentialMovingWindow.covÒ  sE   ú€ õ` 	"à×#Ñ# E¨<Ô8ö	Jð> ×#Ñ#Ø×Ñ  x°¸<ó
ð 	
r;   aK          other : Series or DataFrame, optional
            If not supplied then will default to self and produce pairwise
            output.
        pairwise : bool, default None
            If False then only matching columns between self and other will be
            used and the output will be a DataFrame.
            If True then all pairwise combinations will be calculated and the
            output will be a MultiIndex DataFrame in the case of DataFrame
            inputs. In the case of missing elements, only complete pairwise
            observations will be used.
        zû        >>> ser1 = pd.Series([1, 2, 3, 4])
        >>> ser2 = pd.Series([10, 11, 13, 16])
        >>> ser1.ewm(alpha=.2).corr(ser2)
        0         NaN
        1    1.000000
        2    0.982821
        3    0.977802
        dtype: float64
        z0(exponential weighted moment) sample correlationÚcorrc                ó€   ‡ ‡— ddl mŠ ‰ j                  d|«       ˆˆ fd„}‰ j                  ‰ j                  ||||«      S )Nr   r¸   rÐ   c                ó4  •‡
‡‡— ‰j                  | «      }‰j                  |«      }‰j                  «       }‰j                  �‰j                  n|j                  Š|j	                  t        |«      ‰‰j                  ‰j                  ‰j                  ¬«      \  ŠŠ
ˆ
ˆˆˆfd„}t        j                  d¬«      5   |||«      } |||«      } |||«      }|t        ||z  «      z  }	d d d «        ‰	| j                  | j                  d¬«      S # 1 sw Y   Œ)xY w)Nrº   c                óz   •— t        j                  | ‰‰‰|‰j                  ‰j                  ‰j                  d«	      S )NT)r    rµ   ri   rQ   rR   )ÚXÚYrs   rP   rl   rr   s     €€€€r9   Ú_covz<ExponentialMovingWindow.corr.<locals>.cov_func.<locals>._covk  s=   ø€ Ü*×1Ñ1ØØØØØØ—I‘IØ—K‘KØ—N‘NØó
ð 
r;   Úignore)ÚallFr½   )rÀ   rx   rP   rÁ   rÂ   rb   rZ   r[   r¼   r/   Úerrstater   r¾   r—   )rÃ   rÄ   rÅ   rÆ   rÇ   rÖ   r¶   Úx_varÚy_varrÈ   rs   rP   rr   r(   rl   s             @@@€€r9   rÉ   z.ExponentialMovingWindow.corr.<locals>.cov_funcZ  s  û€ Ø×'Ñ'¨Ó*ˆGØ×'Ñ'¨Ó*ˆGØ!×5Ñ5Ó7ˆNð ×#Ñ#Ð/ð × Ò à#×/Ñ/ð ð
 (×9Ñ9Ü˜w›<Ø'Ø—{‘{Ø—{‘{Ø—Y‘Yð :ó ‰JˆE�3÷ô —‘ Ô*ñ 4Ù˜7 GÓ,�Ù˜W gÓ.�Ù˜W gÓ.�Øœu U¨U¡]Ó3Ñ3�÷	4ñ
 ˜&¨¯©°a·f±fÀ5ÔIÐI÷4ð 4ús   Â9-DÄDrÊ   )rl   rÎ   rÏ   rœ   rÉ   r(   s   `    @r9   rÐ   zExponentialMovingWindow.corr)  sF   ù€ õZ 	"à×#Ñ# F¨LÔ9õ#	JðJ ×#Ñ#Ø×Ñ  x°¸<ó
ð 	
r;   )
NNNNr   TFr   Nr’   )rX   r)   rO   úfloat | Noner4   rÜ   r5   ú(float | TimedeltaConvertibleTypes | Noner6   rÜ   rP   ú
int | NonerQ   ÚboolrR   rß   rS   r$   rH   únp.ndarray | NDFrame | NonerT   rc   ÚreturnÚNone)rr   ú
np.ndarrayrs   rã   rt   r_   rá   râ   )rá   r   )ÚnumbaN)rz   rc   rá   r|   )FNN)rœ   rß   ©FF©r¨   rß   rœ   rß   ©NNFF©rÎ   úDataFrame | Series | NonerÏ   úbool | Noner¨   rß   rœ   rß   ©NNF©rÎ   ré   rÏ   rê   rœ   rß   )r¬   Ú
__module__Ú__qualname__Ú__doc__Ú_attributesr]   ru   rx   r~   r   r   r   r   Úaggr   r   r   r   r   r   r   r�   r¤   r¦   r­   r¶   rÐ   Ú__classcell__©rn   s   @r9   rN   rN   …   sv  ø„ ñ{òz€Kð  !Ø!Ø=AØ"Ø"#ØØØØ-1ØðKð ñKàðKð ðKð ð	Kð
 ;ðKð ðKð  ðKð ðKð ðKð ðKð +ðKð ðKð 
õKðZØðØ&0ðØ<?ðà	óó0ð 48ð*
Øð*
à	&ó*
ñX 	Ø�[Ñ!Ùðó
ñ ðó
ð$ !Øô9ó<8ó=ð<8ð €CáØÙ˜lÓ+ØÙ#Ó%Ù˜iÓ(ØÙ˜jÓ)ØÙ˜gÓ&ØÙ˜jÓ)Ùðó
	
ð Ø DØô3ð: #ØØð	#Jàò#Jó7ð6#JñJ 	ØÙ˜lÓ+ØÙ#Ó%Ù˜iÓ(ØÙ˜jÓ)ØÙ˜gÓ&ØÙ˜jÓ)Ùðó
	
ð Ø CØô3ð: #ØØð	%Jàò%Jó7ð6%JñN 	ØÙ˜lÓ+Ùðó	
ð 	Ù˜iÓ(ØÙ˜jÓ)ØÙ˜jÓ)Ùðó
	
ð Ø RØô9ó<
Eó=ð<
Eñ 	ØÙ˜lÓ+Ùðó	
ð 	Ù˜iÓ(ØÙ˜jÓ)ØÙ˜jÓ)Ùðó
	
ð Ø HØô9ó<Ló=ð<Lñ 	ØÙ˜lÓ+Ùðó	
ð  	Ù˜iÓ(ØÙ˜jÓ)ØÙ˜jÓ)Ùð	ó	
ð Ø QØôO(ðV ,0Ø $ØØ"ð,
à(ð,
ð ð,
ð ð	,
ð
 ò,
óS(ðR,
ñ\ 	ØÙ˜lÓ+Ùðó	
ð 	Ù˜iÓ(ØÙ˜jÓ)ØÙ˜jÓ)Ùð	ó	
ð Ø RØôK&ðR ,0Ø $Ø"ð	1
à(ð1
ð ð1
ð ò	1
óO&ôN1
r;   rN   c                  ód   ‡ — e Zd ZdZej
                  ej
                  z   Zddœdˆ fd„Zdd„Zˆ xZ	S )ÚExponentialMovingWindowGroupbyzF
    Provide an exponential moving window groupby implementation.
    N)Ú_grouperc               óL  •— t        ‰| �  |g|¢­d|i|¤Ž |j                  s‚| j                  �ut	        j
                  t        | j                  j                  j                  «       «      «      }t        | j                  j                  |«      | j                  «      | _        y y y )Nrö   )r\   r]   ÚemptyrH   r/   ÚconcatenateÚliströ   Úindicesr±   rL   Útaker5   rh   )rl   rX   rö   r†   r‡   Úgroupby_orderrn   s         €r9   r]   z'ExponentialMovingWindowGroupby.__init__‹  s   ø€ Ü‰Ñ˜ÐA˜tÒA¨hÐA¸&ÒAà�yŠy˜TŸZ™ZÐ3äŸN™N¬4°·±×0EÑ0E×0LÑ0LÓ0NÓ+OÓPˆMÜ,Ø—
‘
—‘ Ó.Ø—‘óˆD�Lð 4ˆyr;   c                óP   — t        | j                  j                  t        ¬«      }|S )z“
        Return an indexer class that will compute the window start and end bounds

        Returns
        -------
        GroupbyIndexer
        )Úgroupby_indicesrÇ   )r   rö   rû   r   )rl   rÇ   s     r9   rx   z2ExponentialMovingWindowGroupby._get_window_indexer–  s&   € ô (Ø ŸM™M×1Ñ1Ü9ô
ˆð Ðr;   ©rá   râ   )rá   r   )
r¬   rí   rî   rï   rN   rð   r#   r]   rx   rò   ró   s   @r9   rõ   rõ   „  s.   ø„ ñð *×5Ñ5Ð8I×8UÑ8UÑU€Kà,0÷ 	÷r;   rõ   c                  óÚ   ‡ — e Zd Z	 	 	 	 	 	 	 	 	 	 	 dddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zd„ Zddd„Z	 	 	 d	 	 	 	 	 dd„Z	 	 	 	 d	 	 	 	 	 	 	 dd„Zddd	„Z	ddd
œd„Z
ˆ xZS )r|   NrU   c               ó(  •— |
�t        d«      ‚t        ‰| �	  |||||||||	|
|¬«       t        | j                  | j
                  | j                  | j                  |j                  «      | _	        t        |«      r|| _        || _        y t        d«      ‚)Nz0times is not implemented with online operations.)rX   rO   r4   r5   r6   rP   rQ   rR   rS   rH   rV   z$'numba' is the only supported engine)r`   r\   r]   r    ri   rQ   rR   rS   rk   Ú_meanr   rz   r{   r.   )rl   rX   rO   r4   r5   r6   rP   rQ   rR   rS   rH   rz   r{   rV   rn   s                 €r9   r]   z&OnlineExponentialMovingWindow.__init__¦  s¢   ø€ ð" ÐÜ%ØBóð ô 	‰ÑØØØØØØ#ØØØØØð 	ô 	
ô "Ø�I‰I�t—{‘{ D§N¡N°D·I±I¸s¿y¹yó
ˆŒ
ô ˜6Ô"Ø ˆDŒKØ!.ˆDÕäÐCÓDÐDr;   c                ó8   — | j                   j                  «        y)z=
        Reset the state captured by `update` calls.
        N)r  Úresetrw   s    r9   r  z#OnlineExponentialMovingWindow.resetÑ  s   € ð 	�
‰
×ÑÕr;   c                ó   — t        d«      ‚)Nzaggregate is not implemented.©r`   )rl   r…   r†   r‡   s       r9   r   z'OnlineExponentialMovingWindow.aggregate×  s   € Ü!Ð"AÓBÐBr;   c                ó   — t        d«      ‚)Nzstd is not implemented.r  )rl   r¨   r†   r‡   s       r9   r¦   z!OnlineExponentialMovingWindow.stdÚ  ó   € Ü!Ð";Ó<Ð<r;   c                ó   — t        d«      ‚)Nzcorr is not implemented.r  )rl   rÎ   rÏ   rœ   s       r9   rÐ   z"OnlineExponentialMovingWindow.corrÝ  s   € ô "Ð"<Ó=Ð=r;   c                ó   — t        d«      ‚)Nzcov is not implemented.r  )rl   rÎ   rÏ   r¨   rœ   s        r9   r¶   z!OnlineExponentialMovingWindow.covå  s   € ô "Ð";Ó<Ð<r;   c                ó   — t        d«      ‚)Nzvar is not implemented.r  r®   s      r9   r­   z!OnlineExponentialMovingWindow.varî  r	  r;   )ÚupdateÚupdate_timesc               ó²  — i }| j                   j                  dk(  }|�t        d«      ‚t        j                  t        | j                   j                  | j                  dz
     dz
  d«      t        j                  ¬«      }|�º| j                  j                  €t        d«      ‚d}|j                  |d<   |r;| j                  j                  t        j                  dd…f   }	|j                  |d	<   n%| j                  j                  }	|j                  |d
<   t        j                   |	|j#                  «       f«      }
n‰d}| j                   j                  |d<   |r| j                   j                  |d	<   n| j                   j                  |d
<   | j                   j%                  t        j                  d¬«      j#                  «       }
t'        di t)        | j*                  «      ¤Ž}| j                  j-                  |r|
n|
dd…t        j                  f   || j.                  |«      }|s|j1                  «       }||d } | j                   j2                  |fi |¤Ž}|S )a[  
        Calculate an online exponentially weighted mean.

        Parameters
        ----------
        update: DataFrame or Series, default None
            New values to continue calculating the
            exponentially weighted mean from the last values and weights.
            Values should be float64 dtype.

            ``update`` needs to be ``None`` the first time the
            exponentially weighted mean is calculated.

        update_times: Series or 1-D np.ndarray, default None
            New times to continue calculating the
            exponentially weighted mean from the last values and weights.
            If ``None``, values are assumed to be evenly spaced
            in time.
            This feature is currently unsupported.

        Returns
        -------
        DataFrame or Series

        Examples
        --------
        >>> df = pd.DataFrame({"a": range(5), "b": range(5, 10)})
        >>> online_ewm = df.head(2).ewm(0.5).online()
        >>> online_ewm.mean()
              a     b
        0  0.00  5.00
        1  0.75  5.75
        >>> online_ewm.mean(update=df.tail(3))
                  a         b
        2  1.615385  6.615385
        3  2.550000  7.550000
        4  3.520661  8.520661
        >>> online_ewm.reset()
        >>> online_ewm.mean()
              a     b
        0  0.00  5.00
        1  0.75  5.75
        r,   Nz update_times is not implemented.r+   r   r=   z;Must call mean with update=None first before passing updater¾   Úcolumnsr—   F)r¿   rq   )r©   rª   r`   r/   rj   r^   rk   rS   rD   r  Úlast_ewmr.   r¾   Únewaxisr  r—   rù   Úto_numpyÚastyper!   r   r{   Úrun_ewmrP   ÚsqueezeÚ_constructor)rl   r  r  r†   r‡   Úresult_kwargsÚis_frameÚupdate_deltasÚresult_fromÚ
last_valueÚnp_arrayÚ	ewma_funcrÈ   s                r9   r�   z"OnlineExponentialMovingWindow.meanñ  s  € ðX ˆØ×%Ñ%×*Ñ*¨aÑ/ˆØÐ#Ü%Ð&HÓIÐIÜŸ™Ü�×"Ñ"×(Ñ(¨¯©°Q©Ñ7¸!Ñ;¸QÓ?ÄrÇzÁzô
ˆð ÐØ�z‰z×"Ñ"Ð*Ü ØQóð ð ˆKØ%+§\¡\ˆM˜'Ñ"ÙØ!ŸZ™Z×0Ñ0´·±ºQ°Ñ?�
Ø+1¯>©>�˜iÒ(à!ŸZ™Z×0Ñ0�
Ø(.¯©�˜fÑ%Ü—~‘~ z°6·?±?Ó3DÐ&EÓF‰HàˆKØ%)×%7Ñ%7×%=Ñ%=ˆM˜'Ñ"ÙØ+/×+=Ñ+=×+EÑ+E�˜iÒ(à(,×(:Ñ(:×(?Ñ(?�˜fÑ%Ø×)Ñ)×0Ñ0´·±À%Ð0ÓH×QÑQÓSˆHÜ3ñ 
Ü × 2Ñ 2Ó3ñ
ˆ	ð —‘×#Ñ#Ù ‰H hªq´"·*±*¨}Ñ&=ØØ×ÑØó	
ˆñ Ø—^‘^Ó%ˆFØ˜˜Ð%ˆØ0�×#Ñ#×0Ñ0°ÑI¸=ÑIˆØˆr;   )NNNNr   TFr   Nrä   N)rX   r)   rO   rÜ   r4   rÜ   r5   rÝ   r6   rÜ   rP   rÞ   rQ   rß   rR   rß   rS   r$   rH   rà   rz   rc   r{   zdict[str, bool] | Nonerá   râ   r   )F)r¨   rß   rë   rì   rç   rè   rå   ræ   )r¬   rí   rî   r]   r  r   r¦   rÐ   r¶   r­   r�   rò   ró   s   @r9   r|   r|   ¥  sR  ø„ ð !Ø!Ø=AØ"Ø"#ØØØØ-1ØØ04ð)Eð ñ)Eàð)Eð ð)Eð ð	)Eð
 ;ð)Eð ð)Eð  ð)Eð ð)Eð ð)Eð ð)Eð +ð)Eð ð)Eð .ð)Eð  
õ!)EóVòCô=ð
 ,0Ø $Ø"ð	>à(ð>ð ð>ð ó	>ð ,0Ø $ØØ"ð=à(ð=ð ð=ð ð	=ð
 ó=ô=ð "&°D÷ Vð Vr;   r|   )
r3   rÜ   r4   rÜ   r5   rÜ   r6   rÜ   rá   r2   )rH   znp.ndarray | NDFramer5   rÝ   rá   znpt.NDArray[np.float64])JÚ
__future__r   rd   Ú	functoolsr   Útextwrapr   Útypingr   Únumpyr/   Úpandas._libs.tslibsr   Ú pandas._libs.window.aggregationsÚ_libsÚwindowÚaggregationsr    Úpandas.util._decoratorsr   Úpandas.core.dtypes.commonr	   r
   Úpandas.core.dtypes.dtypesr   Úpandas.core.dtypes.genericr   Úpandas.core.dtypes.missingr   Úpandas.corer   Úpandas.core.arrays.datetimeliker   Úpandas.core.indexers.objectsr   r   r   Úpandas.core.util.numba_r   r   Úpandas.core.window.commonr   Úpandas.core.window.docr   r   r   r   r   r   r   r   Úpandas.core.window.numba_r   r   Úpandas.core.window.onliner    r!   Úpandas.core.window.rollingr"   r#   Úpandas._typingr$   r%   r&   rË   r'   r(   Úpandas.core.genericr)   r:   rL   rN   rõ   r|   rq   r;   r9   ú<module>r9     s  ðÝ "ã Ý Ý Ý  ã å )ß >Ó >Ý '÷õ 6Ý 0Ý +å Ý 9÷ñ ÷
õ ,÷	÷ 	ó 	÷÷÷ñ
 ÷ñ ÷õ ,ðØðà
ðð ðð ð	ð
 óðB'Øð'à6ð'ð ó'ô:|
˜jô |
ô~Ð%6Ð8Oô ôBbÐ$;õ br;   