o
    ?Bi                     @   s2  d Z ddlZddlZddlmZmZ G dd deZG dd deZ	G dd	 d	eZ
G d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdZdejfddZd[dejfd!d"Z	#		$	%	&	'	d\dejfd(d)Zd]dejfd+d,Z	d]dejfd-d.ZdZdejfd/d0Zd^dejfd3d4Zd_dejfd8d9Zd`d;ejd<ed=edejfd>d?Z		*	*	dad;ejd<ed@edAed=edejfdBdCZ		*	*	dad;ejd<ed@edAed=edejfdDdEZ 		*	*	dad;ejd<ed@edAed=edejfdFdGZ!	H	:	I	dbd;ejdJedKedLed=edejfdMdNZ"	dbd;ejdejfdOdPZ#	H	:	I	dbd;ejdJedKedLed=edejfdQdRZ$	H	:	I	dbdSejdJedKedLed=edejfdTdUZ%	H	:	I	dbdSejdJedKedLed=edejfdVdWZ&	H	:	I	dbdSejdJedKedLed=edejfdXdYZ'dS )czm
.. module:: momentum
   :synopsis: Momentum Indicators.

.. moduleauthor:: Dario Lopez Padial (Bukosabino)

    N)IndicatorMixin_emac                   @   B   e Zd ZdZddejdedefddZd	d
 Z	dejfddZ
dS )RSIIndicatora  Relative Strength Index (RSI)

    Compares the magnitude of recent gains and losses over a specified time
    period to measure speed and change of price movements of a security. It is
    primarily used to attempt to identify overbought or oversold conditions in
    the trading of an asset.

    https://www.investopedia.com/terms/r/rsi.asp

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n period.
        fillna(bool): if True, fill nan values.
       Fclosewindowfillnac                 C      || _ || _|| _|   d S N_close_window_fillna_runselfr   r   r	    r   K/var/www/html/Trade-python/venv/lib/python3.10/site-packages/ta/momentum.py__init__      zRSIIndicator.__init__c              	   C   s   | j d}||dkd}||dk d }| jrdn| j}|jd| j |dd }|jd| j |dd }|| }tjt	|dkdddd|   | j j
d| _d S )N   r   g        F)alphamin_periodsadjustd   index)r   diffwherer   r   ewmmeanpdSeriesnpr   _rsi)r   r   up_directiondown_directionr   emaupemadnrelative_strengthr   r   r   r   $   s&   zRSIIndicator._runreturnc                 C      | j | jdd}tj|ddS )zjRelative Strength Index (RSI)

        Returns:
            pandas.Series: New feature generated.
        2   valuersiname)_check_fillnar%   r"   r#   )r   
rsi_seriesr   r   r   r0   5      zRSIIndicator.rsiNr   F)__name__
__module____qualname____doc__r"   r#   intboolr   r   r0   r   r   r   r   r      s
    r   c                	   @   sL   e Zd ZdZ			ddejdededefd	d
Zdd Z	dejfddZ
dS )TSIIndicatoray  True strength index (TSI)

    Shows both trend direction and overbought/oversold conditions.

    https://school.stockcharts.com/doku.php?id=technical_indicators:true_strength_index

    Args:
        close(pandas.Series): dataset 'Close' column.
        window_slow(int): high period.
        window_fast(int): low period.
        fillna(bool): if True, fill nan values.
          Fr   window_slowwindow_fastr	   c                 C   s$   || _ || _|| _|| _|   d S r   )r   _window_slow_window_fastr   r   )r   r   r@   rA   r	   r   r   r   r   M   s
   zTSIIndicator.__init__c                 C   s   | j | j d }| jrdn| j}| jrdn| j}|j| j|dd j| j|dd }t|j| j|dd j| j|dd }|| | _|  jd9  _d S )Nr   r   F)spanr   r   r   )	r   shiftr   rB   rC   r    r!   abs_tsi)r   
diff_closemin_periods_rmin_periods_ssmoothedsmoothed_absr   r   r   r   Z   s*   
	


zTSIIndicator._runr+   c                 C   r,   )zfTrue strength index (TSI)

        Returns:
            pandas.Series: New feature generated.
        r   r.   tsir1   )r3   rG   r"   r#   )r   
