
    Q-j                     r    d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
mZmZ 	 	 ddeded	ed
ededefdZy)    )sqrt)Series)DictLikeInt)sma)v_offsetv_pos_defaultv_seriesNcloselengthscalaroffsetkwargsreturnc                     t        |d      }t        |d      }t        | d|z  dz
        } | yt        |      }| j                  |      j	                         }|| |z
  z  |z  }||z  }|j                  dd      }|rt        ||      }	n|j                  |      j                         }	t        |	|z        }
|dk7  r|
j                  |      }
d	|v r|
j                  |d	   d
       d|sdnd d| |
_        d|
_        |
S )a  Ulcer Index

    This indicator, by Peter Martin, attempts to quantify downside volatility
    with a Quadratic Mean.

    Sources:
        * [tangotools](http://www.tangotools.com/ui/ui.htm)
        * [tradingtechnologies](https://library.tradingtechnologies.com/trade/chrt-ti-ulcer-index.html)
        * [wikipedia](https://en.wikipedia.org/wiki/Ulcer_index)

    Parameters:
        close (Series): ```close``` Series
        length (int): The period. Default: ```14```
        scalar (float): Bands scalar. Default: ```100```
        offset (int): Post shift. Default: ```0```

    Other Parameters:
        everget (value): Use Evergets' TradingView SMA.
            Default: ```False```
        fillna (value): ```pd.DataFrame.fillna(value)```

    Returns:
        (Series): 1 column
       d         NevergetFr   fillnaT)inplaceUI e_
volatility)r	   r
   r   rollingmaxpopr   sumr   shiftr   namecategory)r   r   r   r   r   highest_closedownsided2r   _uiuis              e/Users/jameslopez/projects/TradingBot25/.venv/lib/python3.12/site-packages/pandas_ta/volatility/ui.pyr)   r)   
   s   : 62&F63'FUAJN+E}fF MM&)--/M./-?H	H	BjjE*G"fojj $$&	cFl	B {XXf 6
		&"D	1 W2#.ax8BGBKI    )NNN)numpyr   pandasr   pandas_ta._typingr   r   pandas_ta.overlapr   pandas_ta.utilsr   r	   r
   r)    r+   r*   <module>r2      sV      + ! = =
 6:???/2??"*? ?r+   