Reference

Gander is a python library aimed at technical analysis of securities markets, such as the stock market. Gander contains functions for creating popular technical indicators, as well as plotting functions. Plotting functions are built using the Matplotlib library.

Adding technical indicators to a Pandas DataFrame

Simple Moving Average (SMA)

gander.indicators.calc_sma(df, window, column, new_column_name)

Calculate simple moving averages.

Calculate SMA for data frame columns and expand data frame with simple moving averages.

Parameters:
  • df (pandas.DataFrame() [float]) – Input/output data frame
  • window (int) – Number of data points to use in moving average
  • column (str) – which columns in data frame to perform calculations on
  • trim – Whether or not to trim NaN values
Returns:

Input dataframe with added sma column

Return type:

pandas.DataFrame() [float]

Exponential Moving Average (EMA)

gander.indicators.calc_ema(df, column, new_column_name, window=10, custom_a=None)

Calculate exponential moving average.

Parameters:
  • df (pandas.DataFrame() [float]) – Input data frame
  • window (int) – Number of data points to use in average
  • column (pandas.DataFrame() [float]) – One column dataframe to perform calculations on
  • new_column_name (str) – Name for new column of ema
  • custom_a (float) – Custom a for the geometric series \(a + ar + ar^2 + ... + ar^{n - 1}\).
Returns:

Input dataframe with added ema column

Return type:

pandas.DataFrame() [float]

Moving Average Convergence Divergence (MACD)

gander.indicators.calc_macd(df, ema_short, ema_long, window=9)

Create MACD fast-, signal line and Histogram from short and long EMAs.

Parameters:
  • df (pandas.DataFrame() [float]) – Input data frame
  • ema_short (pandas.DataFrame() [float]) – Short term EMA data
  • ema_long (pandas.DataFrame() [float]) – Long term EMA data
Returns:

Input dataframe with added macd columns

Return type:

pandas.DataFrame() [float]

Stochastic Oscillator (STOCH)

gander.indicators.calc_stoch(df, stoch_window=15, ema_window=4)

Add two columns to the dataframe, a %K and a %D line.

Parameters:
  • df (pandas.DataFrame() [float]) – Data frame to do and add calculations to
  • stoch_window (int) – Number of data points in the stochastic, including current data point.
  • ema_window (int) – number data points in ema smoothing of %K, %D — including current data point
Returns:

Input dataframe with added stochastic columns

Return type:

pandas.DataFrame() [float]

Impulse System

gander.indicators.calc_impulse(df, ema, macdh)

Calculate color according to the impulse system by Elder.

Parameters:
  • df (pandas.DataFrame() [float]) – Data frame to do and add calculations to
  • ema (str) – Pandas dataframe column. Normally ema13.
  • macd-h – Pandas dataframe column
Returns:

Input dataframe with added impulse column

Return type:

pandas.DataFrame() [float]

Force Index Oscillator

gander.indicators.calc_force(df, close, volume, col_name='force')

Calculate force indicator (Elder).

Parameters:
  • df (pandas.DataFrame() [float]) – Data frame to do and add calculations to
  • close (str) – Pandas dataframe column name close price
  • volume (str) – Pandas dataframe column name volume
  • col_name (str) – Pandas dataframe column name for new force calculations
Returns:

Input dataframe with added force column

Return type:

pandas.DataFrame() [float]

True Range (TR)

gander.indicators.calc_tr(df, high, low, close, col_name='tr')

Calculate True Range.

Parameters:
  • df (pandas.DataFrame() [float]) – Data frame to do and add calculations to
  • high (str) – Pandas dataframe column name high price
  • low (str) – Pandas dataframe column name low price
  • close (str) – Pandas dataframe column name close price
  • col_name (str) – Pandas dataframe column name for new tr calculations. Default “tr”
Returns:

Input dataframe with added force column

Return type:

pandas.DataFrame() [float]

Plotting

Candlesticks

gander.plotting.candles(df, ax, cwidth=0.6, lwidth=1, columns=None, colors=None, impulse=None)

Draw a candle chart in the figure main ax.

Parameters:
  • df (pandas.DataFrame() [float]) – Input data frame
  • ax (matplotlib.axes.Axes) – Axes instance of subplot to plot candles in
  • cwidth (float or int) – width of candle, 1 is full width, 0 is no width
  • lwidth (float or int) – width of grid line width
  • columns (dict [str]) –

    Dictionary of appropriate column names. Defaults are:

    cols = {"open": "open",
            "close": "close",
            "high": "high",
            "low": "low"
            }
    
  • colors (list [str]) – Colors to use for candles when impulse=None (Deafault). First color in list is for when closing price is higher than opening price. Second color is for when closing price is lower than opening price. Default is [“green”, red]
  • impulse (pandas.DataFrame() [str]) – Impulse system data, either “red”, “green” or “blue”

MACD

gander.plotting.macds(df, ax, fast, signal, macdh)

Plot macd fast- and signal line and histogram.

Parameters:
  • df (pandas.DataFrame() [float]) – Input data frame
  • ax (matplotlib.axes.Axes) – Axes instance of subplot to plot macd in
  • figsize – Size of figure in inches
  • fast (str) – Name of data frame column, fast line
  • signal (str) – Name of data frame column, signal line
  • macdh (str) – Name of data frame column, macd histogram

Force Index

gander.plotting.force(df, ax, force)

Draw force with differential coloring below and above zero.

Parameters:
  • df (pandas.DataFrame() [float]) – Input data frame
  • ax (matplotlib.axes.Axes) – Axes instance of subplot to plot macd in
  • force (str) – Name of data frame column, force

Stochastic Oscillator

gander.plotting.stochs(df, ax, raw, smooth)

Plot stochastic.

Parameters:
  • df (pandas.DataFrame() [float]) – Input data frame
  • ax (matplotlib.axes.Axes) – Axes instance of subplot to plot macd in
  • raw (str) – Name of data frame column, raw stachastic (%K)
  • smooth (str) – Name of data frame column, smoothed raw stachastic (%D)