tsi_seriesr   r   r   rM   p   r5   zTSIIndicator.tsiNr>   r?   F)r7   r8   r9   r:   r"   r#   r;   r<   r   r   rM   r   r   r   r   r=   ?   s     
r=   c                   @   sp   e Zd ZdZ							dd	ejd
ejdejdededededededefddZ	dd Z
dejfddZdS )UltimateOscillatoraT  Ultimate Oscillator

    Larry Williams' (1976) signal, a momentum oscillator designed to capture
    momentum across three different timeframes.

    http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:ultimate_oscillator

    BP = Close - Minimum(Low or Prior Close).
    TR = Maximum(High or Prior Close)  -  Minimum(Low or Prior Close)
    Average7 = (7-period BP Sum) / (7-period TR Sum)
    Average14 = (14-period BP Sum) / (14-period TR Sum)
    Average28 = (28-period BP Sum) / (28-period TR Sum)

    UO = 100 x [(4 x Average7)+(2 x Average14)+Average28]/(4+2+1)

    Args:
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        close(pandas.Series): dataset 'Close' column.
        window1(int): short period.
        window2(int): medium period.
        window3(int): long period.
        weight1(float): weight of short BP average for UO.
        weight2(float): weight of medium BP average for UO.
        weight3(float): weight of long BP average for UO.
        fillna(bool): if True, fill nan values with 50.
       r            @       @      ?Fhighlowr   window1window2window3weight1weight2weight3r	   c                 C   sH   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	| 
  d S r   )_high_lowr   _window1_window2_window3_weight1_weight2_weight3r   r   )r   rV   rW   r   rX   rY   rZ   r[   r\   r]   r	   r   r   r   r      s   zUltimateOscillator.__init__c           
      C   s"  | j d}| | j| j|}| j t| j|djddd }| jr%dn| j	}| jr-dn| j
}| jr5dn| j}|j| j	|d |j| j	|d  }|j| j
|d |j| j
|d  }|j| j|d |j| j|d  }	d| j| | j|  | j|	   | j| j | j  | _d S )Nr   )rW   r   F)axisskipnar   r   g      Y@)r   rE   _true_ranger^   r_   r"   	DataFrameminr   r`   ra   rb   rollingsumrc   rd   re   _uo)
r   close_shift
true_rangebuying_pressurerJ   min_periods_mmin_periods_lenavg_savg_mavg_lr   r   r   r      s@   
zUltimateOscillator._runr+   c                 C   r,   )z`Ultimate Oscillator

        Returns:
            pandas.Series: New feature generated.
        r-   r.   uor1   )r3   rn   r"   r#   )r   ultimate_oscr   r   r   ultimate_oscillator   r5   z&UltimateOscillator.ultimate_oscillatorNrQ   r   rR   rS   rT   rU   F)r7   r8   r9   r:   r"   r#   r;   floatr<   r   r   ry   r   r   r   r   rP   z   s@    !	

rP   c                   @   sh   e Zd ZdZ			ddejdejdejded	ed
efddZdd Z	dejfddZ
dejfddZdS )StochasticOscillatora  Stochastic Oscillator

    Developed in the late 1950s by George Lane. The stochastic
    oscillator presents the location of the closing price of a
    stock in relation to the high and low range of the price
    of a stock over a period of time, typically a 14-day period.

    https://school.stockcharts.com/doku.php?id=technical_indicators:stochastic_oscillator_fast_slow_and_full

    Args:
        close(pandas.Series): dataset 'Close' column.
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        window(int): n period.
        smooth_window(int): sma period over stoch_k.
        fillna(bool): if True, fill nan values.
    r      FrV   rW   r   r   smooth_windowr	   c                 C   s0   || _ || _|| _|| _|| _|| _|   d S r   )r   r^   r_   r   _smooth_windowr   r   )r   rV   rW   r   r   r~   r	   r   r   r   r      s   	zStochasticOscillator.__init__c                 C   sX   | j rdn| j}| jj| j|d }| jj| j|d }d| j|  ||  | _d S )Nr   rh   r   )	r   r   r_   rl   rk   r^   maxr   _stoch_k)r   r   sminsmaxr   r   r   r      s   zStochasticOscillator._runr+   c                 C   r,   )zbStochastic Oscillator

        Returns:
            pandas.Series: New feature generated.
        r-   r.   stoch_kr1   )r3   r   r"   r#   )r   r   r   r   r   stoch  r5   zStochasticOscillator.stochc                 C   sB   | j rdn| j}| jj| j|d }| j|dd}tj|ddS )ziSignal Stochastic Oscillator

        Returns:
            pandas.Series: New feature generated.
        r   rh   r-   r.   stoch_k_signalr1   )r   r   r   rl   r!   r3   r"   r#   )r   r   stoch_dr   r   r   stoch_signal  s   z!StochasticOscillator.stoch_signalNr   r}   F)r7   r8   r9   r:   r"   r#   r;   r<   r   r   r   r   r   r   r   r   r|      s*    
	r|   c                   @   sR   e Zd ZdZ				ddejdeded	ed
ef
ddZdd Z	dejfddZ
dS )KAMAIndicatora  Kaufman's Adaptive Moving Average (KAMA)

    Moving average designed to account for market noise or volatility. KAMA
    will closely follow prices when the price swings are relatively small and
    the noise is low. KAMA will adjust when the price swings widen and follow
    prices from a greater distance. This trend-following indicator can be
    used to identify the overall trend, time turning points and filter price
    movements.

    https://www.tradingview.com/ideas/kama/

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n period.
        pow1(int): number of periods for the fastest EMA constant.
        pow2(int): number of periods for the slowest EMA constant.
        fillna(bool): if True, fill nan values.
    
         Fr   r   pow1pow2r	   c                 C   *   || _ || _|| _|| _|| _|   d S r   )r   r   _pow1_pow2r   r   )r   r   r   r   r   r	   r   r   r   r   .     zKAMAIndicator.__init__c                 C   sD  | j j}tt| j t| j d }| jrdn| j}t|t|| j }|j	| j|d
 }tj||t||dkd}|d| jd  d| jd    d| jd   d j}t|j| _t| j}d}	t|D ]5}
t||
 rztj| j|
< qj|	r||
 | j|
< d	}	qj| j|
d  ||
 ||
 | j|
d     | j|
< qjd S )
Nr   r   rh   )outr   rT   rU   r   TF)r   valuesr"   r#   rF   r$   rollr   r   rl   rm   divide
zeros_liker   r   zerossize_kamalenrangeisnannan)r   close_valuesvolr   er_numer_denefficiency_ratiosmoothing_constantlen_kamafirst_valueir   r   r   r   =  s8   
zKAMAIndicator._runr+   c                 C   s2   t j| j| jjd}| j|| jd}t j|ddS )zuKaufman's Adaptive Moving Average (KAMA)

        Returns:
            pandas.Series: New feature generated.
        r   r.   kamar1   )r"   r#   r   r   r   r3   )r   kama_seriesr   r   r   r   _  s   zKAMAIndicator.kamaNr   r   r   F)r7   r8   r9   r:   r"   r#   r;   r<   r   r   r   r   r   r   r   r     s&    
"r   c                   @   r   )ROCIndicatoru  Rate of Change (ROC)

    The Rate-of-Change (ROC) indicator, which is also referred to as simply
    Momentum, is a pure momentum oscillator that measures the percent change in
    price from one period to the next. The ROC calculation compares the current
    price with the price “n” periods ago. The plot forms an oscillator that
    fluctuates above and below the zero line as the Rate-of-Change moves from
    positive to negative. As a momentum oscillator, ROC signals include
    centerline crossovers, divergences and overbought-oversold readings.
    Divergences fail to foreshadow reversals more often than not, so this
    article will forgo a detailed discussion on them. Even though centerline
    crossovers are prone to whipsaw, especially short-term, these crossovers
    can be used to identify the overall trend. Identifying overbought or
    oversold extremes comes naturally to the Rate-of-Change oscillator.

    https://school.stockcharts.com/doku.php?id=technical_indicators:rate_of_change_roc_and_momentum

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n period.
        fillna(bool): if True, fill nan values.
       Fr   r   r	   c                 C   r
   r   r   r   r   r   r   r     r   zROCIndicator.__init__c                 C   s,   | j | j | j | j | j d | _d S Nr   )r   rE   r   _roc)r   r   r   r   r     s
   
zROCIndicator._runr+   c                 C      |  | j}tj|ddS )zaRate of Change (ROC)

        Returns:
            pandas.Series: New feature generated.
        rocr1   )r3   r   r"   r#   )r   
roc_seriesr   r   r   r        zROCIndicator.rocNr   F)r7   r8   r9   r:   r"   r#   r;   r<   r   r   r   r   r   r   r   r   j  s
    r   c                   @   sR   e Zd ZdZ			ddejdejdeded	ef
d
dZdd Z	dejfddZ
dS )AwesomeOscillatorIndicatorup  Awesome Oscillator

    From: https://www.tradingview.com/wiki/Awesome_Oscillator_(AO)

    The Awesome Oscillator is an indicator used to measure market momentum. AO
    calculates the difference of a 34 Period and 5 Period Simple Moving
    Averages. The Simple Moving Averages that are used are not calculated
    using closing price but rather each bar's midpoints. AO is generally used
    to affirm trends or to anticipate possible reversals.

    From: https://www.ifcm.co.uk/ntx-indicators/awesome-oscillator

    Awesome Oscillator is a 34-period simple moving average, plotted through
    the central points of the bars (H+L)/2, and subtracted from the 5-period
    simple moving average, graphed across the central points of the bars
    (H+L)/2.

    MEDIAN PRICE = (HIGH+LOW)/2

    AO = SMA(MEDIAN PRICE, 5)-SMA(MEDIAN PRICE, 34)

    where

    SMA — Simple Moving Average.

    Args:
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        window1(int): short period.
        window2(int): long period.
        fillna(bool): if True, fill nan values with -50.
       "   FrV   rW   rX   rY   r	   c                 C   r   r   )r^   r_   r`   ra   r   r   )r   rV   rW   rX   rY   r	   r   r   r   r     r   z#AwesomeOscillatorIndicator.__init__c                 C   s^   d| j | j  }| jrdn| j}| jrdn| j}|j| j|d |j| j|d  | _d S )Ng      ?r   rh   )r^   r_   r   r`   ra   rl   r!   _ao)r   median_pricerJ   rs   r   r   r   r     s   zAwesomeOscillatorIndicator._runr+   c                 C   r,   )z_Awesome Oscillator

        Returns:
            pandas.Series: New feature generated.
        r   r.   aor1   )r3   r   r"   r#   )r   	ao_seriesr   r   r   awesome_oscillator  r5   z-AwesomeOscillatorIndicator.awesome_oscillatorNr   r   F)r7   r8   r9   r:   r"   r#   r;   r<   r   r   r   r   r   r   r   r     s$    %
	r   c                   @   sR   e Zd ZdZ		ddejdejdejdedef
