Technical Indicators API Reference¶
Trend Indicators¶
financelib.trading.algo_trade.sma.sma(data: pd.Series, period: int = 20) -> pd.Series
¶
Calculate the Simple Moving Average.
SMA is the unweighted mean of the previous N data points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Series
|
Price series. |
required |
period
|
int
|
Number of periods to average (default: 20). |
20
|
Returns:
| Type | Description |
|---|---|
Series
|
SMA values as a pandas Series. |
Source code in financelib/trading/algo_trade/sma.py
financelib.trading.algo_trade.ema.ema(data: pd.Series, period: int = 20) -> pd.Series
¶
Calculate the Exponential Moving Average.
EMA gives more weight to recent prices, making it more responsive to new information than SMA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Series
|
Price series. |
required |
period
|
int
|
Number of periods for EMA span (default: 20). |
20
|
Returns:
| Type | Description |
|---|---|
Series
|
EMA values as a pandas Series. |
Source code in financelib/trading/algo_trade/ema.py
financelib.trading.algo_trade.macd.macd(data: pd.Series, fast_period: int = 12, slow_period: int = 26, signal_period: int = 9) -> Tuple[pd.Series, pd.Series]
¶
Calculate MACD (Moving Average Convergence Divergence).
MACD shows the relationship between two EMAs of prices. A signal line crossover indicates potential buy/sell signals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Series
|
Price series (typically close prices). |
required |
fast_period
|
int
|
Fast EMA period (default: 12). |
12
|
slow_period
|
int
|
Slow EMA period (default: 26). |
26
|
signal_period
|
int
|
Signal line EMA period (default: 9). |
9
|
Returns:
| Type | Description |
|---|---|
Tuple[Series, Series]
|
Tuple of (macd_line, signal_line) as pandas Series. |
Source code in financelib/trading/algo_trade/macd.py
financelib.trading.algo_trade.adx.adx(high: pd.Series, low: pd.Series, close: pd.Series, period: int = 14) -> pd.Series
¶
Calculate the Average Directional Index.
ADX measures the strength of a trend regardless of direction. Values above 25 indicate a strong trend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
high
|
Series
|
High price series. |
required |
low
|
Series
|
Low price series. |
required |
close
|
Series
|
Close price series. |
required |
period
|
int
|
Lookback period (default: 14). |
14
|
Returns:
| Type | Description |
|---|---|
Series
|
ADX values as a pandas Series. |
Source code in financelib/trading/algo_trade/adx.py
financelib.trading.algo_trade.aroon.aroon(high: pd.Series, low: pd.Series, period: int = 25) -> Tuple[pd.Series, pd.Series]
¶
Calculate the Aroon Indicator.
Aroon identifies whether a security is trending and how strong the trend is. Aroon Up above 70 = strong uptrend, Aroon Down above 70 = strong downtrend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
high
|
Series
|
High price series. |
required |
low
|
Series
|
Low price series. |
required |
period
|
int
|
Lookback period (default: 25). |
25
|
Returns:
| Type | Description |
|---|---|
Tuple[Series, Series]
|
Tuple of (aroon_up, aroon_down) as pandas Series (0-100 range). |
Source code in financelib/trading/algo_trade/aroon.py
Momentum Indicators¶
financelib.trading.algo_trade.rsi.rsi(data: pd.Series, period: int = 14) -> pd.Series
¶
Calculate the Relative Strength Index.
RSI measures the speed and magnitude of price changes to evaluate overbought (>70) or oversold (<30) conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Series
|
Price series (typically close prices). |
required |
period
|
int
|
Lookback period (default: 14). |
14
|
Returns:
| Type | Description |
|---|---|
Series
|
RSI values as a pandas Series (0-100 range). |
Source code in financelib/trading/algo_trade/rsi.py
financelib.trading.algo_trade.stochastic.stochastic(high: pd.Series, low: pd.Series, close: pd.Series, k_period: int = 14, d_period: int = 3) -> Tuple[pd.Series, pd.Series]
¶
Calculate the Stochastic Oscillator.
Compares a closing price to a range of prices over a period. %K above 80 = overbought, below 20 = oversold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
high
|
Series
|
High price series. |
required |
low
|
Series
|
Low price series. |
required |
close
|
Series
|
Close price series. |
required |
k_period
|
int
|
%K lookback period (default: 14). |
14
|
d_period
|
int
|
%D smoothing period (default: 3). |
3
|
Returns:
| Type | Description |
|---|---|
Tuple[Series, Series]
|
Tuple of (%K, %D) as pandas Series. |
Source code in financelib/trading/algo_trade/stochastic.py
financelib.trading.algo_trade.williams_r.williams_r(high: pd.Series, low: pd.Series, close: pd.Series, period: int = 14) -> pd.Series
¶
Calculate Williams %R.
Williams %R is a momentum indicator that measures overbought and oversold levels. Values range from -100 to 0. Above -20 = overbought, below -80 = oversold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
high
|
Series
|
High price series. |
required |
low
|
Series
|
Low price series. |
required |
close
|
Series
|
Close price series. |
required |
period
|
int
|
Lookback period (default: 14). |
14
|
Returns:
| Type | Description |
|---|---|
Series
|
Williams %R values as a pandas Series (-100 to 0 range). |
Source code in financelib/trading/algo_trade/williams_r.py
financelib.trading.algo_trade.cci.cci(high: pd.Series, low: pd.Series, close: pd.Series, period: int = 20) -> pd.Series
¶
Calculate the Commodity Channel Index.
CCI measures the current price relative to an average price level over a given period. Values above +100 may indicate overbought, below -100 may indicate oversold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
high
|
Series
|
High price series. |
required |
low
|
Series
|
Low price series. |
required |
close
|
Series
|
Close price series. |
required |
period
|
int
|
Lookback period (default: 20). |
20
|
Returns:
| Type | Description |
|---|---|
Series
|
CCI values as a pandas Series. |
Source code in financelib/trading/algo_trade/cci.py
Volatility Indicators¶
financelib.trading.algo_trade.bollinger_bands.bollinger_bands(data: pd.Series, period: int = 20, std_dev: int = 2) -> Tuple[pd.Series, pd.Series, pd.Series]
¶
Calculate Bollinger Bands.
Bollinger Bands consist of a middle SMA band with upper and lower bands at a specified number of standard deviations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Series
|
Price series (typically close prices). |
required |
period
|
int
|
SMA lookback period (default: 20). |
20
|
std_dev
|
int
|
Number of standard deviations for bands (default: 2). |
2
|
Returns:
| Type | Description |
|---|---|
Tuple[Series, Series, Series]
|
Tuple of (upper_band, middle_band, lower_band) as pandas Series. |
Source code in financelib/trading/algo_trade/bollinger_bands.py
financelib.trading.algo_trade.atr.atr(high: pd.Series, low: pd.Series, close: pd.Series, period: int = 14) -> pd.Series
¶
Calculate the Average True Range.
ATR measures market volatility by decomposing the entire range of a price for a given period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
high
|
Series
|
High price series. |
required |
low
|
Series
|
Low price series. |
required |
close
|
Series
|
Close price series. |
required |
period
|
int
|
Lookback period (default: 14). |
14
|
Returns:
| Type | Description |
|---|---|
Series
|
ATR values as a pandas Series. |