Exemple #1
0
    def get_free_market_value_date(self, date):

        """ 得到股票自由流通市值 """

        date = Date.change_to_str(date)
        out_path = os.path.join(self.data_path_static, "Free_Market_Value")
        out_file = os.path.join(out_path, 'Free_Market_Value_' + date + '.csv')
        free_market_value = pd.read_csv(out_file, index_col=[0], encoding='gbk')
        return free_market_value
Exemple #2
0
    def get_trade_status_date(self, date):

        """ 得到股票交易状态 """

        date = Date.change_to_str(date)
        out_path = os.path.join(self.data_path_static, "trade_status")
        out_file = os.path.join(out_path, 'trade_status_' + date + '.csv')
        trade_status = pd.read_csv(out_file, index_col=[0], encoding='gbk')
        return trade_status
Exemple #3
0
    def get_wind_fund_asset(self, date=None):

        if date is None:
            date = Date().get_normal_date_series(period='Q')[-2]
            print(date)

        date = Date.change_to_str(date)
        out_path = Parameter().get_read_file("Fund_Asset")
        out_file = "基金规模_" + date + '.csv'
        out_file = os.path.join(out_path, out_file)
        data = pd.read_csv(out_file, encoding='gbk', index_col=[0])
        return data
Exemple #4
0
    def load_free_market_value_date(self, date):

        """ 下载股票自由流通市值 """

        print("######### Loading FreeMarketValue At %s #########" % date)
        date = Date.change_to_str(date)
        out_path = os.path.join(self.data_path_static, "Free_Market_Value")
        code_list = self.get_all_stock_code_now()
        code_list_str = ','.join(code_list)
        data = w.wss(code_list_str,  "mkt_freeshares", "unit=1;tradeDate=" + date)
        data = pd.DataFrame(data.Data, index=['Free_Market_Value'], columns=data.Codes).T
        out_file = os.path.join(out_path, "Free_Market_Value_" + date + '.csv')
        data.to_csv(out_file)
Exemple #5
0
    def get_fund_pool_all(self, date=None, name=None):

        if name is None:
            name = '基金持仓基准基金池'
        if date is None:
            date = Date().get_normal_date_series(period='Q')[-1]
            print(date)
        date = Date.change_to_str(date)
        out_sub_path = os.path.join(self.pool_load_out_path, name)
        file = name + '_' + date + '.csv'
        out_file = os.path.join(out_sub_path, file)
        data = pd.read_csv(out_file, encoding='gbk', index_col=[0])
        data = data.sort_values(by=['wind_code'], ascending=True)
        return data
Exemple #6
0
    def get_fund_pool_name(self, date=None, name=None):
        """ 下载基金池名称 """

        if name is None:
            name = '基金持仓基准基金池'
        if date is None:
            date = Date().get_normal_date_series(period='Q')[-2]

        date = Date.change_to_str(date)
        print(" Get Fund Pool Name %s %s " % (name, date))
        out_file = os.path.join(self.data_path_pool, name,
                                name + '_' + str(date) + '.csv')
        data = pd.read_csv(out_file, encoding='gbk', index_col=[0])
        data = data.sort_values(by=['wind_code'], ascending=True)
        data = list(data['sec_name'].values)
        return data
Exemple #7
0
    def load_fund_pool(self, date, name, pool_number, source="wind_terminal"):

        if source == "wind_terminal":

            date = Date.change_to_str(date)
            data = w.wset("sectorconstituent",
                          "date=%s;sectorid=%s" % (date, pool_number))
            data = pd.DataFrame(data.Data, index=data.Fields).T
            data.date = data.date.map(Date.change_to_str)
        else:
            data = None

        out_sub_path = os.path.join(self.pool_load_out_path, name)
        if not os.path.exists(out_sub_path):
            os.makedirs(out_sub_path)
        file = name + '_' + date + '.csv'
        out_file = os.path.join(out_sub_path, file)
        data.to_csv(out_file)
Exemple #8
0
    def get_fund_pool_all(self, date=None, name=None):
        """ 得到基金池信息 """

        if name is None:
            name = '基金持仓基准基金池'
        if date is None:
            date = Date().get_normal_date_series(period='Q')[-1]

        date = Date.change_to_str(date)
        print(" Get Fund Pool %s %s " % (name, date))
        out_file = os.path.join(self.data_path_pool, name,
                                name + '_' + str(date) + '.csv')
        data = pd.read_csv(out_file, encoding='gbk', index_col=[0])
        data = data.sort_values(by=['wind_code'], ascending=True)

        if 'setupdate' in data.columns:
            data['setupdate'] = data['setupdate'].map(Date().change_to_str)

        data.index = data['wind_code']
        data = data[~data.index.duplicated()]
        return data