d	d
Zdd Z	dejfddZ
dS )WilliamsRIndicatorau  Williams %R

    Developed by Larry Williams, Williams %R is a momentum indicator that is
    the inverse of the Fast Stochastic Oscillator. Also referred to as %R,
    Williams %R reflects the level of the close relative to the highest high
    for the look-back period. In contrast, the Stochastic Oscillator reflects
    the level of the close relative to the lowest low. %R corrects for the
    inversion by multiplying the raw value by -100. As a result, the Fast
    Stochastic Oscillator and Williams %R produce the exact same lines, only
    the scaling is different. Williams %R oscillates from 0 to -100.

    Readings from 0 to -20 are considered overbought. Readings from -80 to -100
    are considered oversold.

    Unsurprisingly, signals derived from the Stochastic Oscillator are also
    applicable to Williams %R.

    %R = (Highest High - Close)/(Highest High - Lowest Low) * -100

    Lowest Low = lowest low for the look-back period
    Highest High = highest high for the look-back period
    %R is multiplied by -100 correct the inversion and move the decimal.

    https://school.stockcharts.com/doku.php?id=technical_indicators:williams_r

    The Williams %R oscillates from 0 to -100. When the indicator produces
    readings from 0 to -20, this indicates overbought market conditions. When
    readings are -80 to -100, it indicates oversold market conditions.

    Args:
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        close(pandas.Series): dataset 'Close' column.
        lbp(int): lookback period.
        fillna(bool): if True, fill nan values with -50.
    r   FrV   rW   r   lbpr	   c                 C   r   r   )r^   r_   r   _lbpr   r   )r   rV   rW   r   r   r	   r   r   r   r     r   zWilliamsRIndicator.__init__c                 C   sX   | j rdn| j}| jj| j|d }| jj| j|d }d|| j  ||  | _d S )Nr   rh   i)	r   r   r^   rl   r   r_   rk   r   _wr)r   r   highest_high
