Technical analysis - moving averages (pynance.tech.movave)

pynance.tech.movave.bollinger(eqdata, **kwargs)[source]

Bollinger bands

Returns bolldf, smadf where bolldf is a DataFrame containing Bollinger bands with columns ‘Upper’ and ‘Lower’ and smadf contains the simple moving average.

Parameters:

eqdata : DataFrame

Must include a column specified in the selection parameter or, if no selection parameter is given, a column ‘Adj Close’.

window : int, optional

Lookback period.

multiple : float, optional

Multiple of standard deviation above and below sma to use in calculating band value. Defaults to 2.0.

selection : str, optional

Column of eqdata on which to calculate bollinger bands. Defaults to ‘Adj Close’.

Returns:

bolldf : DataFrame

Dataframe containing columns ‘Upper’ and ‘Lower’ describing the given multiple of standard deviations above and below simple moving average for the lookback period.

smadf : DataFrame

Simple moving average given the specified lookback.

pynance.tech.movave.ema(eqdata, **kwargs)[source]

Exponential moving average with the given span.

Parameters:

eqdata : DataFrame

Must have exactly 1 column on which to calculate EMA

span : int, optional

Span for exponential moving average. Cf. pandas.stats.moments.ewma and additional Pandas documentation.

outputcol : str, optional

Column to use for output. Defaults to ‘EMA’.

selection : str, optional

Column of eqdata on which to calculate ema. If eqdata has only 1 column, selection is ignored, and ema is calculated on that column. Defaults to ‘Adj Close’.

Returns:

emadf : DataFrame

Exponential moving average using the given span.

pynance.tech.movave.ema_growth(eqdata, **kwargs)[source]

Growth of exponential moving average.

Parameters:

eqdata : DataFrame

span : int, optional

Span for exponential moving average. Defaults to 20.

outputcol : str, optional.

Column to use for output. Defaults to ‘EMA Growth’.

selection : str, optional

Column of eqdata on which to calculate ema growth. If eqdata has only 1 column, selection is ignored, and ema growth is calculated on that column. Defaults to ‘Adj Close’.

Returns:

out : DataFrame

Growth of exponential moving average from one day to next

pynance.tech.movave.growth_volatility(eqdata, **kwargs)[source]

Return the volatility of growth.

Note that, like pynance.tech.simple.growth() but in contrast to volatility(), growth_volatility() applies directly to a dataframe like that returned by pynance.data.retrieve.get(), not necessarily to a single-column dataframe.

Parameters:

eqdata : DataFrame

Data from which to extract growth volatility. An exception will be raised if eqdata does not contain a column ‘Adj Close’ or an optional name specified by the selection parameter.

window : int, optional

Window on which to calculate volatility. Defaults to 20.

selection : str, optional

Column of eqdata on which to calculate volatility of growth. Defaults to ‘Adj Close’

outputcol : str, optional

Column to use for output. Defaults to ‘Growth Risk’.

Returns:

out : DataFrame

Dataframe showing the volatility of growth over the specified window.

pynance.tech.movave.ratio_to_ave(window, eqdata, **kwargs)[source]

Return values expressed as ratios to the average over some number of prior sessions.

Parameters:

eqdata : DataFrame

Must contain a column with name matching selection, or, if selection is not specified, a column named ‘Volume’

window : int

Interval over which to calculate the average. Normally 252 (1 year)

selection : str, optional

Column to select for calculating ratio. Defaults to ‘Volume’

skipstartrows : int, optional

Rows to skip at beginning in addition to the window rows that must be skipped to get the baseline volume. Defaults to 0.

skipendrows : int, optional

Rows to skip at end. Defaults to 0.

outputcol : str, optional

Name of column in output dataframe. Defaults to ‘Ratio to Ave’

Returns:

out : DataFrame

pynance.tech.movave.sma(eqdata, **kwargs)[source]

simple moving average

Parameters:

eqdata : DataFrame

window : int, optional

Lookback period for sma. Defaults to 20.

outputcol : str, optional

Column to use for output. Defaults to ‘SMA’.

selection : str, optional

Column of eqdata on which to calculate sma. If eqdata has only 1 column, selection is ignored, and sma is calculated on that column. Defaults to ‘Adj Close’.

pynance.tech.movave.volatility(eqdata, **kwargs)[source]

Volatility (standard deviation) over the given window

Parameters:

eqdata : DataFrame

window : int, optional

Lookback period. Defaults to 20.

outputcol : str, optional

Name of column to be used in returned dataframe. Defaults to ‘Risk’.

selection : str, optional

Column of eqdata on which to calculate volatility. If eqdata has only 1 column, selection is ignored, and volatility is calculated on that column. Defaults to ‘Adj Close’.

Returns:

risk : DataFrame

Moving volatility with the given lookback.