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 GetPreTradingDay(self, strExchange, tradingDay): dtTradingDay = dateTime.ToDateTime(tradingDay) nTradingDay = int(dateTime.ToIso(tradingDay)) if nTradingday <= self.__dictTc[strExchange][0]: return False, 0 while True: dtTradingDay = Yestoday(dtTradingDay) nTradingDay = int(dateTime.ToIso(dtTradingDay)) if self.IsTradingDay(nTradingDay) == True: return True, nTradingDay
def GenerateTdIndex(self, dtFrom, dtTo): strFrom = dateTime.ToIso(dtFrom) strTo = dateTime.ToIso(dtTo) if (strFrom == '' or strFrom == None or strTo == '' or strTo == None): return False inputPeriod = dateTime.CDatePeriod(strFrom, strTo) for strICode in self.__dictSipL1.keys(): for nStockId in self.__dictSipL1[strICode]: # self.__dictSipL1BySid[nStockId] = {} # self.__dictSipL1BySid[nStockId][strICode] = self.__dictSipL1[strICode][nStockId] for period in self.__dictSipL1[strICode][nStockId].GetPeriods(): dpIntersection = inputPeriod.Intersection(period) if (dpIntersection == None): continue
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 GetNextTradingDay(self, strExchange, tradingDay): nTradingDay = tradingDay if (isinstance(tradingDay, str) or isinstance(tradingDay, datetime.datetime)): strTd = dateTime.ToIso(tradingDay) if (strTd == None): return False, 0 nTradingDay = int(strTd) if (self.IsTradingDay(strExchange, tradingDay) == True): tdIndex = self.__dictTc[strExchange].index(nTradingDay) + 1 if (tdIndex >= len(self.__dictTc[strExchange])): return False, 0 return True, self.__dictTc[strExchange][tdIndex] else: if (strExchange in self.__dictTc == False): return False, 0 if (len(self.__dictTc[strExchange]) <= 0): return False, 0 n1st = self.__dictTc[strExchange][0] nLast = self.__dictTc[strExchange][len(self.__dictTc[strExchange]) - 1] # 比第一天还早,则返回第一天 if (nTradingDay < n1st): return True, n1st # 比最后一天还晚,则返回错误 elif (nTradingDay > nLast): return False, 0 for nDay in self.__dictTc[strExchange]: if nTradingDay < nDay: return True, nDay return False, 0
def GenerateTdIndex(self): print('CStockPoolManager.GenerateTdIndex ...') nLoopIndex = 0 nShowPercent = 0 for nStockId, listElems in self.__dictSpElems.items(): nLoopPercent = int(nLoopIndex * 100 / len(self.__dictSpElems)) if (nShowPercent < nLoopPercent and nLoopPercent % 10 == 0): nShowPercent = int(nLoopIndex * 100 / len(self.__dictSpElems)) print(str(nShowPercent) + '%') # print(nLoopIndex, '/', len(self.__dictSpElems)) nLoopIndex += 1 for elem in listElems: nInDate = elem.GetInDate() nOutDate = elem.GetOutDate() nLoopDate = nInDate while (nLoopDate <= nOutDate): if ((nLoopDate in self.__dictSpElemsByTd) == False): self.__dictSpElemsByTd[nLoopDate] = list() self.__dictSpElemsByTd[nLoopDate].append(nStockId) # Next Date dateLoopDate = dateTime.ToDateTime(nLoopDate) dateTomorrow = dateLoopDate + datetime.timedelta(days=1) nLoopDate = int(dateTime.ToIso(dateTomorrow))
def Remove(self, dtFrom, dtTo): nFrom = dtFrom if (isinstance(dtFrom, int) == False): strFrom = dateTime.ToIso(dtFrom) if (strFrom == None): return False nFrom = int(strFrom) nTo = dtTo if (isinstance(nTo, int) == False): strTo = dateTime.ToIso(nTo) if (strTo == None): return False nTo = int(strTo) for key in self.__dictStockSectionsByTd.keys(): if (key >= nFrom and key <= nTo): del self.__dictStockSectionsByTd[key] pass
def GetStocksByTd(self, inputDate): strTd = dateTime.ToIso(inputDate) if (strTd == None or strTd == ''): return None nTd = int(strTd) if (nTd in self.__dictSpElemsByTd.keys()): return self.__dictSpElemsByTd[nTd] else: return None
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 IsTradingDay(self, strExchange, tradingDay): if (strExchange in self.__dictTc == False): return False nTradingDay = tradingDay if (isinstance(tradingDay, str)): strTd = dateTime.ToIso(tradingDay) if (strTd == None): return False nTradingDay = int(strTd) return nTradingDay in self.__dictTc[strExchange]
def __GetDateLimit(self, strDateFrom, strDateTo, strTableCol, strTablePrefix=''): if (strDateFrom == '' or strDateTo == '' or strTableCol == ''): return None strDateFromFix = dateTime.ToIso(strDateFrom) strDateToFix = dateTime.ToIso(strDateTo) if (strDateFromFix > strDateToFix): strDateFromFix = dateTime.ToIso(strDateTo) strDateToFix = dateTime.ToIso(strDateFrom) strRtn = '(' strRtn += strTablePrefix + strTableCol + " >= '" + strDateFromFix strRtn += "') AND (" strRtn += strTablePrefix + strTableCol + " <= '" + strDateToFix + "')" return strRtn
def GetTradingDayList(self, strExchange, dtFrom, dtTo, bDateTime=False): listRtn = [] nTradingDay = int(dateTime.ToIso(dtFrom)) nTdTo = int(dateTime.ToIso(dtTo)) if self.IsTradingDay(strExchange, nTradingDay) == True: if bDateTime == True: listRtn.append(dateTime.ToDateTime(dtFrom)) else: listRtn.append(nTradingDay) while True: bSuccess, nTradingDay = self.GetNextTradingDay( strExchange, nTradingDay) if bSuccess == False or nTradingDay > nTdTo: break if bDateTime == True: dtTradingDay = dateTime.ToDateTime(nTradingDay) listRtn.append(dtTradingDay) else: listRtn.append(nTradingDay) return listRtn
def GetTradingDayCount(self, strExchange, tdFrom, tdTo): if (self.IsTradingDay(strExchange, tdFrom) == False or self.IsTradingDay(strExchange, tdTo) == False): return False, 0 nFrom = tdFrom nTo = tdTo if (isinstance(nFrom, str)): strTd = dateTime.ToIso(nFrom) if (strTd == False, -1): return False, -1 nFrom = int(strTd) if (isinstance(nTo, str)): strTd = dateTime.ToIso(nTo) if (strTd == False, -1): return False, -1 nTo = int(strTd) tdIndexFrom = self.__dictTc[strExchange].index(nFrom) tdIndexTo = self.__dictTc[strExchange].index(nTo) return True, tdIndexTo - tdIndexFrom
def DBReqStockIndustries_ZX(self): strSelect = "SELECT S_INFO_WINDCODE, CITICS_IND_CODE, ENTRY_DT, REMOVE_DT, CUR_SIGN FROM [WindDB].[dbo].[ASHAREINDUSTRIESCLASSCITICS];" sqlS = sqlServer.CSqlServer(self.__strHost, self.__strUser, self.__strPwd, self.__strDB) listResult = sqlS.ExecQuery(strSelect) listStockIndustries = [] for row in listResult: if (len(row) != 5): continue strStockWindCode = row[0] strICode = row[1] nInDate = int(dateTime.ToIso(row[2])) nOutDate = -1 nIsIn = int(row[4]) if (nIsIn == 0): nOutDate = int(dateTime.ToIso(row[3])) else: dtToday = datetime.date.today() nOutDate = int(dateTime.ToIso(dtToday)) listRow = [strStockWindCode, strICode, nInDate, nOutDate, nIsIn] listStockIndustries.append(listRow) return listStockIndustries
def RemoveBefore(self, dtBefore): nBefore = dtBefore print(1) if (isinstance(dtBefore, int) == False): print(2) strBefore = dateTime.ToIso(dtBefore) if (strBefore == None): print(3, strBefore, dtBefore) return False print(4) nBefore = int(strBefore) for key in list(self.__dictStockSectionsByTd.keys()): if (key <= nBefore): del self.__dictStockSectionsByTd[key] print(5)
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 CalcIndex(strDbHost, strDbUserName, strDbPasswd, strDbDatabase, strDateFrom, strDateTo, strCsvFile, euCFI): # 初始化数据 tcInst = tCal.CTradingCalendar() ## 资金总额,分配到不同的成分中 dFundTotal = BaseIndexValue() * IndexMulti() ## 读取成分比重 dfCFIndexWeight_NanHua = pd.read_csv(strCsvFile) nCFRowLen = len(dfCFIndexWeight_NanHua) nCFColLen = len(dfCFIndexWeight_NanHua.columns) nCFRowIndex = 0 ## 行情数据;连续合约实际合约对应表 ### 循环处理成分比重表示,第一循环从数据库读取数据 dfCFPrice = pd.DataFrame() dfCFMapping = pd.DataFrame() dt1stDate = None dtLastDate = dateTime.ToDateTime(strDateTo) dictDailyIndexValue = {} dtDailyConstituent = pd.DataFrame() # 每次循环做一次一次指数成分调整 while nCFRowIndex < nCFRowLen: dictFundByProduct = {} # 各个品种分配的资金 nColIndex = 0 dtLoopFrom = None dtLoopTo = None # 处理起始日期 和 各个品种分配的初始资金 while nColIndex < nCFColLen: strCol = dfCFIndexWeight_NanHua.columns[nColIndex] dValue = dfCFIndexWeight_NanHua[strCol][nCFRowIndex] if (strCol == 'TradingDay'): dtLoopFrom = dateTime.ToDateTime( int(dfCFIndexWeight_NanHua[strCol][nCFRowIndex])) else: if dValue != 0: dictFundByProduct[strCol] = dfCFIndexWeight_NanHua[strCol][ nCFRowIndex] * dFundTotal nColIndex += 1 # 查询数据库, 初始化数据 if (nCFRowIndex == 0): dt1stDate = dtLoopFrom dfCFPrice, dfCFMapping = InitData_Common(strDbHost, strDbUserName, strDbPasswd, strDbDatabase, dateTime.ToIso(dt1stDate), strDateTo) # 处理结束日期 if nCFRowIndex + 1 == nCFRowLen: dtLoopTo = dtLastDate else: dtLoopTo = dateTime.ToDateTime( int(dfCFIndexWeight_NanHua['TradingDay'][nCFRowIndex + 1])) if tcInst.IsTradingDay('SHFE', dateTime.ToIso(dtLoopFrom)) == False: bSuccess, nRtn = tcInst.GetNextTradingDay('SHFE', dtLoopFrom) if bSuccess == True: dtLoopFrom = dateTime.ToDateTime(nRtn) else: print('tcInst.GetNextTradingDay failed', 'SHFE', dtLoopFrom) break if tcInst.IsTradingDay('SHFE', dateTime.ToIso(dtLoopTo)) == False: bSuccess, nRtn = tcInst.GetNextTradingDay('SHFE', dtLoopTo) if bSuccess == True: dtLoopTo = dateTime.ToDateTime(nRtn) else: print('tcInst.GetNextTradingDay failed', 'SHFE', dtLoopTo) break print( '--------------------------------------------------------------------' ) print('Processing From ' + dateTime.ToIso(dtLoopFrom) + ' To ' + dateTime.ToIso(dtLoopTo)) # 处理每个成分 dfLoopAll = pd.DataFrame() for strProduct in dictFundByProduct.keys(): # 连续合约与现实合约进行对应 for idxProd in dfCFMapping.ix[strProduct].index: # 期货合约 strInstrument = dfCFMapping['FS_MAPPING_WINDCODE'][strProduct][ idxProd] if strInstrument not in dfCFPrice.index.levels[0]: continue strExchange = GetExchange(strProduct) if strExchange == '': print('xxxxxx Exchange Is NULL: ', strProduct) continue # 日期处理, 只处理本次循环的 bIncludeTailRow = True dtProductFrom = idxProd[0] dtProductTo = idxProd[1] if dtProductFrom > dtLoopTo: break if dtProductTo < dtLoopFrom: continue if dtProductFrom < dtLoopFrom: dtProductFrom = dtLoopFrom if dtProductTo >= dtLoopTo: dtProductTo = dtLoopTo else: bSuccess, nProductTo = tcInst.GetNextTradingDay( strExchange, dtProductTo) if bSuccess == False: continue dtProductTo = dateTime.ToDateTime(nProductTo) bIncludeTailRow = False # 获取时间区间的行情数据 listDates = tcInst.GetTradingDayList(strExchange, dtProductFrom, dtProductTo, True) dfLoopMd = dfCFPrice.ix[strInstrument].ix[listDates].dropna() # 处理缺失的行情数据,使用昨收盘和昨结算 if len(list(set(listDates).difference(dfLoopMd.index))) >= 1: dateLastTd = None for keyDate in listDates: if keyDate not in dfLoopMd.index: if dateLastTd == None: bSuccess, nLastTd = tcInst.GetPreTradingDay( strExchange, keyDate) if (bSuccess == None): print( 'xxxxxx Last TradingDay Md Is NULL: ' + strInstrument + ' ' + str(keyDate)) continue dateLastTd = dateTime.ToDateTime(nLastTd) dClose = dfLoopMd['S_DQ_CLOSE'][dateLastTd] dSettle = dfLoopMd['S_DQ_SETTLE'][dateLastTd] dfToday = pd.DataFrame( { 'S_DQ_CLOSE': [dClose], 'S_DQ_SETTLE': [dSettle] }, index=[keyDate]) dfToday.index.names = ['TRADE_DT'] dfLoopMd = pd.concat([dfLoopMd, dfToday], axis=0, join='outer') dateLastTd = keyDate dfLoopMd['InstrumentId'] = strInstrument dfLoopMd['DominantContract'] = strProduct dfLoopMd['Volume'] = np.nan dfLoopMd['Value'] = np.nan dfLoopMd.reset_index(inplace=True) dfLoopMd = dfLoopMd.set_index(['DominantContract', 'TRADE_DT']) dfLoopMd = dfLoopMd.sortlevel(1) dPrice = dfLoopMd['S_DQ_CLOSE'][strProduct][dtProductFrom] dVolume = dictFundByProduct[strProduct] / dPrice dfLoopMd['Volume'][strProduct][ dtProductFrom:dtProductTo] = dVolume dfLoopMd['Value'][strProduct][dtProductFrom:dtProductTo] = \ dfLoopMd['S_DQ_CLOSE'][strProduct][dtProductFrom:dtProductTo] * \ dfLoopMd['Volume'][strProduct][dtProductFrom:dtProductTo] dfLoopMd['Value'][strProduct][ dtProductFrom] = dictFundByProduct[strProduct] dictFundByProduct[strProduct] = dfLoopMd['Value'][strProduct][ dtProductTo] dfLoopAll = pd.concat([dfLoopAll, dfLoopMd[:-1]], axis=0, join='outer') dfSwap = dfLoopAll.swaplevel(0, 1) dfSwap['Weight'] = np.nan for dtKey in dfSwap['Value'].index.levels[0]: total = dfSwap['Value'][dtKey].sum() dictDailyIndexValue[dtKey] = total print(str(dtKey) + ' ' + str(dfSwap['Value'][dtKey].sum())) dfSwap['Weight'][dtKey] = dfSwap['Value'][dtKey] / total dFundTotal = total nCFRowIndex += 1 dtDailyConstituent = pd.concat([dtDailyConstituent, dfSwap], axis=0, join='outer') # 处理每日每个品种的权重 dtDailyConstituent = dtDailyConstituent.swaplevel(0, 1) print('Dump Index Value into index_daily.csv') fIndex = open('index_daily.csv', 'w') for key in sorted(dictDailyIndexValue.keys()): strOutput = dateTime.ToIso(key) + ',' + str( dictDailyIndexValue[key] / IndexMulti()) + ',' + str( euCFI.value) + '\n' fIndex.write(strOutput) fIndex.close() del dtDailyConstituent['Volume'] del dtDailyConstituent['Value'] print('Dump Index Daily Constituent into index_daily_constituent.csv') dtDailyConstituent['IndexType'] = euCFI.value dtDailyConstituent.to_csv('index_daily_constituent.csv', header=False)