lowest_lowr   r   r   r     s   zWilliamsRIndicator._runr+   c                 C   r,   )zXWilliams %R

        Returns:
            pandas.Series: New feature generated.
        ir.   wrr1   )r3   r   r"   r#   )r   	wr_seriesr   r   r   
williams_r  r5   zWilliamsRIndicator.williams_rNr6   )r7   r8   r9   r:   r"   r#   r;   r<   r   r   r   r   r   r   r   r     s"    *

r   c                   @   sZ   e Zd ZdZ				ddejdededed	ef
d
dZdd Z	dd Z
dd Zdd ZdS )StochRSIIndicatora  Stochastic RSI

    The StochRSI oscillator was developed to take advantage of both momentum
    indicators in order to create a more sensitive indicator that is attuned to
    a specific security's historical performance rather than a generalized analysis
    of price change.

    https://school.stockcharts.com/doku.php?id=technical_indicators:stochrsi
    https://www.investopedia.com/terms/s/stochrsi.asp

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n period
        smooth1(int): moving average of Stochastic RSI
        smooth2(int): moving average of %K
        fillna(bool): if True, fill nan values.
    r   r}   Fr   r   smooth1smooth2r	   c                 C   r   r   )r   r   _smooth1_smooth2r   r   )r   r   r   r   r   r	   r   r   r   r   8  r   zStochRSIIndicator.__init__c                 C   sf   t | j| j| jd | _| j| j }| j| | j| j |  | _	| j	| j
 | _d S )Nr   r   r	   )r   r   r   r   r0   r%   rl   rk   r   	_stochrsir   r!   _stochrsi_k)r   lowest_low_rsir   r   r   r   G  s   zStochRSIIndicator._runc                 C   r   )z[Stochastic RSI

        Returns:
            pandas.Series: New feature generated.
        stochrsir1   )r3   r   r"   r#   )r   stochrsi_seriesr   r   r   r   Q  r   zStochRSIIndicator.stochrsic                 C   r   )z^Stochastic RSI %k

        Returns:
            pandas.Series: New feature generated.
        
