MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / ma

Function ma

alphapy/transforms.py:889–916  ·  view source on GitHub ↗

r"""Calculate the mean on a rolling basis. Parameters ---------- f : pandas.DataFrame Dataframe containing the column ``c``. c : str Name of the column in the dataframe ``f``. p : int The period over which to calculate the rolling mean. Returns -

(f, c, p = 20)

Source from the content-addressed store, hash-verified

887#
888
889def ma(f, c, p = 20):
890 r"""Calculate the mean on a rolling basis.
891
892 Parameters
893 ----------
894 f : pandas.DataFrame
895 Dataframe containing the column ``c``.
896 c : str
897 Name of the column in the dataframe ``f``.
898 p : int
899 The period over which to calculate the rolling mean.
900
901 Returns
902 -------
903 new_column : pandas.Series (float)
904 The array containing the new feature.
905
906 References
907 ----------
908 *In statistics, a moving average (rolling average or running average)
909 is a calculation to analyze data points by creating series of averages
910 of different subsets of the full data set* [WIKI_MA]_.
911
912 .. [WIKI_MA] https://en.wikipedia.org/wiki/Moving_average
913
914 """
915 new_column = f[c].rolling(p).mean()
916 return new_column
917
918
919#

Callers 6

abovemaFunction · 0.85
belowmaFunction · 0.85
maratioFunction · 0.85
rsiFunction · 0.85
xmadownFunction · 0.85
xmaupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected