self._avg = self._inc.rolling(window=self._window, min_periods=self._min_periods).mean() self._std = self._inc.rolling(window=self._window, min_periods=self._min_periods).std() self._pos_std = self._std * 2 self._neg_std = -self._std * 2 @property def inc(self): return self._inc.rename('inc') @property def pos_std(self): return self._pos_std.rename('pos_std') @property def neg_std(self): return self._neg_std.rename('neg_std') @property def std(self): return self._std.rename('std') if __name__ == '__main__': _df = OHLC('2017-12-15', '2017-12-18', 'HSIc1') _macd = Macd(_df) _ma = Ma(_df, 10, 20, 30) print(_macd) print(_ma)
from pyqtgraph.Qt import QtCore, QtWidgets import sys from data_visualize import MainWindow from data_visualize.graph import * import experimental as test V_logger.info('初始化app') pg.setConfigOptions(leftButtonPan=True, crashWarning=True) # ------------------------------数据获取与整理---------------------------+ # 确定需要展示的K线范围 Start_Time, End_Time = date_range('present', bar_num=680) Symbol = symbol('HSI') symbols = ['HSIN8', 'HSENG$.JUL8'] # init_data_sub(symbol_list) # 初始化主图的历史ohlc,最新ohlc与指标数据的参数配置 ohlc = OHLC(symbols[0], minbar=600, ktype='1T', db='wh_same_month_min') ohlc(daterange=[Start_Time, End_Time]) i_ma = MA(ma10=10, ma20=20, ma30=30, ma60=60) i_macd = MACD(short=12, long=26, m=9) i_std = STD(window=60, min_periods=2) h_macd_hl_mark = MACD_HL_MARK() h_buysell = BuySell() trade_datas = TradeData(symbols[1]) extra_data = [i_ma, i_macd, i_std, h_macd_hl_mark, h_buysell, trade_datas] # 将指标假如到主图数据里 ohlc.active_ticker() # 让ticker数据推送生效 ohlc.active_price() # 让price数据推送生效 ohlc._thread_lock.acquire() for d in extra_data: ohlc + d ohlc._thread_lock.release()
from PyQt5.QtCore import Qt import sys from data_visualize import MainWindow from data_visualize.graph import * import experimental as test V_logger.info('初始化app') pg.setConfigOptions(leftButtonPan=True, crashWarning=True) # ------------------------------数据获取与整理---------------------------+ # 确定需要展示的K线范围 Start_Time, End_Time = date_range('present', bar_num=680) Symbol = symbol('HSI') symbol_list = ['HSIJ8'] # init_data_sub(symbol_list) # 初始化主图的历史ohlc,最新ohlc与指标数据的参数配置 ohlc = OHLC('HSIJ8', minbar=600, ktype='1T') ohlc(daterange=[Start_Time, End_Time]) i_ma = MA(ma10=10, ma20=20, ma30=30, ma60=60) i_macd = MACD(short=10, long=22, m=9) i_std = STD(window=60, min_periods=2) h_macd_hl_mark = MACD_HL_MARK() i_coincide = COINCIDE() h_buysell = BuySell() trade_datas = TradeData('HSENG$.APR8') extra_data = [ i_ma, i_macd, i_std, h_macd_hl_mark, h_buysell, i_coincide, trade_datas ] # 将指标假如到主图数据里 ohlc.active_ticker() # 让ticker数据推送生效 ohlc.active_price() #让price数据推送生效 ohlc._thread_lock.acquire()
from data_fetch.util import MONTH_LETTER_MAPS from data_fetch.trade_data import TradeData import datetime as dt import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtWidgets import sys pg.setConfigOptions(leftButtonPan=True, crashWarning=True) # ------------------------------数据获取与整理---------------------------+ # 确定需要展示的K先范围 start_time = dt.datetime.now() - dt.timedelta(minutes=680) end_time = dt.datetime.now() + dt.timedelta(minutes=10) symbol = 'HSI' + MONTH_LETTER_MAPS[dt.datetime.now().month] + str( dt.datetime.now().year)[-1] # 根据当前时间生成品种代码 # 初始化主图的历史ohlc,最新ohlc与指标数据的参数配置 ohlc = OHLC(start_time, end_time, 'HSIH8', minbar=580) tick_datas = NewOHLC('HSIH8') i_macd = Macd(short=10, long=22, m=9) i_ma = Ma(ma10=10, ma20=20, ma30=30, ma60=60) i_std = Std(window=60, min_periods=2) trade_datas = TradeData(start_time, end_time, 'HSENG$.MAR8') # 将指标假如到主图数据里 ohlc + i_ma ohlc + i_macd ohlc + i_std # -----------------------------------------------------------------------+ # -----------------------窗口与app初始化---------------------------------+ app = QtWidgets.QApplication(sys.argv) win = OHlCWidget() win.setWindowTitle(symbol + '实盘分钟图') # 各个初始化之间存在依赖关系,需要按照以下顺序初始化