stochrsi_kr1   )r3   r   r"   r#   )r   stochrsi_k_seriesr   r   r   r   Z  r   zStochRSIIndicator.stochrsi_kc                 C   s*   | j | j }| |}tj|ddS )z^Stochastic RSI %d

        Returns:
            pandas.Series: New feature generated.
        
stochrsi_dr1   )r   rl   r   r!   r3   r"   r#   )r   stochrsi_d_seriesr   r   r   r   c  s   
zStochRSIIndicator.stochrsi_dNr   r}   r}   F)r7   r8   r9   r:   r"   r#   r;   r<   r   r   r   r   r   r   r   r   r   r   %  s*    

		r   c                   @   sZ   e Zd ZdZ				ddejdeded	ed
ef
ddZdd Z	dd Z
dd Zdd ZdS )PercentagePriceOscillatora
  
    The Percentage Price Oscillator (PPO) is a momentum oscillator that measures
    the difference between two moving averages as a percentage of the larger moving average.

    https://school.stockcharts.com/doku.php?id=technical_indicators:price_oscillators_ppo

    Args:
        close(pandas.Series): dataset 'Price' column.
        window_slow(int): n period long-term.
        window_fast(int): n period short-term.
        window_sign(int): n period to signal.
        fillna(bool): if True, fill nan values.
       r   	   Fr   r@   rA   window_signr	   c                 C   r   r   )r   rB   rC   _window_signr   r   )r   r   r@   rA   r   r	   r   r   r   r   }  r   z"PercentagePriceOscillator.__init__c                 C   \   t | j| j| j}t | j| j| j}|| | d | _t | j| j| j| _| j| j | _d S r   )	r   r   rC   r   rB   _ppor   _ppo_signal	_ppo_histr   _emafast_emaslowr   r   r   r     
   zPercentagePriceOscillator._runc                 C   .   | j | jdd}tj|d| j d| j dS )zmPercentage Price Oscillator Line

        Returns:
            pandas.Series: New feature generated.
        r   r.   PPO__r1   )r3   r   r"   r#   rC   rB   )r   
ppo_seriesr   r   r   ppo     zPercentagePriceOscillator.ppoc                 C   r   )ztPercentage Price Oscillator Signal Line

        Returns:
            pandas.Series: New feature generated.
        r   r.   	PPO_sign_r   r1   )r3   r   r"   r#   rC   rB   )r   ppo_signal_seriesr   r   r   
ppo_signal     z$PercentagePriceOscillator.ppo_signalc                 C   r   )zrPercentage Price Oscillator Histogram

        Returns:
            pandas.Series: New feature generated.
        r   r.   	PPO_hist_r   r1   )r3   r   r"   r#   rC   rB   )r   ppo_hist_seriesr   r   r   ppo_hist  r   z"PercentagePriceOscillator.ppo_histNr   r   r   F)r7   r8   r9   r:   r"   r#   r;   r<   r   r   r   r   r   r   r   r   r   r   n  s*    
