def jieba_initialize(self): #结巴可以添加两个词典,是add过程 log_exp.debug('initialize jieba vocab...') jieba.load_userdict(project_path() + '/resource/segDic/others.txt') jieba.load_userdict(project_path() + '/resource/segDic/THUOCL_caijing.txt') # jieba.load_userdict(utils.project_path() + '/resource/segDic/vocab.txt') # 当前词典很多和其他词典覆盖的地方,不能直接用 self.stopwords = { line.strip() for line in open( project_path() + '/resource/segDic/stop_words.txt', 'r').readlines() } jieba.initialize()
def get_data(data_name='bitfinex_dataETHUSD.h5',rule_type = '15T'): ''' 读取数据 :return: ''' # 导入数据 all_data = pd.read_hdf(utils.project_path()+'/data/'+data_name, key='data') # 转换数据周期 all_data = evaluate.transfer_to_period_data(all_data, rule_type) # 选取时间段 all_data = all_data[all_data['candle_begin_time'] >= pd.to_datetime('2018-11-01')] all_data.reset_index(inplace=True, drop=True) return all_data
def write_2_file_hdf5(kData,path='/result/default.h5'): ''' 读写h5文件 :param kData:df :param path: :param is_read: :return: ''' path_t = utils.project_path()+path # HDF5的写入: # 压缩格式存储 h5 = pd.HDFStore(path_t, 'w', complevel=4, complib='blosc') h5['data'] = kData h5.close() utils.log_exp.info('写入完成')
log_exp.debug('持多仓信号为%d,当前信号为%d, 继续做多!', state[1], flag) elif state[1] == -2: # 迁移状态为-2 if flag == 0 or flag == 1 or flag == -2: # ===止损:涨幅达到一定量就平 if ((df_copy.loc[index, 'close'] - df_copy.loc[state[0], 'close']) / df_copy.loc[state[0], 'close']) > self.th4: df_sell.loc[index, 'signal_sell'] = -20 state = (0, 0, -20) # 平仓掉了之前的状态 else: # 智能止盈,由下往上穿越中线并达到波动量则平仓 if (df_copy.loc[index, 'bbPb'] <= 0.5) and (df_copy.loc[index - 1, 'bbPb'] > 0.5): df_sell.loc[index, 'signal_sell'] = -20 state = (0, 0, -20) # 平仓掉了之前的状态 elif flag == 2 or flag == -1: # 【穿越下线的两种形态】 log_exp.debug('持空仓信号为%d,当前信号为%d, 继续做空!', state[1], flag) pass return state if __name__ == '__main__': para_now = [90, 3.2, 0.04, 0.05, 1.4, 0.15] data = pd.read_excel(utils.project_path() + '/excel_output.xls', sheet_name='src') # 计算交易信号 ins = BollingAdvanced() df = ins.signal_bolling(data, para=para_now) pass
def __init__(self, db_file): """ :param db: 数据库文件链接, 默认 在datacache文件夹下 """ self.db = project_path() + '/datacache/' + db_file
import pandas as pd from common import utils if __name__ == '__main__': all_data = pd.read_hdf(utils.project_path() + '/data/next/bitfinex_dataXRPUSD.h5') #temp_data = pd.read_hdf(utils.project_path()+'/data/bitfinex_dataETH.h5') all_data.rename(columns={ '开盘时间': 'candle_begin_time', '开盘价': 'open', '最高价': 'high', '最低价': 'low', '收盘价': 'close', '交易数量': 'volume' }, inplace=True) all_data.drop(['交易品种'], axis=1, inplace=True) all_data.reset_index(inplace=True, drop=True) # 压缩格式存储 h5 = pd.HDFStore(utils.project_path() + '/data/bitfinex_dataXRPUSD.h5', 'w', complevel=4, complib='blosc') h5['data'] = all_data h5.close() pass
async def index(request): with open(project_path() + '/webUI/templates/search.html', encoding='utf-8') as html_file: template = Template(html_file.read()) return response.html(template.render(name='index2'))