class ProcessManager: TARGET: str = 'target' ARGS: str = 'args' CONFIGURATION: Dict[str, Dict[str, Tuple[Any, ...]]] = { 'update-table-stock': { TARGET: StockDAO.update, ARGS: (Portfolio.test_prod_portfolio(),) }, 'update-table-intraday': { TARGET: IntradayBO.update, ARGS: (Portfolio.test_prod_portfolio(),) }, 'schedule': { TARGET: Scheduler.start, ARGS: [] }, 'optimize': { TARGET: OptimizationBO.start, ARGS: (Portfolio.test_portfolio(), 100, 4) }, 'forward': { TARGET: ForwardBO.start, ARGS: [] } } @staticmethod def start(name: str) -> bool: if name in ProcessManager.CONFIGURATION.keys(): configuration: Dict[str, Tuple[Any, ...]] = ProcessManager.CONFIGURATION.get(name) process: Process = ProcessManager.__find(name) if process is None or not process.is_alive(): process = multiprocessing.Process(name=name, target=configuration.get(ProcessManager.TARGET), args=configuration.get(ProcessManager.ARGS)) process.start() return True return False @staticmethod def stop(name: str) -> bool: if name in ProcessManager.CONFIGURATION.keys(): process: Process = ProcessManager.__find(name) if process is not None: process.terminate() process.join() return True return False @staticmethod def running() -> bool: return len(multiprocessing.active_children()) > 0 @staticmethod def get_active_names() -> List[str]: return sorted(list(map(lambda p: p.name, list(multiprocessing.active_children())))) @staticmethod def get_inactive_names() -> List[str]: return sorted(list(filter(lambda p: p not in ProcessManager.get_active_names(), ProcessManager.CONFIGURATION.keys()))) @staticmethod def __find(name: str) -> Optional[Process]: return next(iter(filter(lambda p: p.name == name, multiprocessing.active_children())), None)
if evaluation is None: break evaluation_sum: Decimal = ZERO analysis_funds: List[Decimal] = [] table_number: int = len(tables) for i in range(table_number): analysis_number: int = i + 1 statistic_name: str = 'statistic analysis{}'.format( analysis_number) statistic: StatisticBO = StatisticBO(statistic_name) broker: BrokerBO = BrokerBO(cash, fee) AnalyserBO.analyse(tables[i], StrategyBO.counter_cyclical, broker, statistic, evaluation_attempt) evaluation_sum += broker.funds() analysis_funds.append(broker.funds().normalize()) if analysis_number == table_number and evaluation_sum > optimise_sum: EvaluationDAO.create(evaluation_sum, ','.join(map(str, analysis_funds)), evaluation_attempt) @staticmethod def start(portfolio: List[str], number: int, group_number: int) -> None: group_size: int = int(number / group_number) groups: Tuple[Tuple[str]] = Utils.group(group_size, portfolio[:number]) OptimizationBO.optimise(IntradayDAO.dataframe_group(groups)) if __name__ == '__main__': OptimizationBO.start(Portfolio.test_portfolio(), 100, 4)