From f63e57e140dba94ff0e22d75fe4cc5e35534b358 Mon Sep 17 00:00:00 2001 From: Redsandy <34872843+Redsandyg@users.noreply.github.com> Date: Sun, 20 Mar 2022 03:01:14 +0300 Subject: [PATCH] Add files via upload --- Core/Ind_LRI.py | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Core/Ind_LRI.py diff --git a/Core/Ind_LRI.py b/Core/Ind_LRI.py new file mode 100644 index 0000000..d518592 --- /dev/null +++ b/Core/Ind_LRI.py @@ -0,0 +1,104 @@ + +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 LRI: + 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.col=self.base_df[self.options['valueType']] + self.ans=self.getAns() + if needFig: + self.fig=self.pltShow(showOnlyIndex,drawFig) + + def getAns(self): + ans=None + + l=np.asarray(list(range(len(self.col)))) + k,b=np.polyfit(l,self.col,1) + setattr(self,'k',k) + setattr(self,'b',b) + b1=b+self.options['k']*pow(1-k*k,0.5) + b2=b-self.options['k']*pow(1-k*k,0.5) + ans={ + 'LRI':l*k+b, + 'LRI+':l*k+b1, + 'LRI-':l*k+b2, + 'x':self.base_df['date'] + } + + + + 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['LRI'],'date':self.ans['x']}) , + 'row':row, + 'col':1, + 'name':'LRI' + + }) + req.append({ + 'vtype':'Scatter', + 'df':pd.DataFrame( + {'value':self.ans['LRI+'],'date':self.ans['x']}) , + 'row':row, + 'col':1, + 'name':'LRI+' + + }) + req.append({ + 'vtype':'Scatter', + 'df':pd.DataFrame( + {'value':self.ans['LRI-'],'date':self.ans['x']}) , + 'row':row, + 'col':1, + 'name':'LRI-' + + }) + self.figDict=req + ans = CoreDraw.coreDraw(req,drawFig) + return ans \ No newline at end of file