def test_calc_industry_info(self): p = MarketSignalProcessor('CALC_INDUSTRY_INFO') result = p.reduce() self.assertIsNotNone(result) for industry in ['ind_1', 'ind_2', 'ind_3']: for kind in ['name', 'index', 'score', 'change', 'state']: self.assertIsNotNone(result['%s_%s' % (industry, kind)])
def test_calc_style_info(self): p = MarketSignalProcessor('CALC_STYLE_INFO') result = p.reduce() self.assertIsNotNone(result) for style in ['g', 'v', 'y', 'q', 's']: for kind in ['index', 'score', 'change', 'state']: self.assertIsNotNone(result['%s_%s' % (style, kind)])
def test_calc_size_info(self): p = MarketSignalProcessor('CALC_SIZE_INFO') result = p.reduce() self.assertIsNotNone(result) for market in ['kp', 'kd']: for size in ['lg', 'md', 'sm']: for kind in ['index', 'score', 'change', 'state']: self.assertIsNotNone(result['%s_%s_%s' % (market, size, kind)])
def test_calc_bm_info(self): p = MarketSignalProcessor('CALC_BM_INFO') result = p.reduce() self.assertIsNotNone(result) self.assertIn('kospi_index', result) self.assertIn('kospi_change', result) self.assertIn('kospi_rate', result) self.assertIn('kosdaq_index', result) self.assertIn('kosdaq_change', result) self.assertIn('kosdaq_rate', result)
def get(self, request, *args, **kwargs): algorithm = request.GET.get('algorithm') task = request.GET.get('task') ##### 모든 태스크 클래스는 리듀서를 불러서 result 값을 받아야 합니다 ##### ##### ALGO #1 ##### if algorithm == 'MARKET': task_class = MarketSignalProcessor(task) result = task_class.reduce() ##### ALGO #2 ##### elif algorithm == 'SCANNER': task_class = ScannerProcessor(task) result = task_class.reduce() ##### ALGO #3 ##### elif algorithm == 'PORTFOLIO': portfolio_type = request.GET.get('portfolio_type') stocks = request.GET.get('stocks').split(',') capital = float(request.GET.get('capital')) task_class = PortfolioProcessor(task, portfolio_type, stocks, capital) result = task_class.reduce() ##### ALGO #4 ##### elif algorithm == 'RMS': task_class = RMSProcessor(task) result = task_class.reduce() else: # 받은 알고리즘 값이 존재하지 않는 알고리즘이면 '없는 알고리즘'이라고 리턴 result = '없는 알고리즘' # 위에서 받은 result 값을 result_json에 result키값으로 넣어준다 if result == '없는 알고리즘': result_json = {'status': 'FAIL', 'result': result} return Response(result_json, status=status.HTTP_400_BAD_REQUEST) else: result_json = {'status': 'GOOD', 'result': result} return Response(result_json, status=status.HTTP_200_OK)
def test_emit_buysell_signal(self): p = MarketSignalProcessor('EMIT_BUYSELL_SIGNAL') result = p.reduce() self.assertIsNotNone(result) self.assertIn('kospi', result) self.assertIn('kosdaq', result)
def test_make_rank_data(self): p = MarketSignalProcessor('MAKE_RANK_DATA') result = p.reduce() self.assertIsNotNone(result) self.assertIsInstance(result, pd.DataFrame)