# Moving Average¶

Moving Averages are implemented in finquant.moving_average.

The module provides functions to compute and visualise:

• Simple Moving Averages,
• Exponential Moving Averages,
• a band of Moving Averages (simple or exponential), and
• Bollinger Bands.
finquant.moving_average.compute_ma(data, fun, spans, plot=True)

Computes a band of moving averages (sma or ema, depends on the input argument fun) for a number of different time windows. If plot is True, it also computes and sets markers for buy/sell signals based on crossovers of the Moving Averages with the shortest/longest spans.

Input:
data: pandas.DataFrame with stock prices, only one column is expected. function that computes a moving average, e.g. sma (simple) or ema (exponential). list of integers, time windows to compute the Moving Average on. boolean (default: True), whether to plot the moving averages and buy/sell signales based on crossovers of shortest and longest moving average.
Output:
ma: pandas.DataFrame with moving averages of given data.
finquant.moving_average.ema(data, span=100)

Computes and returns the exponential moving average.

Note: the moving average is computed on all columns.

Input:
data: pandas.DataFrame with stock prices in columns int (defaul: 100), number of days/values over which the average is computed
Output:
ema: pandas.DataFrame of exponential moving average
finquant.moving_average.ema_std(data, span=100)

Computes and returns the standard deviation of the exponential moving average.

Input:
data: pandas.DataFrame with stock prices in columns int (defaul: 100), number of days/values over which the average is computed
Output:
ema_std: pandas.DataFrame of standard deviation of exponential moving average
finquant.moving_average.plot_bollinger_band(data, fun, span)

Computes and visualises a Bolling Band.

Input:
data: pandas.DataFrame with stock prices in columns function that computes a moving average, e.g. sma (simple) or ema (exponential). int (defaul: 100), number of days/values over which the average is computed
finquant.moving_average.sma(data, span=100)

Computes and returns the simple moving average.

Note: the moving average is computed on all columns.

Input:
data: pandas.DataFrame with stock prices in columns int (defaul: 100), number of days/values over which the average is computed
Output:
sma: pandas.DataFrame of simple moving average
finquant.moving_average.sma_std(data, span=100)

Computes and returns the standard deviation of the simple moving average.

Input:
data: pandas.DataFrame with stock prices in columns int (defaul: 100), number of days/values over which the average is computed
Output:
sma_std: pandas.DataFrame of standard deviation of simple moving average