Exemple #9
0
    def load_trade_status_today(self):

        """
        下载股票交易状态
        超过9:15 就用今天的数据
        不超过9:15 就用昨天的数据
         """

        today = datetime.today()
        today_str = Date.change_to_str(today)
        before_date = Date().get_trade_date_offset(today, -1)

        out_path = os.path.join(self.data_path_static, "trade_status")
        out_file = os.path.join(out_path, 'trade_status_' + today_str + '.csv')

        code_list = self.get_all_stock_code_now()
        code_list_str = ','.join(code_list)

        if today.time() > time(9, 15):

            print("######### Loading Trade Status At %s #########" % today_str)
            trade_status = w.wsq(code_list_str, "rt_trade_status")
            trade_status_pd = pd.DataFrame(trade_status.Data, index=['Trade_Status'], columns=trade_status.Codes).T
            trade_status_pd = trade_status_pd[(trade_status_pd['Trade_Status'] != 1.0)
                                              & (trade_status_pd['Trade_Status'] != 4.0)]

            if len(trade_status_pd) > 1000:
                trade_status = w.wss(code_list_str, "trade_status", "tradeDate=" + today_str)
                trade_status_pd = pd.DataFrame(trade_status.Data, index=['Trade_Status'], columns=trade_status.Codes).T
                trade_status_pd = trade_status_pd[trade_status_pd['Trade_Status'] != "交易"]
                trade_status_pd.to_csv(out_file)
            else:
                trade_status_pd.to_csv(out_file)

        else:
            print("######### Loading Trade Status At %s #########" % before_date)
            trade_status = w.wss(code_list_str, "trade_status", "tradeDate=" + before_date)
            trade_status_pd = pd.DataFrame(trade_status.Data, index=['Trade_Status'], columns=trade_status.Codes).T
            trade_status_pd = trade_status_pd[trade_status_pd['Trade_Status'] != "交易"]
            trade_status_pd.to_csv(out_file)
Exemple #10
0
    def load_fund_pool(self, date, name, pool_number):
        """ 下载基金池 为了便于比较每个类型加了 部门几个基金 """

        date = Date.change_to_str(date)
        data = w.wset("sectorconstituent",
                      "date=%s;sectorid=%s" % (date, pool_number))
        data = pd.DataFrame(data.Data, index=data.Fields).T
        data.date = data.date.map(Date.change_to_str)
        data['Type'] = name

        if name == "中证500基金":
            d = pd.DataFrame([['001733.OF', "泰达宏利量化"]],
                             columns=['wind_code', 'sec_name'])
            data = data.append(d)
            data = data.reset_index(drop=True)

        if name == "沪深300基金":
            d = pd.DataFrame([['004484.OF', '泰达宏利业绩驱动']],
                             columns=['wind_code', 'sec_name'])
            data = data.append(d)
            data = data.reset_index(drop=True)

        if name == "指数增强型基金":
            d = pd.DataFrame(
                [['001733.OF', "泰达宏利量化"], ['004484.OF', '泰达宏利业绩驱动']],
                columns=['wind_code', 'sec_name'])
            data = data.append(d)
            data = data.reset_index(drop=True)

        if name == "被动指数型基金":
            d = pd.DataFrame([['162213.OF', "泰达宏利沪深300"]],
                             columns=['wind_code', 'sec_name'])
            data = data.append(d)
            data = data.reset_index(drop=True)

        if name == "偏债混合型基金":
            d = pd.DataFrame([['003912.OF', "泰达宏利启富"],
                              ['004000.OF', '泰达宏利睿选稳健'],
                              ['003501.OF', '泰达宏利睿智稳健'],
                              ['162211.OF', '泰达宏利品质生活'],
                              ['001419.OF', '泰达宏利新思路']])
            d.columns = ['wind_code', 'sec_name']
            data = data.append(d)
            data = data.reset_index(drop=True)

        if name == "偏股混合型基金":
            d = pd.DataFrame([['001017.OF', "泰达宏利改革动力"],
                              ['002263.OF', '泰达宏利同顺大数据'],
                              ["001170.OF", "泰达宏利复兴伟业"],
                              ["005903.OF", "泰达宏利绩优增长"]])
            d.columns = ['wind_code', 'sec_name']
            data = data.append(d)
            data = data.reset_index(drop=True)

        out_sub_path = os.path.join(self.data_path_pool, name)
        if not os.path.exists(out_sub_path):
            os.makedirs(out_sub_path)

        print(" Loading Fund Pool %s At %s" % (name, date))
        out_file = os.path.join(out_sub_path, name + '_' + date + '.csv')
        data.to_csv(out_file)
        print(data.head())