def GetStockSectionValue(self, euSs, strStockWindCode, dtTradingDay): if (isinstance(euSs, EU_StockSection) == False): print( 'GetStockSectionValue: euSs is not instance of EU_StockSection: ', euSs) return None nStockId = stockCn.StockWindCode2Int(strStockWindCode) if (nStockId == None): print('GetStockSectionValue: strStockWindCode Error: ', nStockId) return None nTradingDay = dtTradingDay if (isinstance(dtTradingDay, int) == False): strTradingDay = dateTime.ToIso(dtTradingDay) if (strTradingDay == None): return None nTradingDay = int(strTradingDay) if (nTradingDay == None): print('GetStockSectionValue: dtTradingDay Error: ', dtTradingDay) if (nTradingDay not in self.__dictStockSectionsByTd.keys()): print('GetStockSectionValue: nTradingDay is not in : ', nTradingDay) return None if (nStockId not in self.__dictStockSectionsByTd[nTradingDay].keys()): print('GetStockSectionValue: nStockId is not in : ', nStockId) return None dValue = None if (euSs == EU_StockSection.euSs_Pe): dValue = self.__dictStockSectionsByTd[nTradingDay][nStockId].dPe elif (euSs == EU_StockSection.euSs_Pb): dValue = self.__dictStockSectionsByTd[nTradingDay][nStockId].dPb elif (euSs == EU_StockSection.euSs_Pcf): dValue = self.__dictStockSectionsByTd[nTradingDay][nStockId].dPcf elif (euSs == EU_StockSection.euSs_Ps): dValue = self.__dictStockSectionsByTd[nTradingDay][nStockId].dPs elif (euSs == EU_StockSection.euSs_MarketValueTotal): dValue = self.__dictStockSectionsByTd[nTradingDay][ nStockId].d_val_mv elif (euSs == EU_StockSection.euSs_MarketValueFlowing): dValue = self.__dictStockSectionsByTd[nTradingDay][ nStockId].d_dq_mv elif (euSs == EU_StockSection.euSs_MarketValueFlowingFree): dValue = self.__dictStockSectionsByTd[nTradingDay][ nStockId].d_freefloat_mv elif (euSs == EU_StockSection.euSs_Qfa_yoynetprofit): dValue = self.__dictStockSectionsByTd[nTradingDay][ nStockId].d_qfa_yoynetprofit elif (euSs == EU_StockSection.euSs_Qfa_yoysales): dValue = self.__dictStockSectionsByTd[nTradingDay][ nStockId].d_qfa_yoysales elif (euSs == EU_StockSection.euSs_Fa_yoyroe): dValue = self.__dictStockSectionsByTd[nTradingDay][ nStockId].d_fa_yoyroe elif (euSs == EU_StockSection.euSs_Fa_yoyocf): dValue = self.__dictStockSectionsByTd[nTradingDay][ nStockId].d_fa_yoyocf elif (euSs == EU_StockSection.euSs_Fa_yoy_equity): dValue = self.__dictStockSectionsByTd[nTradingDay][ nStockId].d_fa_yoy_equity return dValue
def DBReqStockPool(self, strWindCode): if (len(strWindCode) != 9): return None strSelect = "SELECT S_CON_WINDCODE, S_CON_INDATE, S_CON_OUTDATE, CUR_SIGN FROM [WindDB].[dbo].[AINDEXMEMBERS]" strSelect += " where S_INFO_WINDCODE = '" + strWindCode + "'" sqlS = sqlServer.CSqlServer(self.__strHost, self.__strUser, self.__strPwd, self.__strDB) listResult = sqlS.ExecQuery(strSelect) # print(listResult) listStockPool = [] for row in listResult: if (len(row) != 4): continue strStockWindCode = row[0] nStockId = stockCn.StockWindCode2Int(strStockWindCode) if (nStockId == None): print('stockCn.StockWindCode2Int return None: ', strStockWindCode) continue nInDate = int(dateTime.ToIso(row[1])) nOutDate = -1 nIsIn = int(row[3]) if (nIsIn == 0): nOutDate = int(dateTime.ToIso(row[2])) else: dtToday = datetime.date.today() nOutDate = int(dateTime.ToIso(dtToday)) listRow = [nStockId, nInDate, nOutDate, nIsIn] listStockPool.append(listRow) return listStockPool
def __init__(self, nStockId, nInDate, nOutDate, nIsIn): self.__nStockId = stockCn.StockWindCode2Int(nStockId) strInDate = dateTime.ToIso(nInDate) strOutDate = dateTime.ToIso(nOutDate) if (strInDate == None or strOutDate == None): return None self.__nInDate = int(strInDate) self.__nOutDate = int(strOutDate) self.__nIsIn = nIsIn
def __init__(self, nStockId, nTradingDay, euSs, dSectionValue): self.__nStockId = stockCn.StockWindCode2Int(nStockId) self.__nTradingDay = nTradingDay if (isinstance(nTradingDay, int) == False): strTradingDay = dateTime.ToIso(nTradingDay) if (strTradingDay == None): return None self.__nTradingDay = int(strTradingDay) self.__euSs = euSs self.__dValue = dSectionValue
def AddPeriod(self, strStockWindCode, strICode, nFromDate, nToDate): if (strICode not in self.__dictSipL1.keys()): self.__dictSipL1[strICode] = {} nStockId = stockCn.StockWindCode2Int(strStockWindCode) if (nStockId == None): return False if (nStockId not in self.__dictSipL1[strICode].keys()): self.__dictSipL1[strICode][nStockId] = CStockIndustryPeriod(nStockId, strICode) bRtnAdd = self.__dictSipL1[strICode][nStockId].Add(nFromDate, nToDate) if (bRtnAdd == False): return False else: if (nStockId not in self.__dictSipL1BySid.keys()): self.__dictSipL1BySid[nStockId] = {} self.__dictSipL1BySid[nStockId][strICode] = self.__dictSipL1[strICode][nStockId] return True
def Add(self, strStockWindCode, mdBarData): nStockId = stockCn.StockWindCode2Int(strStockWindCode) if (nStockId == None): return False if (isinstance(mdBarData, CMdBarData) == False): return False euMdBi = mdBarData.GetInterval() if (euMdBi not in self.__dictMdBarData.keys()): self.__dictMdBarData[euMdBi] = {} if (nStockId not in self.__dictMdBarData[euMdBi]): self.__dictMdBarData[euMdBi][nStockId] = {} dtDateTime = dateTime.ToDateTime(mdBarData.GetDateTime()) if (dtDateTime == None): return False self.__dictMdBarData[euMdBi][nStockId][dtDateTime] = mdBarData return True
def __IsIn(self, euMdbi, strStockWindCode, strTradingDay): nStockId = stockCn.StockWindCode2Int(strStockWindCode) if (nStockId == None): print('nStockId is None') return False dtDateTime = dateTime.ToDateTime(strTradingDay) if (dtDateTime == None): print('dtDateTime is None') return False if (euMdbi not in self.__dictMdBarData.keys()): print('euMdbi is not in: ', euMdi, self.__dictMdBarData.keys()) return False if (nStockId not in self.__dictMdBarData[euMdbi].keys()): # print('nStockId is not in: ', nStockId, self.__dictMdBarData[euMdbi].keys()) return False if (dtDateTime not in self.__dictMdBarData[euMdbi][nStockId].keys()): # print('dtDateTime is not in: ', dtDateTime, strStockWindCode, self.__dictMdBarData[euMdbi][nStockId].keys()) return False return True
def AddValue1(self, strStockWindCode, nTradingDay, dPe, dPb, dPcf, dPs, d_val_mv, d_dq_mv, d_freeshared_today): nStockId = stockCn.StockWindCode2Int(strStockWindCode) if (nStockId == None): return False nTradingDayFix = nTradingDay if (isinstance(nTradingDay, int) == False): strTradingDay = dateTime.ToIso(nTradingDay) if (strTradingDay == None): return False nTradingDayFix = int(strTradingDay) if (nTradingDayFix not in self.__dictStockSectionsByTd.keys()): self.__dictStockSectionsByTd[nTradingDayFix] = {} if (nStockId not in self.__dictStockSectionsByTd[nTradingDayFix].keys()): self.__dictStockSectionsByTd[nTradingDayFix][ nStockId] = CStockSectionRecord() self.__dictStockSectionsByTd[nTradingDayFix][nStockId].dPe = dPe self.__dictStockSectionsByTd[nTradingDayFix][nStockId].dPb = dPb self.__dictStockSectionsByTd[nTradingDayFix][nStockId].dPcf = dPcf self.__dictStockSectionsByTd[nTradingDayFix][nStockId].dPs = dPs self.__dictStockSectionsByTd[nTradingDayFix][ nStockId].d_val_mv = d_val_mv self.__dictStockSectionsByTd[nTradingDayFix][ nStockId].d_dq_mv = d_dq_mv self.__dictStockSectionsByTd[nTradingDayFix][ nStockId].d_freeshared_today = d_freeshared_today # print(strStockWindCode, nTradingDayFix, self.__dictStockSectionsByTd[nTradingDayFix][nStockId].dPe \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].dPb \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].dPcf \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].dPs \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_val_mv \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_dq_mv \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_freeshared_today) return True
def AddValue2(self, strStockWindCode, nTradingDay, d_qfa_yoynetprofit, d_qfa_yoysales, d_fa_yoy_equity, d_fa_yoyroe, d_fa_yoyocf): nStockId = stockCn.StockWindCode2Int(strStockWindCode) if (nStockId == None): return False nTradingDayFix = nTradingDay if (isinstance(nTradingDay, int) == False): strTradingDay = dateTime.ToIso(nTradingDay) if (strTradingDay == None): return False nTradingDayFix = int(strTradingDay) if (nTradingDayFix not in self.__dictStockSectionsByTd.keys()): self.__dictStockSectionsByTd[nTradingDayFix] = {} if (nStockId not in self.__dictStockSectionsByTd[nTradingDayFix].keys()): self.__dictStockSectionsByTd[nTradingDayFix][ nStockId] = CStockSectionRecord() self.__dictStockSectionsByTd[nTradingDayFix][ nStockId].d_qfa_yoynetprofit = d_qfa_yoynetprofit self.__dictStockSectionsByTd[nTradingDayFix][ nStockId].d_qfa_yoysales = d_qfa_yoysales self.__dictStockSectionsByTd[nTradingDayFix][ nStockId].d_fa_yoy_equity = d_fa_yoy_equity self.__dictStockSectionsByTd[nTradingDayFix][ nStockId].d_fa_yoyroe = d_fa_yoyroe self.__dictStockSectionsByTd[nTradingDayFix][ nStockId].d_fa_yoyocf = d_fa_yoyocf # self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_qfa_roe_deducted = d_qfa_roe_deducted # print(strStockWindCode, nTradingDayFix, self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_qfa_yoynetprofit \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_qfa_yoysales \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_fa_yoy_equity \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_fa_yoyroe \ # , self.__dictStockSectionsByTd[nTradingDayFix][nStockId].d_fa_yoyocf) return True
def GetVolume(self, euMdbi, strStockWindCode, strTradingDay): dtDateTime = dateTime.ToDateTime(strTradingDay) nStockId = stockCn.StockWindCode2Int(strStockWindCode) if (self.__IsIn(euMdbi, nStockId, dtDateTime) == False): return None return self.__dictMdBarData[euMdbi][nStockId][dtDateTime].GetVolume()
def Add(self, pos): if (isinstance(pos, CPosition_Index) == False): return None nInstId = stockCn.StockWindCode2Int(pos.nStockId) pos.nStockId = nInstId self.dictPositions[nInstId] = pos