Exemple #1
0
class AshareDailyTrade():
    def __init__(self):
        self.file_reader = FileReader(gs.A_SHARE_DAILY_TRADE_PATH,
                                      DataframeFileFetcher())
        self.data = self.read()

    def read(self):
        return self.file_reader.read()

    def get_trade_info(self, ticker, date, columns=None):
        """
        :param ticker:
        :param date:
        :param columns: Should be an array
        :return:
        """
        if columns is None:
            result = self.data[(self.data[TICKER_FIELD] == ticker)
                               and (self.data[TRADE_DATE_FIELD] == date)]
        else:
            result = self.data[(self.data[TICKER_FIELD] == ticker) and (
                self.data[TRADE_DATE_FIELD] == date)][columns]
        if result is None or result.empty:
            return None
        else:
            return result[0]
Exemple #2
0
class AShareStockFetch(DataFetch):

    file_reader = FileReader(gs.A_SHARE_STOCKS_PATH,
                             DataframeFileFetcher())

    def __init__(self, data_reader):
        super(AShareStockFetch, self).__init__(data_reader=data_reader)
        columns = ashare_stocks_fields_map.values()
        for column in columns:
            setattr(self, column, column)

            # self.ticker_field = columns[0]
        # self.name_field = columns[1]
        # self.exchange_field = columns[2]
        # self.status_field = columns[3]
        # self.list_date_field = columns[4]

    def
Exemple #3
0
class AShareStocks():
    def __init__(self):
        self.file_reader = FileReader(gs.A_SHARE_STOCKS_PATH,
                                      DataframeFileFetcher())
        self.data = self.read()

    def read(self):
        return self.file_reader.read()

    def get_info_by_columns(self,
                            ticker=None,
                            name=None,
                            exchange=None,
                            status=None,
                            list_date=None,
                            fields=None):
        pass

    def get_ticker_by_name(self, name):
        ticker_list = self.data[self.data[NAME_FIELD] ==
                                name][TICKER_FIELD].tolist()
        if ticker_list is not None:
            return ticker_list[0]
        else:
            return None

    def get_name_by_ticker(self, ticker):
        name_list = self.data[self.data[TICKER_FIELD] ==
                              ticker][NAME_FIELD].tolist()
        if name_list is not None:
            return name_list[0]
        else:
            return None

    def get_all_tickers_name(self):
        return self.data[NAME_FIELD].tolist()

    def get_all_sids(self):
        return self.data[TICKER_FIELD].tolist()

    def get_data(self):
        return self.data
Exemple #4
0
class AShareStocksAdj(object):
    def __init__(self):
        self.file_reader = FileReader(gs.A_SHARE_STOCKS_ADJUST_PATH,
                                      DataframeFileFetcher())
        self.data = self.read()

    def read(self):
        return self.file_reader.read()

    def get_adjs_by_ticker(self, ticker):
        # Should return [Adj_tuple]
        result = []
        adjs = self.data[self.data[TICKER_FIELD] == ticker]
        for index, row in adjs.iterrows():
            result.append(
                Adj_tuple(ticker=row[TICKER_FIELD],
                          div_date=row[DIV_DATE_FIELD],
                          per_cash=row[PER_CASH_FIELD],
                          per_share_div_ratio=row[PER_SHARE_DIV_FIELD],
                          per_share_trans_ratio=row[PER_SHARE_TRANS_FIELD],
                          allotment_ratio=row[ALLOTMENT_RATIO_FIELD],
                          allotment_price=row[ALLOTMENT_PRICE_FIELD]))
        return result
Exemple #5
0
def test_notice_analyzer():
    noon_url_reader = FileReader(file_path=nconf.NOTICE_RAW_URL_NOON_DATA_PATH,
                                 file_fetcher=DataframeFileFetcher())
    noon_df = noon_url_reader.read()
    noon_date = noon_df['date'].tolist()
    noon_url = noon_df['url'].tolist()
    noon_pairs = zip(noon_date, noon_url)

    mourning_url_reader = FileReader(
        file_path=nconf.NOTICE_RAW_URL_MOURNING_DATA_PATH,
        file_fetcher=DataframeFileFetcher())
    mourning_df = mourning_url_reader.read()
    mourning_date = mourning_df['date'].tolist()
    mourning_url = mourning_df['url'].tolist()
    mourning_pairs = zip(mourning_date, mourning_url)

    na = NoticeAnalyzer(mourning_pairs, noon_pairs)
    na.analyze()
    na.read_noon_notice()
Exemple #6
0
 def __init__(self):
     self.file_reader = FileReader(gs.A_SHARE_STOCKS_ADJUST_PATH,
                                   DataframeFileFetcher())
     self.data = self.read()
Exemple #7
0
 def __init__(self):
     self.file_reader = FileReader(gs.A_SHARE_DAILY_TRADE_PATH,
                                   DataframeFileFetcher())
     self.data = self.read()
Exemple #8
0
def create_natural_cal_reader():
    ncr = FileReader(file_path=gs.NATURAL_CALENDAR_PATH,
                     file_fetcher=ListFileFetcher())
    return ncr
Exemple #9
0
def create_ashare_cal_reader():
    acr = FileReader(file_path=gs.A_SHARE_TRADING_CALENDAR_PATH,
                     file_fetcher=ListFileFetcher())
    return acr
Exemple #10
0
 def read_noon_notice(self):
     notice_reader = FileReader(file_path=conf.NOTICE_NOON_DATA_PATH,
                                file_fetcher=DataframeFileFetcher())
     print notice_reader.read()