def read_QT_HKDailyQuoteIndex_data(self, mydate): ''' 数据类型解析:: HKStkShares 港股股数(股) HKStkMV 港股市值(元) TurnoverRate 换手率 PERatio 市盈率 PS 市销率 PB 市净率 PCF 市现率 DividendRatioFY 股息率(报告期)(%) DividendRatioRW 股息率(近12个月)(%) ''' mydate_str = PyDating.dt_to_string(PyDating.ymd_int_to_dt(mydate), format='%Y-%m-%d') command = ''' select codetable.SecuCode,t.TradingDay,t.InsertTime,t.UpdateTime, t.HKStkShares, t.HKStkMV, t.TurnoverRate, t.PERatio,t.PETTM, t.PS, t.PB, t.PCF, t.DividendRatioFY, t.DividendRatioRW from QT_HKDailyQuoteIndex t left join HK_SecuCodeTable codetable on t.InnerCode = codetable.InnerCode where (codetable.SecuCategory = "港股" or codetable.SecuCategory = "H股") and t.TradingDay ="{TradingDay}" '''.format(TradingDay=mydate_str) dfdata, nlines = self.db.read(command) columns = "SecuCode,TradingDay,InsertTime,UpdateTime,HKStkShares,HKStkMV,TurnoverRate,PERatio,PETTM,PS,PB,PCF,DividendRatioFY,DividendRatioRW" columns_list = columns.split(",") dfdata = pd.DataFrame(data=dfdata, columns=columns_list) return dfdata
def HK_FinStatsDirectable(self, mydate): mydate_str = PyDating.dt_to_string(PyDating.ymd_int_to_dt(mydate), format='%Y-%m-%d') command = ''' select codetable.SecuCode,t.EndDate,t.DateTypeCode,t.InfoPublDateBS from HK_FinStatsDirectable t left join HK_SecuCodeTable codetable on t.CompanyCode = codetable.CompanyCode where (codetable.SecuCategory = "港股" or codetable.SecuCategory = "H股") and codetable.SecuCode="{company_code}" and t.EndDate <="{TradingDay}" '''.format(company_code='03998', TradingDay=mydate_str) dfdata, nlines = self.db.read(command) columns = "SecuCode,EndDate,DateTypeCode,InfoPublDateBS" columns_list = columns.split(",") dfdata = pd.DataFrame(data=dfdata, columns=columns_list) return dfdata
def read_QT_HKBefRehDQuote_data(self, mydate): mydate_str = PyDating.dt_to_string(PyDating.ymd_int_to_dt(mydate), format='%Y-%m-%d') command = ''' select codetable.SecuCode,t.TradingDay,t.OpenPrice from QT_HKBefRehDQuote t left join HK_SecuCodeTable codetable on t.InnerCode = codetable.InnerCode where (codetable.SecuCategory = "港股" or codetable.SecuCategory = "H股") and t.TradingDay ="{TradingDay}" '''.format(TradingDay=mydate_str) dfdata, nlines = self.db.read(command) columns = "SecuCode,TradingDay,OpenPrice" columns_list = columns.split(",") dfdata = pd.DataFrame(data=dfdata, columns=columns_list) return dfdata
def read_HK_MainIndex_data(self, mydate): mydate_str = PyDating.dt_to_string(PyDating.ymd_int_to_dt(mydate), format='%Y-%m-%d') command = ''' select codetable.SecuCode,t.BeginDate,t.EndDate,t.PeriodMark,t.FinancialYear,t.ROEWeighted,t.DividendRatio,t.CurrentRatio,t.BasicEPS,t.DebtAssetsRatio,t.DebtEquityRatio,t.OperatingRevenueGR1Y,t.OperProfitGR1Y,t.GrossIncomeGR1Y,t.BasicEPS1Y,t.NetProfitRatio,t.ROA,t.OperatingRevenueGR3Y,t.NPParentCompanyGR1Y,t.NPParentCompanyGR3Y from HK_MainIndex t left join HK_SecuCodeTable codetable on t.CompanyCode = codetable.CompanyCode where (codetable.SecuCategory = "港股" or codetable.SecuCategory = "H股") and t.PeriodMark = '12' and t.EndDate <="{TradingDay}" '''.format(TradingDay=mydate_str) dfdata, nlines = self.db.read(command) columns = "SecuCode,BeginDate,EndDate,PeriodMark,FinancialYear,ROEWeighted,DividendRatio,CurrentRatio,BasicEPS,DebtAssetsRatio,DebtEquityRatio,OperatingRevenueGR1Y,OperProfitGR1Y,GrossIncomeGR1Y,BasicEPS1Y,NetProfitRatio,ROA,OperatingRevenueGR3Y,NPParentCompanyGR1Y,NPParentCompanyGR3Y" columns_list = columns.split(",") dfdata = pd.DataFrame(data=dfdata, columns=columns_list) return dfdata
def read_HK_MainIndex_data(self, target, mydate): mydate_str = PyDating.dt_to_string(PyDating.ymd_int_to_dt(mydate), format='%Y-%m-%d') command = ''' select codetable.SecuCode,t.BeginDate,t.EndDate,t.PeriodMark,t.FinancialYear,t.ROEWeighted,t.DividendRatio,t.CurrentRatio,t.BasicEPS from HK_MainIndex t left join HK_SecuCodeTable codetable on t.CompanyCode = codetable.CompanyCode where (codetable.SecuCategory = "港股" or codetable.SecuCategory = "H股") and t.PeriodMark = '12' and codetable.SecuCode="{company_code}" and t.EndDate <="{TradingDay}" '''.format(company_code=target, TradingDay=mydate_str) dfdata, nlines = self.db.read(command) columns = "SecuCode,BeginDate,EndDate,PeriodMark,FinancialYear,ROEWeighted,DividendRatio,CurrentRatio,BasicEPS" columns_list = columns.split(",") dfdata = pd.DataFrame(data=dfdata, columns=columns_list) return dfdata
def read_trading_data(self, mydate): mydate_str = PyDating.dt_to_string(PyDating.ymd_int_to_dt(mydate), format='%Y-%m-%d') command = ''' select codetable.SecuCode, t.ClosePrice, t.OpenPrice, t.HighPrice, t.LowPrice, t.TurnoverVolume, t.TurnoverValue from QT_HKDailyQuote t left join HK_SecuCodeTable codetable on t.InnerCode = codetable.InnerCode where (t.TradingDay = "{}") and (codetable.SecuCode is not null) and (t.ClosePrice>0) '''.format(mydate_str) dfdata, nlines = self.db.read(command) columns = "SecuCode,ClosePrice,OpenPrice,HighPrice,LowPrice,VolumeValue,AmountValue" columns_list = columns.split(",") dfdata = pd.DataFrame(data=dfdata, columns=columns_list) return dfdata
def read_financeindex_data(self, mydate): finance_q = 3 mydate_str = PyDating.dt_to_string(PyDating.ymd_int_to_dt(mydate), format='%Y-%m-%d') this_qter = "第一季报,中期报告,第三季报,年度报告".split(",")[finance_q % 4] command = ''' select codetable.SecuCode, t.InfoPublDate,t.PerformancePublDate,t.PeriodicReportPublDate,t.PeriodMark,t.FinancialYear,t.TotalAssets,t.EPSBasic,t.EarningAfterTax,t.FinancialExpense,t.TotalShareholderEquity,t.NetOperateCashFlow,t.OperatingIncome from HK_FinancialIndex t left join HK_SecuCodeTable codetable on t.CompanyCode = codetable.CompanyCode where (codetable.SecuCategory = "港股" or codetable.SecuCategory = "H股") and (InfoSource="{}") and t.InfoPublDate <="{TradingDay}" '''.format(this_qter, TradingDay=mydate_str) dfdata, nlines = self.db.read(command) columns = "SecuCode,InfoPublDate,PerformancePublDate,PeriodicReportPublDate,PeriodMark,FinancialYear,TotalAssets,EPSBasic,EarningAfterTax,FinancialExpense,TotalShareholderEquity,NetOperateCashFlow,OperatingIncome" columns_list = columns.split(",") dfdata = pd.DataFrame(data=dfdata, columns=columns_list) return dfdata
def _prepare_update(self): self.GR.set_secucode(self.stocks_pool) data = self.GR.get_secucode_tradedata("ClosePrice", self.selectdate) stocks_price = list(data[self.selectdate].values) updatetime = PyDating.dt_to_string(PyDating.ymd_int_to_dt(self.today), format='%Y-%m-%d') stocks_dict = [] for i in range(len(stocks_price)): stocks_dict.append({ 'secuCode': self.stocks_pool[i], 'entryPrice': stocks_price[i], 'entryTime': updatetime }) return stocks_dict
def read_tradedays(self, days=250): command = ''' select TradingDay from QT_HKDailyQuote group by TradingDay order by TradingDay ''' fdata, nlines = self.db.read(command) fdata = [PyDating.dt_to_ymd_int(item[0]) for item in fdata] fdata = fdata[-days:] if self.limit_lstdate is not None: fdata = [x for x in fdata if x <= self.limit_lstdate] return fdata
def get_today(self): today1 = PyDating.get_today() return today1