r   c                   @   sr   e Zd ZdZ				ddejdeded	ed
ef
ddZdd Z	dejfddZ
dejfddZdejfddZdS )PercentageVolumeOscillatora8  
    The Percentage Volume Oscillator (PVO) is a momentum oscillator for volume.
    The PVO measures the difference between two volume-based moving averages as a
    percentage of the larger moving average.

    https://school.stockcharts.com/doku.php?id=technical_indicators:percentage_volume_oscillator_pvo

    Args:
        volume(pandas.Series): dataset 'Volume' column.
        window_slow(int): n period long-term.
        window_fast(int): n period short-term.
        window_sign(int): n period to signal.
        fillna(bool): if True, fill nan values.
    r   r   r   Fvolumer@   rA   r   r	   c                 C   r   r   )_volumerB   rC   r   r   r   )r   r   r@   rA   r   r	   r   r   r   r     r   z#PercentageVolumeOscillator.__init__c                 C   r   r   )	r   r   rC   r   rB   _pvor   _pvo_signal	_pvo_histr   r   r   r   r     r   zPercentageVolumeOscillator._runr+   c                 C   r   )zUPVO Line

        Returns:
            pandas.Series: New feature generated.
        r   r.   PVO_r   r1   )r3   r   r"   r#   rC   rB   )r   
pvo_seriesr   r   r   pvo  r   zPercentageVolumeOscillator.pvoc                 C   r   )zXSignal Line

        Returns:
            pandas.Series: New feature generated.
        r   r.   	PVO_sign_r   r1   )r3   r   r"   r#   rC   rB   )r   pvo_signal_seriesr   r   r   
pvo_signal  r   z%PercentageVolumeOscillator.pvo_signalc                 C   r   )zUHistgram

        Returns:
            pandas.Series: New feature generated.
        r   r.   	PVO_hist_r   r1   )r3   r   r"   r#   rC   rB   )r   pvo_hist_seriesr   r   r   pvo_hist  r   z#PercentageVolumeOscillator.pvo_histNr   )r7   r8   r9   r:   r"   r#   r;   r<   r   r   r   r   r   r   r   r   r   r     s*    
r   r   Fr+   c                 C      t | ||d S )a(  Relative Strength Index (RSI)

    Compares the magnitude of recent gains and losses over a specified time
    period to measure speed and change of price movements of a security. It is
    primarily used to attempt to identify overbought or oversold conditions in
    the trading of an asset.

    https://www.investopedia.com/terms/r/rsi.asp

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n period.
        fillna(bool): if True, fill nan values.

    Returns:
        pandas.Series: New feature generated.
    r   )r   r0   r   r   r   r   r0     s   r0   r>   r?   c                 C   s   t | |||d S )a  True strength index (TSI)

    Shows both trend direction and overbought/oversold conditions.

    https://en.wikipedia.org/wiki/True_strength_index

    Args:
        close(pandas.Series): dataset 'Close' column.
        window_slow(int): high period.
        window_fast(int): low period.
        fillna(bool): if True, fill nan values.

    Returns:
        pandas.Series: New feature generated.
    r   r@   rA   r	   )r=   rM   r  r   r   r   rM     s
   rM   rQ   rR   rS   rT   rU   c
           
      C   s    t | |||||||||	d
 S )a  Ultimate Oscillator

    Larry Williams' (1976) signal, a momentum oscillator designed to capture
    momentum across three different timeframes.

    http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:ultimate_oscillator

    BP = Close - Minimum(Low or Prior Close).
    TR = Maximum(High or Prior Close)  -  Minimum(Low or Prior Close)
    Average7 = (7-period BP Sum) / (7-period TR Sum)
    Average14 = (14-period BP Sum) / (14-period TR Sum)
    Average28 = (28-period BP Sum) / (28-period TR Sum)

    UO = 100 x [(4 x Average7)+(2 x Average14)+Average28]/(4+2+1)

    Args:
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        close(pandas.Series): dataset 'Close' column.
        window1(int): short period.
        window2(int): medium period.
        window3(int): long period.
        weight1(float): weight of short BP average for UO.
        weight2(float): weight of medium BP average for UO.
        weight3(float): weight of long BP average for UO.
        fillna(bool): if True, fill nan values with 50.

    Returns:
        pandas.Series: New feature generated.

    
