def __init__(self,parent=None): self.parent = None super(dataManagerLayout,self).__init__() #mid data self.dataCenter = dataCenter.dataCenter() self.dfSymbolsToDownload = pd.DataFrame(columns=['code','name','c_name']) #mid 1) codesSource layoutCodesSource = self.initLayoutCodesSource() #mid 2) layoutCodeMover = self.initLayoutCodeMover() #mid 3) layoutCodesToDownload = self.initLayoutCodesTableToDownload() #mid 4) layoutDownloadParams = self.initDownloaderParams() #mid asignment self.addLayout(layoutCodesSource) self.addLayout(layoutCodeMover) self.addLayout(layoutCodesToDownload) self.addLayout(layoutDownloadParams) self.updateLocalSymbolsTable()
def getCandleData(self): import os, sys dataRoot = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'histdata')) sys.path.append(dataRoot) import dataCenter as dataCenter rowSelected = self.tableLocalSymbols.currentRow() if ((rowSelected < 0) and (self.tableLocalSymbols.rowCount() > 0)): rowSelected = 0 dataSource = {} dataSource['dataProvider'] = 'tushare' dataSource['storageFormat'] = 'mongodb' dataSource['dataPeriod'] = 'D' dataSource['symbol'] = self.tableLocalSymbols.item(rowSelected, 0).text() dataSource['dateStart'] = '2015-03-19' dataSource['dateEnd'] = '2015-12-31' dataSource['alone'] = True dataSource['overlay'] = False dataCenter = dataCenter.dataCenter() dataForCandle = dataCenter.retriveCandleData(params=dataSource) return dataForCandle
def getFeeds(self,timeFrom=None,timeTo=None): import os,sys xpower = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir,os.pardir,os.pardir,'midProjects','histdata')) sys.path.append(xpower) import dataCenter as dataCenter self.dataCenter = dataCenter.dataCenter() feeds = self.dataCenter.getFeedsForPAT(dataProvider = self.dataProvider,storageType = self.storageType,instruments = self.instruments, period=self.period,timeTo = timeTo,timeFrom=timeFrom) return feeds
def __init__(self,parent=None): super(DataManagerDialog,self).__init__(parent) import os,sys dataRoot = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir,os.pardir,'histdata')) sys.path.append(dataRoot) import dataCenter as dataCenter #mid data self.dataCenter = dataCenter.dataCenter() self.dfLocalSymbols = pd.DataFrame(columns=['code','name','c_name']) self.dfSymbolsToDownload = pd.DataFrame(columns=['code','name','c_name']) self.setWindowTitle(self.tr("DataManager")) self.initUI()
def subMain(): DC = dataCenter.dataCenter() remoteDataSourceType = 'mt5' localStorageType = 'mongodb' periodType = 'D' timeStart = dt.datetime(2000,10,20) timeEnd = dt.datetime.now() # 1)get codes form eastmoney codeList = getSymbols() # 2)download history data dataDict = DC.downloadHistData(providerType=remoteDataSourceType,storageType=localStorageType,periodType=periodType, codeList=codeList,timeFrom = timeStart,timeTo = timeEnd)
def getFeeds(self, timeFrom=None, timeTo=None): import os, sys xpower = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'midProjects', 'histdata')) sys.path.append(xpower) import dataCenter as dataCenter self.dataCenter = dataCenter.dataCenter() feeds = self.dataCenter.getFeedsForPAT(dataProvider=self.dataProvider, storageType=self.storageType, instruments=self.instruments, period=self.period, timeTo=timeTo, timeFrom=timeFrom) return feeds
def __init__(self, parent=None): '''mid 1)创建combobox组,并初始化值 2)依据combobox组的值初始化table 3)依据combobox,table初始化candleview ''' self.parent = None super(dataVisualizerLayout, self).__init__() #mid data self.dataCenter = dataCenter.dataCenter() #mid 1) local data selector layoutLocalDataSource = self.createDataSourceSelectorLayout() layoutLocalDataVisualizer = self.createDataVisualizerLayout() # bottom-------------------------------------------------------------------- self.addLayout(layoutLocalDataSource) self.addLayout(layoutLocalDataVisualizer)
def __init__(self,parent=None): '''mid 1)创建combobox组,并初始化值 2)依据combobox组的值初始化table 3)依据combobox,table初始化candleview ''' self.parent = None super(dataVisualizerLayout,self).__init__() #mid data self.dataCenter = dataCenter.dataCenter() #mid 1) local data selector layoutLocalDataSource = self.createDataSourceSelectorLayout() layoutLocalDataVisualizer = self.createDataVisualizerLayout() # bottom-------------------------------------------------------------------- self.addLayout(layoutLocalDataSource) self.addLayout(layoutLocalDataVisualizer)
def getRawData(): import os,sys dataRoot = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir,os.pardir,'histdata')) sys.path.append(dataRoot) import dataCenter as dataCenter dataSource={} dataSource['dataProvider'] = 'tushare' dataSource['storageFormat']='mongodb' dataSource['dataPeriod']='D' dataSource['symbol']='600028' dataSource['dateStart']='2015-03-19' dataSource['dateEnd']='2015-12-31' dataSource['alone'] = True dataSource['overlay'] = False dataCenter = dataCenter.dataCenter() data = dataCenter.retriveHistData(params = dataSource) return data
def getCandleData(code): #mid 1)获取历史数据 #df = ts.get_stock_basics() #date = df.ix['600848']['timeToMarket'] #上市日期YYYYMMDD #本接口还提供大盘指数的全部历史数据,调用时,请务必设定index参数为True, #由于大盘指数不存在复权的问题,故可以忽略autype参数。 df = ts.get_h_data(code,start='2013-06-03', end='2016-05-31') #前复权ts.get_h_data('002337', autype='hfq') #后复权 #ts.get_h_data('002337', autype=None) #不复权 #ts.get_h_data('002337', start='2015-01-01', end='2015-03-16') #两个日期之间的前复权数据 #ts.get_h_data('399106', index=True) #深圳综合指数 #mid 2)调用tushareDataManager将历史数据转换为candle数据 dc = dataCenter() dataForCandle = dc.tsCenter.__DataFrameToCandle__(df) return dataForCandle
def __init__(self,toPlot = True,instruments = [],shortPeriod = 20,longPeriod = 40,dataProvider = 'tushare',storageType = 'mongodb',period = 'D',toYear = '',fromYear='',money = None): self.instrument = instruments[0] self.shortPeriod = shortPeriod self.longPeriod = longPeriod self.toPlot = toPlot #mid data self.dataCenter = dataCenter.dataCenter() #mid dataProvider = tushareCsv|tushare|yahooCsv|yahoo|generic feeds = self.dataCenter.getFeedsForPAT(dataProvider = dataProvider,storageType = storageType,instruments = instruments,period=period, timeTo = toYear,timeFrom=fromYear) self.feed = feeds[self.instrument] #mid money self.money = money #mid strategy self.strat = dma_crossover.DMACrossOver(feed=self.feed, instrument=self.instrument,shortPeriod=self.shortPeriod, longPeriod=self.longPeriod,money=money) #self.strat.setUseAdjustedValues(False) #mid results self.initAnalyzer()
def getCandleData(self): import os,sys dataRoot = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir,os.pardir,'histdata')) sys.path.append(dataRoot) import dataCenter as dataCenter rowSelected = self.tableLocalSymbols.currentRow() if((rowSelected<0) and (self.tableLocalSymbols.rowCount()>0)): rowSelected = 0 dataSource={} dataSource['dataProvider'] = 'tushare' dataSource['storageFormat']='mongodb' dataSource['dataPeriod']='D' dataSource['symbol']=self.tableLocalSymbols.item(rowSelected,0).text() dataSource['dateStart']='2015-03-19' dataSource['dateEnd']='2015-12-31' dataSource['alone'] = True dataSource['overlay'] = False dataCenter = dataCenter.dataCenter() dataForCandle = dataCenter.retriveCandleData(params = dataSource) return dataForCandle
def run(self,timeFrom = None,timeTo = None): self.timeFrom = timeFrom self.timeTo = timeTo self.dataCenter = dataCenter.dataCenter() feeds = self.dataCenter.getFeedsForPAT(dataProvider = self.dataProvider,storageType = self.storageType,instruments = self.instruments, period=self.period,timeTo = timeTo,timeFrom=timeFrom) self.feed = feeds[self.instrument] #mid strategy self.strat = dma_crossover.DMACrossOver(feed=self.feed, instrument=self.instrument,shortPeriod=self.shortPeriod, longPeriod=self.longPeriod,money=self.money) #self.strat.setUseAdjustedValues(False) #mid results self.initAnalyzer() result = self.strat.run() if(self.toPlot): analyzer = Analyzer(Globals=[]) dataForCandle = dataCenter.getCandleData(dataProvider = self.dataProvider,dataStorage = self.storageType,dataPeriod = self.period, symbol = self.instrument,dateStart=timeFrom,dateEnd = timeTo) analyzer.analyze(result,dataForCandle) self.analyzers.append(analyzer) return result
os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'midProjects', 'histdata')) sys.path.append(xpower) import dataCenter as dataCenter from Analyzers.Analyzer01 import Analyzer01 from Analyzers.Analyzer02 import Analyzer02 from Analyzers.Analyzer03 import Analyzer03 from Analyzers.Analyzer04 import Analyzer04 from Analyzers.Analyzer05 import Analyzer05 from Analyzers.PriceScatter import PriceScatter dataSource = params['dataSource'] algo = params['algo'] dataCenter = dataCenter.dataCenter() dataForZipline = dataCenter.getFeedsForZipline(dataSource) dataForCandle = dataCenter.retriveCandleData(params=dataSource) def dumpDict(dictStr): """""" import json jsonDumpsIndentStr = json.dumps(dictStr, indent=4, skipkeys=False, default=str, sort_keys=True) print(jsonDumpsIndentStr)
601788.SH 601800.SH 601818.SH 601857.SH 601919.SH 601985.SH 601988.SH 601989.SH 601998.SH """ #mid 2)将字符串使用split()分割为list,默认会去除\n和所有空格。 #codeList = ['000021.SZ','000022.SZ'] codeList = codesStr.split() dataCenter = dataCenter.dataCenter() remoteDataSourceType = 'eastmoney' localStorageType = 'mongodb' periodType = 'D' timeStart = dt.datetime(2010,10,20) timeEnd = dt.datetime.now() # 2)download history data dataDict = dataCenter.downloadHistData(providerType=remoteDataSourceType,storageType=localStorageType,periodType=periodType, codeList=codeList,timeFrom = timeStart,timeTo = timeEnd)