Ejemplo n.º 1
0
 def __is_valid_intrinio_record(self, record: Dict) -> bool:
     fiscal_period: str = record.get(
         AppConsts.INTRINIO_KEY_INC_STMT_FISC_PD)
     return record \
         and not StringUtils.isNullOrWhitespace(record.get(AppConsts.INTRINIO_KEY_INC_STMT_TICKER)) \
         and not StringUtils.isNullOrWhitespace(record.get(AppConsts.INTRINIO_KEY_INC_STMT_NAME)) \
         and not StringUtils.isNullOrWhitespace(fiscal_period) \
         and (fiscal_period.endswith(AppConsts.INTRINIO_PERIOD_SUFFIX_TTM) or fiscal_period.endswith(AppConsts.INTRINIO_PERIOD_SUFFIX_FY))
Ejemplo n.º 2
0
 def get_date(datestr: str, fmt: str) -> date:
     if not isinstance(datestr, str) \
             or not isinstance(fmt, str) \
             or StringUtils.isNullOrWhitespace(datestr) \
             or StringUtils.isNullOrWhitespace(fmt):
         return None
     try:
         return datetime.strptime(datestr, fmt)
     except Exception as ex:
         LogUtils.warning('Invalid date inputs={0} {1}'.format(
             datestr, fmt))
         return None
Ejemplo n.º 3
0
 def is_valid_model(self) -> bool:
     return not StringUtils.isNullOrWhitespace(self.strategy_type) \
         and self.pct_risk_per_trade > 0 \
         and self.pct_risk_per_trade <= 100 \
         and self.volume_limit >= 0.01 \
         and self.volume_limit <= 100 \
         and self.test_limit_symbol >= 1
Ejemplo n.º 4
0
 def get_files(file_path: str, is_full: bool = False) -> List[str]:
     if StringUtils.isNullOrWhitespace(file_path):
         return []
     path: str = os.path.join(os.getcwd(), file_path)
     if is_full:
         return [os.path.join(path, f) for f in os.listdir(path)]
     return os.listdir(path)
Ejemplo n.º 5
0
 def parse_as_list(file_path: str) -> List[List[str]]:
     try:
         LogUtils.debug('START')
         if StringUtils.isNullOrWhitespace(file_path):
             return []
         with open(file_path) as f:
             return list(csv.reader(f)) if f else []
     finally:
         LogUtils.debug('END')
Ejemplo n.º 6
0
 def __get_quarter(self, fiscal_period: str) -> int:
     if StringUtils.isNullOrWhitespace(fiscal_period):
         return None
     if fiscal_period.endswith(AppConsts.INTRINIO_PERIOD_SUFFIX_FY):
         return 4
     return NumberUtils.to_int(
         fiscal_period.replace(AppConsts.INTRINIO_PERIOD_PREFIX,
                               '').replace(
                                   AppConsts.INTRINIO_PERIOD_SUFFIX_TTM,
                                   ''))
Ejemplo n.º 7
0
 def is_valid_model(self) -> bool:
     return not StringUtils.isNullOrWhitespace(self.strategy_type) \
         and self.start_capital > 0 \
         and self.pct_risk_per_trade > 0 \
         and self.pct_risk_per_trade <= 100 \
         and self.portfolio_max > 0 \
         and self.date_from_obj \
         and self.date_from_obj >= AppConsts.MIN_DATE \
         and self.date_to_obj \
         and self.date_to_obj >= AppConsts.MIN_DATE \
         and self.date_from_obj < self.date_to_obj \
         and self.slippage >= 0 \
         and self.volume_limit >= 0.01 \
         and self.volume_limit <= 100 \
         and self.test_limit_symbol >= 1
Ejemplo n.º 8
0
 def import_from_csv_companynames(self) -> str:
     file: str = FileUtils.get_file(AppConsts.INCOME_STMT_FILE)
     records: List[Dict] = CsvUtils.parse_as_dict(file)
     curr_symbol: str = ''
     for record in records:
         symbol: str = record.get(AppConsts.INTRINIO_KEY_INC_STMT_TICKER)
         company_name: str = record.get(
             AppConsts.INTRINIO_KEY_INC_STMT_NAME)
         if symbol == curr_symbol or StringUtils.isNullOrWhitespace(
                 company_name):
             continue
         curr_symbol = symbol
         org_symbol: SM = self.__stock_service.get_symbol(
             curr_symbol, AppConsts.INSTRUMENT_STOCK)
         if not org_symbol:
             continue
         LogUtils.debug('Updating {0}.'.format(company_name))
         org_symbol.name = company_name
         BaseService._update()
     return "1"
Ejemplo n.º 9
0
 def get_symbol(self, symbol: str, instrument: str) -> SM:
     if StringUtils.isNullOrWhitespace(symbol):
         return None
     symbol = symbol.strip().upper()
     return BaseService._get_first(
         SM, [SM.symbol == symbol, SM.instrument == instrument])
Ejemplo n.º 10
0
 def get_wo_ext(file_path: str) -> str:
     if StringUtils.isNullOrWhitespace(file_path):
         return ''
     split: Tuple[str] = os.path.splitext(file_path)
     return split[0] if split else ''
Ejemplo n.º 11
0
 def get_base_name(file_path: str) -> str:
     if StringUtils.isNullOrWhitespace(file_path):
         return ''
     return os.path.basename(file_path)
Ejemplo n.º 12
0
 def get_file(file_path: str) -> str:
     if StringUtils.isNullOrWhitespace(file_path):
         return ''
     return os.path.join(os.getcwd(), file_path)