cleanup and restructuring
This commit is contained in:
parent
04eda1fec1
commit
d03f2fb7f6
@ -1,90 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
|
||||||
|
|
||||||
# This notebook is designed for ray integrations for signals
|
|
||||||
#
|
|
||||||
# lets load askbid candlesticks file.
|
|
||||||
|
|
||||||
# In[20]:
|
|
||||||
|
|
||||||
|
|
||||||
import market_trade.constants
|
|
||||||
import market_trade.dataloader
|
|
||||||
|
|
||||||
candlesticks_filepaths = [filepath for filepath in market_trade.constants.CANDLESTICK_DATASETS_PATH.iterdir()]
|
|
||||||
candlesticks_filepath = candlesticks_filepaths[0]
|
|
||||||
duka_interface = market_trade.dataloader.DukaMTInterface(candlesticks_filepath)
|
|
||||||
duka_interface.bid_candlesticks
|
|
||||||
|
|
||||||
|
|
||||||
# Let's test signal.
|
|
||||||
|
|
||||||
# In[21]:
|
|
||||||
|
|
||||||
|
|
||||||
import market_trade.signals.Signal1
|
|
||||||
|
|
||||||
bid_candlesticks_df = duka_interface.bid_candlesticks[:10000]
|
|
||||||
|
|
||||||
ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
|
|
||||||
indEl1 = {
|
|
||||||
'df': bid_candlesticks_df,
|
|
||||||
'params': ind_params,
|
|
||||||
'needFig': False,
|
|
||||||
'showOnlyIndex': False,
|
|
||||||
'drawFig': True
|
|
||||||
}
|
|
||||||
signal_result = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
|
|
||||||
signal_result.analiz
|
|
||||||
|
|
||||||
|
|
||||||
# Now let's design ray trainable.
|
|
||||||
|
|
||||||
# In[22]:
|
|
||||||
|
|
||||||
|
|
||||||
def trainable(config):
|
|
||||||
ind_params = {'MeanType': 'SMA',
|
|
||||||
'window': config['window'],
|
|
||||||
'valueType': config['value_type'],
|
|
||||||
'kDev': config['k_dev']}
|
|
||||||
indEl1 = {
|
|
||||||
'df': bid_candlesticks_df,
|
|
||||||
'params': ind_params,
|
|
||||||
'needFig': False,
|
|
||||||
'showOnlyIndex': False,
|
|
||||||
'drawFig': True
|
|
||||||
}
|
|
||||||
signal_result = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
|
|
||||||
tune.report(accuracy=signal_result.analiz["toch"])
|
|
||||||
|
|
||||||
|
|
||||||
# Let's create config space.
|
|
||||||
|
|
||||||
# In[23]:
|
|
||||||
|
|
||||||
|
|
||||||
from ray import tune
|
|
||||||
|
|
||||||
config = {
|
|
||||||
'window': tune.qrandint(5,100,5),
|
|
||||||
'value_type': tune.choice(['open', 'low', 'high', 'close']),
|
|
||||||
'k_dev': tune.uniform(1,4)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Let's run ray tune
|
|
||||||
|
|
||||||
# In[24]:
|
|
||||||
|
|
||||||
|
|
||||||
analysis = tune.run(trainable, config=config, num_samples=100, mode='max', metric='accuracy')
|
|
||||||
|
|
||||||
|
|
||||||
# Let's see who was the best
|
|
||||||
|
|
||||||
# In[31]:
|
|
||||||
|
|
||||||
|
|
||||||
analysis.best_config
|
|
||||||
|
|
||||||
@ -1,129 +0,0 @@
|
|||||||
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 market_trade.core.CoreTraidMath
|
|
||||||
import market_trade.core.CoreDraw
|
|
||||||
import market_trade.core.Ind_bollingerBands
|
|
||||||
import market_trade.signals.coreSignal
|
|
||||||
|
|
||||||
|
|
||||||
class SignalBollingerBands1(market_trade.signals.coreSignal.coreSignal):
|
|
||||||
def __init__(self,
|
|
||||||
IndDict={},
|
|
||||||
mode='retro',
|
|
||||||
):
|
|
||||||
super().__init__(name='1.1',mode=mode,target='nextBar',valeType='price')
|
|
||||||
self.IndDict=IndDict
|
|
||||||
self.BB=market_trade.core.Ind_bollingerBands.BB(
|
|
||||||
IndDict['BB']['df'],
|
|
||||||
IndDict['BB']['params'],
|
|
||||||
IndDict['BB']['needFig'],
|
|
||||||
IndDict['BB']['showOnlyIndex'],
|
|
||||||
IndDict['BB']['drawFig']
|
|
||||||
)
|
|
||||||
self.getAns()
|
|
||||||
if mode=='retro':
|
|
||||||
self.analiz=self.analiz()
|
|
||||||
|
|
||||||
def getAns(self):
|
|
||||||
if self.mode=='retro':
|
|
||||||
df=self.BB.base_df#.set_index('date')
|
|
||||||
#print (df)
|
|
||||||
df_ind=pd.DataFrame.from_dict({
|
|
||||||
'date': self.BB.ans['x'],
|
|
||||||
'BB': self.BB.ans['BB'],
|
|
||||||
'pSTD': self.BB.ans['pSTD'],
|
|
||||||
'mSTD': self.BB.ans['mSTD'],
|
|
||||||
})
|
|
||||||
self.df_ind=df_ind
|
|
||||||
#df_ind=df_ind.set_index('date')
|
|
||||||
#print(df_ind)
|
|
||||||
dictSig={}
|
|
||||||
ans_sig=[]
|
|
||||||
analizLst=[]
|
|
||||||
difSize=len(df)-len(df_ind)
|
|
||||||
for i in range(len(df_ind)):
|
|
||||||
#print(df.iloc[i+dif]['date'],df_ind.iloc[i]['date'])
|
|
||||||
if df.iloc[i+difSize]['close'] >df_ind.iloc[i]['pSTD']:
|
|
||||||
ans_sig.append(1)
|
|
||||||
elif df.iloc[i+difSize]['close'] <df_ind.iloc[i]['mSTD']:
|
|
||||||
ans_sig.append(-1)
|
|
||||||
else:
|
|
||||||
ans_sig.append(0)
|
|
||||||
|
|
||||||
self.ans={
|
|
||||||
'signal':ans_sig,
|
|
||||||
'dttm':self.BB.ans['x']
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return self.ans
|
|
||||||
|
|
||||||
def analiz(self):
|
|
||||||
df=self.BB.base_df
|
|
||||||
dictSig={}
|
|
||||||
ans_sig=self.ans['signal']
|
|
||||||
difSize=len(df)-len(self.df_ind)
|
|
||||||
analizLst=[]
|
|
||||||
for i in range(len(self.df_ind)-1):
|
|
||||||
if ans_sig[i]==1 and df.iloc[i+difSize]['close']<df.iloc[i+difSize+1]['high']:
|
|
||||||
analizLst.append(1)
|
|
||||||
elif ans_sig[i]==1 and df.iloc[i+difSize]['close']>=df.iloc[i+difSize+1]['low']:
|
|
||||||
analizLst.append(-1)
|
|
||||||
elif ans_sig[i]==-1 and df.iloc[i+difSize]['close']>df.iloc[i+difSize+1]['low']:
|
|
||||||
analizLst.append(1)
|
|
||||||
elif ans_sig[i]==-1 and df.iloc[i+difSize]['close']<=df.iloc[i+difSize+1]['high']:
|
|
||||||
analizLst.append(-1)
|
|
||||||
else:
|
|
||||||
analizLst.append(0)
|
|
||||||
|
|
||||||
self.analizLst=analizLst
|
|
||||||
|
|
||||||
t=0
|
|
||||||
f=0
|
|
||||||
zeroNum=0
|
|
||||||
for i in self.analizLst:
|
|
||||||
if i==1:
|
|
||||||
t=t+1
|
|
||||||
if i==-1:
|
|
||||||
f=f+1
|
|
||||||
if i==0:
|
|
||||||
zeroNum=zeroNum+1
|
|
||||||
|
|
||||||
ans={}
|
|
||||||
ans['chstota']=sum(self.analizLst)/len(self.analizLst)
|
|
||||||
ans['zeroNum %']=zeroNum/len(self.analizLst)
|
|
||||||
ans['t %']=t/len(self.analizLst)
|
|
||||||
ans['f %']=f/len(self.analizLst)
|
|
||||||
try:
|
|
||||||
ans['toch']=t/(t+f)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return ans
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
Signal_1
|
|
||||||
BB синал предсказывающий будет ли цена за следубщий бар больше\меньше цены закртыия текущего, если текущиий бар закрылся ниже\выше диапазона BB
|
|
||||||
|
|
||||||
ind_params={'MeanType':'SMA','window':5,'valueType':'low','kDev':2}
|
|
||||||
#df_candle[:3000],ind_params,True,False,True
|
|
||||||
indEl1={
|
|
||||||
'df':df_candle[:3000],
|
|
||||||
'params':ind_params,
|
|
||||||
'needFig':False,
|
|
||||||
'showOnlyIndex':False,
|
|
||||||
'drawFig':True
|
|
||||||
}
|
|
||||||
a=Signal_1.SignalB_B_1({'BB':indEl1})
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
"""
|
|
||||||
Signal_1
|
|
||||||
BB
|
|
||||||
синал
|
|
||||||
предсказывающий
|
|
||||||
будет
|
|
||||||
ли
|
|
||||||
цена
|
|
||||||
за
|
|
||||||
следубщий
|
|
||||||
бар
|
|
||||||
больше\меньше
|
|
||||||
цены
|
|
||||||
закртыия
|
|
||||||
текущего, если
|
|
||||||
текущиий
|
|
||||||
бар
|
|
||||||
закрылся
|
|
||||||
ниже\выше
|
|
||||||
диапазона
|
|
||||||
BB
|
|
||||||
"""
|
|
||||||
|
|
||||||
import market_trade.signals.Signal1
|
|
||||||
|
|
||||||
df_candle = []
|
|
||||||
ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
|
|
||||||
# df_candle[:3000],ind_params,True,False,True
|
|
||||||
# window 5..100 (5) | valueType: 'open', 'low' | 'kdev' : 1..4 (0.1)
|
|
||||||
indEl1 = {
|
|
||||||
'df': df_candle[:3000],
|
|
||||||
'params': ind_params,
|
|
||||||
'needFig': False,
|
|
||||||
'showOnlyIndex': False,
|
|
||||||
'drawFig': True
|
|
||||||
}
|
|
||||||
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
|
|
||||||
Loading…
x
Reference in New Issue
Block a user