diff --git a/Core/Ind_STD.py b/Core/Ind_STD.py new file mode 100644 index 0000000..a7f6489 --- /dev/null +++ b/Core/Ind_STD.py @@ -0,0 +1,88 @@ + +import pandas as pd +import datetime +import numpy as np +import plotly as pl +import plotly.graph_objs as go +import matplotlib.pyplot as plt +import math +import scipy +import random +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() + +import CoreTraidMath +import CoreDraw + +class ISTD: + def __init__(self, base_df,options={}, needFig=False,showOnlyIndex=True,drawFig=False): + self.base_df=base_df.reset_index(drop=True) + self.options=options + self.ans=self.getAns() + if needFig: + self.fig=self.pltShow(showOnlyIndex,drawFig) + + def getAns(self): + ans=None + try: + op={'dataType':'ohcl', + 'action':'findSTD', + 'actionOptions':{ + 'valueType':self.options['valueType'], + 'window':self.options['window'] + } + } + x=self.base_df['date'][self.options['window']-1:].to_list() + except: + op={'dataType':'ohcl', + 'action':'findSTD', + 'actionOptions':{'valueType':self.options['valueType']} + } + x=self.base_df['date'].to_list() + y= CoreTraidMath.CoreMath(self.base_df,op).ans + ans={'y':y,'x':x} + + + + return ans + def pltShow(self,showOnlyIndex,drawFig): + ans=None + req=[] + row=1 + if not showOnlyIndex: + + row=2 + req.append({ + 'vtype':'OCHL', + 'df':self.base_df, + 'row':1, + 'col':1, + 'name':'OHCL' + + }) + req.append({ + 'vtype':'Scatter', + 'df':pd.DataFrame( + {'value':self.ans['y'],'date':self.ans['x']}) , + 'row':row, + 'col':1, + 'name':'ISTD' + + }) + self.figDict=req + ans = CoreDraw.coreDraw(req,drawFig) + return ans \ No newline at end of file