diff --git a/Core/CoreTraidMath.py b/Core/CoreTraidMath.py index dda9770..523a80e 100644 --- a/Core/CoreTraidMath.py +++ b/Core/CoreTraidMath.py @@ -12,18 +12,10 @@ import statistics import datetime -import matplotlib.dates as mdates -import matplotlib.pyplot as plt -import mplfinance as mpf -import plotly -#import plotly.plotly as py -import plotly.graph_objs as go -# these two lines allow your code to show up in a notebook -from plotly.offline import init_notebook_mode, iplot -from plotly.subplots import make_subplots -init_notebook_mode() + + class CoreMath: @@ -48,8 +40,10 @@ class CoreMath: if self.params['action']=='findExt': ans = self.getExtremumValue() - if self.params['action']=='findMean': + elif self.params['action']=='findMean': ans = self.getMeanValue() + elif self.params['action']=='findSTD': + ans=self.getSTD() return ans @@ -102,6 +96,7 @@ class CoreMath: if self.params['actionOptions']['MeanType']=='SMA': ans=np.convolve(self.col, np.ones(self.params['actionOptions']['window']), 'valid') / self.params['actionOptions']['window'] #ans=self.col.rolling(window=self.params['actionOptions']['window']).mean().to_list() + if self.params['actionOptions']['MeanType']=='EMA': ans=self.col.ewm(span=self.params['actionOptions']['span'], adjust=False).mean().to_list() if self.params['actionOptions']['MeanType']=='WMA': @@ -114,4 +109,30 @@ class CoreMath: return(ans) + + def getSTD(self): + ''' + actionOptions: + window + + + + + + ''' + + ans=None + + + try: + window=self.params['actionOptions']['window'] + ans=np.asarray([]) + for i in range(len(self.col)-window+1): + ans=np.append(ans,np.std(self.col[i:i+window], ddof=1)) + + except: + #window = len(self.col) + ans=np.std(self.col, ddof=1) + + return ans