Add files via upload

This commit is contained in:
Redsandy 2022-03-11 23:58:33 +03:00 committed by GitHub
parent 632d5961be
commit c33e65cd83

108
Core/Ind_DonchianChannel.py Normal file
View File

@ -0,0 +1,108 @@
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 IDC:
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 getSMA(self,windowSMA):
return np.convolve(self.npCol, np.ones(int(windowSMA)), 'valid') / int(windowSMA)
def getAns(self):
ans={
'MaxExt':[],
'MinExt':[],
'x':[]
}
opMin={'dataType':'ohcl',
'action':'findExt',
'actionOptions':{'extremumtype':'min','valueType':'low'}
}
opMax={'dataType':'ohcl',
'action':'findExt',
'actionOptions':{'extremumtype':'max','valueType':'high'}
}
for i in range(self.options['window'],len(self.base_df)-self.options['shift']+1):
ans['MaxExt'].append(CoreTraidMath.CoreMath(self.base_df[i-self.options['window']:i],opMax).ans)
ans['x'].append(self.base_df['date'][i-1+self.options['shift']])
ans['MinExt'].append(CoreTraidMath.CoreMath(self.base_df[i-self.options['window']:i],opMin).ans)
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['MaxExt'],'date':self.ans['x']}) ,
'row':row,
'col':1,
'name':'MaxExt'
})
req.append({
'vtype':'Scatter',
'df':pd.DataFrame(
{'value':self.ans['MinExt'],'date':self.ans['x']}) ,
'row':row,
'col':1,
'name':'MinExt'
})
self.figDict=req
ans = CoreDraw.coreDraw(req,drawFig)
return ans