rV   rW   r   rX   rY   rZ   r[   r\   r]   r	   )rP   ry   r  r   r   r   ry   +  s   +ry   r}   c                 C      t | |||||d S )a  Stochastic Oscillator

    Developed in the late 1950s by George Lane. The stochastic
    oscillator presents the location of the closing price of a
    stock in relation to the high and low range of the price
    of a stock over a period of time, typically a 14-day period.

    https://www.investopedia.com/terms/s/stochasticoscillator.asp

    Args:
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        close(pandas.Series): dataset 'Close' column.
        window(int): n period.
        smooth_window(int): sma period over stoch_k
        fillna(bool): if True, fill nan values.

    Returns:
        pandas.Series: New feature generated.
    rV   rW   r   r   r~   r	   )r|   r   r  r   r   r   r   d  s   r   c                 C   r  )a
  Stochastic Oscillator Signal

    Shows SMA of Stochastic Oscillator. Typically a 3 day SMA.

    https://www.investopedia.com/terms/s/stochasticoscillator.asp

    Args:
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        close(pandas.Series): dataset 'Close' column.
        window(int): n period.
        smooth_window(int): sma period over stoch_k
        fillna(bool): if True, fill nan values.

    Returns:
        pandas.Series: New feature generated.
    r  )r|   r   r  r   r   r   r     s   r   c                 C      t | ||||d S )a   Williams %R

    From: http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:williams_r

    Developed by Larry Williams, Williams %R is a momentum indicator that is
    the inverse of the Fast Stochastic Oscillator. Also referred to as %R,
    Williams %R reflects the level of the close relative to the highest high
    for the look-back period. In contrast, the Stochastic Oscillator reflects
    the level of the close relative to the lowest low. %R corrects for the
    inversion by multiplying the raw value by -100. As a result, the Fast
    Stochastic Oscillator and Williams %R produce the exact same lines, only
    the scaling is different. Williams %R oscillates from 0 to -100.

    Readings from 0 to -20 are considered overbought. Readings from -80 to -100
    are considered oversold.

    Unsurprisingly, signals derived from the Stochastic Oscillator are also
    applicable to Williams %R.

    %R = (Highest High - Close)/(Highest High - Lowest Low) * -100

    Lowest Low = lowest low for the look-back period
    Highest High = highest high for the look-back period
    %R is multiplied by -100 correct the inversion and move the decimal.

    From: https://www.investopedia.com/terms/w/williamsr.asp
    The Williams %R oscillates from 0 to -100. When the indicator produces
    readings from 0 to -20, this indicates overbought market conditions. When
    readings are -80 to -100, it indicates oversold market conditions.

    Args:
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        close(pandas.Series): dataset 'Close' column.
        lbp(int): lookback period.
        fillna(bool): if True, fill nan values with -50.

    Returns:
        pandas.Series: New feature generated.
    rV   rW   r   r   r	   )r   r   r  r   r   r   r     s
   )
r   r   r   c                 C   r  )u  Awesome Oscillator

    From: https://www.tradingview.com/wiki/Awesome_Oscillator_(AO)

    The Awesome Oscillator is an indicator used to measure market momentum. AO
    calculates the difference of a 34 Period and 5 Period Simple Moving
    Averages. The Simple Moving Averages that are used are not calculated
    using closing price but rather each bar's midpoints. AO is generally used
    to affirm trends or to anticipate possible reversals.

    From: https://www.ifcm.co.uk/ntx-indicators/awesome-oscillator

    Awesome Oscillator is a 34-period simple moving average, plotted through
    the central points of the bars (H+L)/2, and subtracted from the 5-period
    simple moving average, graphed across the central points of the bars
    (H+L)/2.

    MEDIAN PRICE = (HIGH+LOW)/2

    AO = SMA(MEDIAN PRICE, 5)-SMA(MEDIAN PRICE, 34)

    where

    SMA — Simple Moving Average.

    Args:
        high(pandas.Series): dataset 'High' column.
        low(pandas.Series): dataset 'Low' column.
        window1(int): short period.
        window2(int): long period.
        fillna(bool): if True, fill nan values with -50.

    Returns:
        pandas.Series: New feature generated.
    rV   rW   rX   rY   r	   )r   r   r  r   r   r   r     s
   $
r   r   r   r   c                 C   r  )a_  Kaufman's Adaptive Moving Average (KAMA)

    Moving average designed to account for market noise or volatility. KAMA
    will closely follow prices when the price swings are relatively small and
    the noise is low. KAMA will adjust when the price swings widen and follow
    prices from a greater distance. This trend-following indicator can be
    used to identify the overall trend, time turning points and filter price
    movements.

    https://www.tradingview.com/ideas/kama/

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n number of periods for the efficiency ratio.
        pow1(int): number of periods for the fastest EMA constant.
        pow2(int): number of periods for the slowest EMA constant.
        fillna(bool): if True, fill nan values.

    Returns:
        pandas.Series: New feature generated.
    r   r   r   r   r	   )r   r   r	  r   r   r   r     s
   
