コード例 #1
0
    def TrimData(self):
        '''
        清洗和预处理数据
        :return: 处理好的 pandas.Dataframe
        '''
        # 数据导入
        fundNav = read_csvEx(self.dataFile, 0)
        benchName = self.benchmarkName.strip(u'_stocks')
        bench = self.index_DF(benchName,
                              u'stocks')[u'close'].to_frame(benchName)
        fundNav = fundNav.replace({0: np.nan})
        pct_fund = fundNav.pct_change()
        pct_fund.iloc[0, :] = 0.

        # 直接给出市道
        scenarioCond = self.marketPoint
        scenarioCond = scenarioCond.replace({
            u'下行': u'显著下降',
            u'上行': u'显著上升'
        }).loc[bench.index]
        self.fund_predfund_manager = pd.read_csv(
            u'../Data/Main/fund_predfund_manager.csv', encoding='gbk')
        managerIndex = self.fund_predfund_manager.index

        # 基金经理管理基金时间处理
        stCol = []
        enCol = []
        lastDate = self.time_List()[-1]
        for i in range(self.fund_predfund_manager.index.size):
            tempStr = self.fund_predfund_manager[u'fund_manage_time'].iloc[i]
            try:
                if isinstance(tempStr, unicode):
                    if u'至今' in tempStr:
                        tempSt, tempEn = [tempStr.strip(u'至今'), lastDate]
                    else:
                        tempSt, tempEn = tempStr.split(u'-')
                else:
                    tempSt, tempEn = [None, None]
            except:
                tempSt, tempEn = [None, None]
            stCol.append(tempSt)
            enCol.append(tempEn)
        self.fund_predfund_manager[u'fund_manage_time_st'] = pd.Series(
            pd.DatetimeIndex(stCol, index=managerIndex))
        self.fund_predfund_manager[u'fund_manage_time_en'] = pd.Series(
            pd.DatetimeIndex(enCol, index=managerIndex))
        # self.stockLatest = pd.read_csv(u'../Data/Main/股票型基金日期.csv', index_col=0)
        # self.hybridLatest = pd.read_csv(u'../Data/Main/混合型基金日期.csv', index_col=0)
        # self.fixedincomeLatest = pd.read_csv(u'../Data/Main/债券型基金日期.csv', index_col=0)
        self.actualNetasset = read_csvEx(u'../Data/Main/基金规模.csv', 0)

        self.fundNavFirst = read_csvEx(u'../Data/Main/基金净值.csv', 0)
        self.pct_fund = pct_fund
        self.scenarioCond = scenarioCond
        self.firstTriger = True
        return super(MyStrategy, self).TrimData()
    def TrimData(self):
        '''
        清洗和预处理数据
        :return: 处理好的 pandas.Dataframe
        '''
        # 数据导入
        fundNav = read_csvEx(self.dataFile, 0)
        fundNav = fundNav.replace({0: np.nan})
        pct_fund = fundNav.pct_change()
        pct_fund.iloc[0, :] = 0.

        # 基金经理代码
        self.managerIndex = []

        # 直接给出市道
        self.fund_predfund_manager = pd.read_csv(
            u'../Data/Main/fund_predfund_manager.csv', encoding='gbk')
        managerIndex = self.fund_predfund_manager.index

        # 基金经理管理基金时间处理
        stCol = []
        enCol = []
        lastDate = self.time_List()[-1]
        for i in range(self.fund_predfund_manager.index.size):
            tempStr = self.fund_predfund_manager[u'fund_manage_time'].iloc[i]
            try:
                if isinstance(tempStr, unicode):
                    if u'至今' in tempStr:
                        tempSt, tempEn = [tempStr.strip(u'至今'), lastDate]
                    else:
                        tempSt, tempEn = tempStr.split(u'-')
                else:
                    tempSt, tempEn = [None, None]
            except:
                tempSt, tempEn = [None, None]
            stCol.append(tempSt)
            enCol.append(tempEn)

        self.fund_predfund_manager[u'fund_manage_time_st'] = pd.Series(
            pd.DatetimeIndex(stCol, index=managerIndex))
        self.fund_predfund_manager[u'fund_manage_time_en'] = pd.Series(
            pd.DatetimeIndex(enCol, index=managerIndex))
        self.actualNetasset = read_csvEx(u'../Data/Main/基金规模.csv', 0)
        self.fundNavFirst = read_csvEx(u'../Data/Main/基金净值.csv', 0)
        self.fund_list = pd.read_csv(u'../Data/Main/fund_list.csv',
                                     index_col=0,
                                     encoding='utf-8')
        self.firstTriger = True
        self.pct_fund = pct_fund
        return super(MyStrategy, self).TrimData()
コード例 #3
0
    def TrimData(self):
        '''
        清洗和预处理数据
        :return: 处理好的 pandas.Dataframe
        '''
        # 数据导入
        fundNav = read_csvEx(self.dataFile, 0)
        benchName = self.benchmarkName.strip(u'_stocks')
        bench = self.index_DF(benchName,
                              u'stocks')[u'close'].to_frame(benchName)
        fundNav = fundNav.replace({0: np.nan})
        pct_fund = fundNav.pct_change()
        pct_fund.iloc[0, :] = 0.

        # 直接给出市道
        scenarioCond = self.marketPoint
        scenarioCond = scenarioCond.replace({
            u'下行': u'显著下降',
            u'上行': u'显著上升'
        }).loc[bench.index]
        fundLatestRptDate = self.fundLatestRptDate[pct_fund.columns].dropna()

        self.fundNavFirst = fundNav
        self.pct_fund = pct_fund
        self.scenarioCond = scenarioCond
        self.fundLatestRptDate = fundLatestRptDate
        self.firstTriger = True
        return super(MyStrategy, self).TrimData()
コード例 #4
0
    def TrimData(self):
        '''
        清洗和预处理数据
        :return: 处理好的 pandas.Dataframe
        '''
        # 数据导入
        fundNav = read_csvEx(self.dataFile, 0)
        benchName = self.benchmarkName.strip(u'_stocks')
        bench = self.index_DF(benchName,
                              u'stocks')[u'close'].to_frame(benchName)
        fundNav = fundNav.replace({0: np.nan})
        pct_fund = fundNav.pct_change()
        pct_fund.iloc[0, :] = 0.

        # 直接给出市道
        scenarioCond = self.marketPoint
        scenarioCond = scenarioCond.replace({
            u'下行': u'显著下降',
            u'上行': u'显著上升'
        }).loc[bench.index]
        self.stockLatest = pd.read_csv(u'../Data/Main/股票型基金日期.csv',
                                       index_col=0)
        self.hybridLatest = pd.read_csv(u'../Data/Main/混合型基金日期.csv',
                                        index_col=0)
        self.fixedincomeLatest = pd.read_csv(u'../Data/Main/债券型基金日期.csv',
                                             index_col=0)
        self.actualNetasset = read_csvEx(u'../Data/Main/基金规模.csv', 0)

        self.fundNavFirst = fundNav
        self.pct_fund = pct_fund
        self.scenarioCond = scenarioCond
        self.firstTriger = True
        self.typeDict = {u'显著上升': u'股票型基金', u'震荡': u'混合型基金', u'显著下降': u'债券型基金'}

        # 超额收益

        self.tempBenchPct = self.benchmark.values()[0].pct_change().loc[
            pct_fund.index]
        self.tempBenchPctDf = pd.DataFrame(
            {i: self.tempBenchPct.iloc[:, 0]
             for i in self.pct_fund})
        # self.exPct = pct_fund - tempDf
        return super(MyStrategy, self).TrimData()