Пример #1
0
    def set_target_data(self) -> None:
        """
        """
        accumulative_data = self.data_container.get_accumulative_data(
            self.stock_code)
        if accumulative_data.empty:
            log.e(f'No accumulative data relevant to {self.stock_code}')
            log.e('')
            return None

        try:
            self.length = len(accumulative_data)
            self.open = sum(
                accumulative_data.loc[:, ColumnsDefinition.OPENING_PRICE])
            self.high = sum(
                accumulative_data.loc[:, ColumnsDefinition.HIGH_PRICE])
            self.low = sum(accumulative_data.loc[:,
                                                 ColumnsDefinition.LOW_PRICE])
            self.close = sum(
                accumulative_data.loc[:, ColumnsDefinition.CLOSING_PRICE])
        except Exception as e:
            log.e(e)
            log.e('Failed to prepare calculation with accumulative data.')
            log.e('')
            return None

        return None
Пример #2
0
    def calculate_data(self) -> None:
        """
        """
        if str() in [self.open, self.high, self.low, self.close]:
            log.e('Failed to do calculation with accumulative data.')
            log.e('')
            return None

        average_data = pandas.DataFrame([{
            'TERM':
            str(self.term),
            'DATE':
            str(self.date),
            'NAME':
            str(self.stock_name),
            'CODE':
            str(self.stock_code),
            'OPENING PRICE (AVE)':
            float(self.open / self.length),
            'HIGH PRICE (AVE)':
            float(self.high / self.length),
            'LOW PRICE (AVE)':
            float(self.low / self.length),
            'CLOSING PRICE (AVE)':
            float(self.close / self.length)
        }])

        self.data_container.register_average_data(self.stock_code,
                                                  average_data)

        return None
Пример #3
0
    def get_conversion_table(self) -> pandas.Series:
        """
        """
        if self.conversion_table.empty:
            log.e('Failed to get conversion table.')
            log.e('')
            return pandas.Series()

        return self.conversion_table
    def __init__(self, file_name: str) -> None:
        """
        """
        execution_date = datetime.datetime.now().strftime('%Y%m%d')

        self.log_path = str()
        self.file_path = str()

        try:
            root = os.path.join(os.path.dirname(
                os.path.dirname(__file__)), 'conf', 'Logging.ini')
            config = configparser.ConfigParser()
            config.read(root)
            logging_information = config['LOGGING']
            self.log_path = logging_information['LOG_PATH']
        except Exception as e:
            log.w(e)
            log.w('Failed to get the information from Logging.ini .')
            log.w('')
            return None

        try:
            if self.log_path == str():
                self.log_path = os.path.dirname(os.path.dirname(__file__))
            os.makedirs(os.path.join(self.log_path,
                                     execution_date), exist_ok=True)
            self.file_path = os.path.join(
                self.log_path, execution_date, file_name)
        except Exception as e:
            log.e(e)
            log.e('Failed to create a log file.')
            log.e('')
            return None

        return None
Пример #5
0
    def get_stock_codes(self) -> list:
        """
        """
        if self.stock_codes == list():
            log.e('Failed to get a list of sotck codes.')
            log.e('Stock code doesn\'t exist.')
            log.e('')
            return list()

        return self.stock_codes
Пример #6
0
    def convert_into_name(self, stock_code: str) -> str:
        """
        """
        try:
            stock_name = self.conversion_table[stock_code]
        except Exception as e:
            log.e(e)
            log.e('Failed to convert code into name.')
            log.e('')
            return str()

        return stock_name
    def get_existence_log(self) -> pandas.DataFrame:
        """
        """
        if not os.path.isfile(self.file_path)\
                or os.path.getsize(self.file_path) == 0:
            return pandas.DataFrame()

        try:
            existence_log = pandas.read_csv(self.file_path)
        except Exception as e:
            log.e(e)
            log.e('Failed to read existence log.')
            log.e('')
            return pandas.DataFrame()

        return existence_log
Пример #8
0
    def register_accumulative_data(self, url_table) -> None:
        """
        """
        target_data = list()

        if url_table == dict():
            log.e('Failed to accumulate data (URL doesn\'t exist).')
            log.e('')
            return None

        for stock_code, urls in url_table.items():
            target_data = [pandas.read_html(url)[5] for url in urls]
            if len(target_data) != len(urls) or target_data == list():
                log.e(f'Failed to accumulate data with URLs ({stock_code}).')
                log.e('')
                continue
            else:
                self.data_table[stock_code] = pandas.concat(
                    target_data, axis=0).sort_values(ColumnsDefinition.DATE,
                                                     ascending=False)
                log.i(f'Accumulated data with URLs related to {stock_code}.')
                log.i('')

        return None
Пример #9
0
    def register_stock_codes(self, codes_list) -> None:
        """
        """
        pattern = re.compile(r'^(\d{4})$')
        codes = [code for code in self.stock_codes if pattern.match(code)]
        stock_codes = [code for code in codes if code in codes_list]
        if stock_codes == list():
            log.e('Failed to create URL.')
            log.e('Valid Stock code doesn\'t exist.')
            log.e('')
            return None
        else:
            self.stock_codes = stock_codes
            stock_codes = ', '.join(stock_codes)
            log.i(f'Found {len(self.stock_codes)} valid codes.')
            log.i(f'STOCK CODE: {stock_codes}')
            log.i('')

            return None

        return None