-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMovingAverage.py
More file actions
61 lines (46 loc) · 1.3 KB
/
Copy pathMovingAverage.py
File metadata and controls
61 lines (46 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''
Created on 04/09/2017
@author: michaelnew
'''
# 3rd parties
import pandas as pd
# Our Library
from Skyze_Indicators_Library.IndicatorAbstract import IndicatorAbstract
class MovingAverage(IndicatorAbstract):
'''
classdocs
'''
# Static Variables
name = "Moving Average"
version = 1.0
def __init__(self,
p_ma_period,
p_ma_column
):
''' Constructor '''
# Validate parameters ... raise exceptionality
if p_ma_period < 0:
pass
self.ma_period = p_ma_period
self.ma_column = p_ma_column
self.result = pd.DataFrame()
self.error = []
def initial(self, p_data):
"""Calculate the first value if the calc is different
to the subsequent calculations"""
return p_data
def calculate(self,
p_data # pd dataframe series
):
''' Calculations '''
p_data = self.initial(p_data)
p_data["MA_" + str(self.ma_period)] = p_data[self.ma_column].rolling(
window=self.ma_period).mean().shift(1)
return p_data
def getResult(self):
''' Getter '''
return self.result
@classmethod
def getName(self):
''' Getter '''
return self.name