r   r   r   r   r	   c                 C   r  )u  Rate of Change (ROC)

    The Rate-of-Change (ROC) indicator, which is also referred to as simply
    Momentum, is a pure momentum oscillator that measures the percent change in
    price from one period to the next. The ROC calculation compares the current
    price with the price “n” periods ago. The plot forms an oscillator that
    fluctuates above and below the zero line as the Rate-of-Change moves from
    positive to negative. As a momentum oscillator, ROC signals include
    centerline crossovers, divergences and overbought-oversold readings.
    Divergences fail to foreshadow reversals more often than not, so this
    article will forgo a detailed discussion on them. Even though centerline
    crossovers are prone to whipsaw, especially short-term, these crossovers
    can be used to identify the overall trend. Identifying overbought or
    oversold extremes comes naturally to the Rate-of-Change oscillator.

    https://school.stockcharts.com/doku.php?id=technical_indicators:rate_of_change_roc_and_momentum

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n periods.
        fillna(bool): if True, fill nan values.

    Returns:
        pandas.Series: New feature generated.

    r   )r   r   r   r   r   r   r     s   r   r   r   c                 C   r  )a  Stochastic RSI

    The StochRSI oscillator was developed to take advantage of both momentum
    indicators in order to create a more sensitive indicator that is attuned to
    a specific security's historical performance rather than a generalized analysis
    of price change.

    https://www.investopedia.com/terms/s/stochrsi.asp

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n period
        smooth1(int): moving average of Stochastic RSI
        smooth2(int): moving average of %K
        fillna(bool): if True, fill nan values.
    Returns:
            pandas.Series: New feature generated.
    r   r   r   r   r	   )r   r   r
  r   r   r   r   2  
   
r   c                 C   r  )a  Stochastic RSI %k

    The StochRSI oscillator was developed to take advantage of both momentum
    indicators in order to create a more sensitive indicator that is attuned to
    a specific security's historical performance rather than a generalized analysis
    of price change.

    https://www.investopedia.com/terms/s/stochrsi.asp

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n period
        smooth1(int): moving average of Stochastic RSI
        smooth2(int): moving average of %K
        fillna(bool): if True, fill nan values.
    Returns:
            pandas.Series: New feature generated.
    r
  )r   r   r
  r   r   r   r   P  r  r   c                 C   r  )a  Stochastic RSI %d

    The StochRSI oscillator was developed to take advantage of both momentum
    indicators in order to create a more sensitive indicator that is attuned to
    a specific security's historical performance rather than a generalized analysis
    of price change.

    https://www.investopedia.com/terms/s/stochrsi.asp

    Args:
        close(pandas.Series): dataset 'Close' column.
        window(int): n period
        smooth1(int): moving average of Stochastic RSI
        smooth2(int): moving average of %K
        fillna(bool): if True, fill nan values.
    Returns:
            pandas.Series: New feature generated.
    r
  )r   r   r
  r   r   r   r   n  r  r   r   r   r@   rA   r   c                 C   r  aE  
    The Percentage Price Oscillator (PPO) is a momentum oscillator that measures
    the difference between two moving averages as a percentage of the larger moving average.

    https://school.stockcharts.com/doku.php?id=technical_indicators:price_oscillators_ppo

    Args:
        close(pandas.Series): dataset 'Price' column.
        window_slow(int): n period long-term.
        window_fast(int): n period short-term.
        window_sign(int): n period to signal.
        fillna(bool): if True, fill nan values.
    Returns:
        pandas.Series: New feature generated.
    r   r@   rA   r   r	   )r   r   r  r   r   r   r        r   c                 C   r  r  )r   r   r  r   r   r   r     s   r   c                 C   r  r  )r   r   r  r   r   r   r     r  r   r   c                 C      t | ||||d}| S as  
    The Percentage Volume Oscillator (PVO) is a momentum oscillator for volume.
    The PVO measures the difference between two volume-based moving averages as a
    percentage of the larger moving average.

    https://school.stockcharts.com/doku.php?id=technical_indicators:percentage_volume_oscillator_pvo

    Args:
        volume(pandas.Series): dataset 'Volume' column.
        window_slow(int): n period long-term.
        window_fast(int): n period short-term.
        window_sign(int): n period to signal.
        fillna(bool): if True, fill nan values.
    Returns:
        pandas.Series: New feature generated.
    )r   r@   rA   r   r	   )r   r   r   r@   rA   r   r	   	indicatorr   r   r   r        r   c                 C   r  r  )r   r   r  r   r   r   r     r  r   c                 C   r  r  )r   r   r  r   r   r   r   )  r  r   r6   rO   rz   r   r   r   r   r   r   )(r:   numpyr$   pandasr"   ta.utilsr   r   r   r=   rP   r|   r   r   r   r   r   r   r   r#   r0   rM   ry   r   r   r   r   r   r;   r<   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sd   1;_AP.DIIIJ
9!
.)  
 
 
 
 

!
$
$