예제 #1
0
    def read_data(self):
        from Utils.FileUtils import FileUtils
        if self.reload_stockdata:
            FileUtils.check_file_exists_and_delete(
                self._parameter_dict['last_check_date_file'])

        # self._read_news_from_traderfox(self._parameter_dict['last_check_date_file'])
        # TODO enable for enhanced info
        # url = "https://traderfox.de/nachrichten/dpa-afx-compact/kategorie-2-5-8-12/"  # analysen, ad hoc, unternehmen, pflichtmitteilungen
        start_time = datetime.now()

        self.text_analysis = GermanTaggerAnalyseNews(
            self.stock_data_container_list, None,
            self._parameter_dict['german_tagger'])

        # ex: #news = "27.02. 10:41 dpa-AFX: ANALYSE-FLASH: Bryan Garnier hebt Morphosys auf 'Buy' - Ziel 91 Euro"
        all_news = []
        all_articles = self._read_news_from_traderfox(
            self._parameter_dict['last_check_date_file'])

        # all_news.extend(self.map_list(all_articles))
        self.map_list(all_articles)

        print("Time diff map_list:" + (str(datetime.now() - start_time)))
    def test_dump_and_load_other_parameter_to_file(self):
        global val, w, root
        root = Tk()
        top = ASTA_Framework(root)
        controller = MvcController.init(root, top)

        data_file_path = GlobalVariables.get_data_files_path()

        strat_param_file = data_file_path + '\\TestData\\ParameterFile_test_dump_and_load_strat_params.pickle'
        FileUtils.check_file_exists_and_delete(strat_param_file)

        strategy_parameter_dict = {
            'SimplePatternNewsStrategy': {
                'news_threshold': 0.7,
                'german_tagger':
                data_file_path + 'nltk_german_classifier_data.pickle',
                'data_readers': {
                    'TraderfoxNewsDataReader': {
                        'last_check_date_file':
                        data_file_path + 'TestData\\last_date_time.csv',
                        'german_tagger':
                        data_file_path + 'nltk_german_classifier_data.pickle',
                        'reload_data': True,
                        'ticker_needed': False
                    },
                    'HistoricalDataReader': {
                        'weeks_delta': 52,
                        'data_source': 'iex',
                        'reload_data': True,
                        'ticker_needed': False
                    }
                }
            },
            'W52HighTechnicalStrategy': {
                'check_days': 7,
                'min_cnt': 3,
                'min_vol_dev_fact': 1.2,
                'within52w_high_fact': 0.98,
                'data_readers': {
                    'HistoricalDataReader': {
                        'weeks_delta': 52,
                        'data_source': 'iex',
                        'reload_data': False,
                        'ticker_needed': True
                    }
                }
            }
        }
        stock_data_file = data_file_path + 'TestData\\stock_data_container_file.pickle'
        other_params = {
            'stock_data_container_file': stock_data_file,
            'dict_with_stock_pages_to_read': {
                'SP500': {
                    'websource_address':
                    "http://en.wikipedia.org/wiki/List_of_S%26P_500_companies",
                    'find_name': 'table',
                    'class_name': 'class',
                    'table_class': 'wikitable sortable',
                    'ticker_column_to_read': 0,
                    'name_column_to_read': 1,
                    'stock_exchange': 'en'
                }
            },
            'RiskModels': {
                'FixedSizeRiskModel': {
                    'OrderTarget': 'order_target_value',
                    'TargetValue': 2500
                }
            }
        }

        params = {
            'Strategies': strategy_parameter_dict,
            'OtherParameters': other_params
        }
        req_params = StrategyFactory.get_required_parameters_with_default_parameters(
        )
        controller.dump_analysis_parameters_to_file(strat_param_file, params,
                                                    req_params)

        controller.load_analysis_parameters_from_file(strat_param_file,
                                                      req_params)
        self.assertEqual(ast.literal_eval(params),
                         controller.model.analysis_parameters.get(),
                         req_params)
    def test_dump_params(self):
        global val, w, root
        root = Tk()
        top = ASTA_Framework(root)
        controller = MvcController.init(root, top)
        data_file_path = GlobalVariables.get_data_files_path()

        strat_param_file = GlobalVariables.get_data_files_path(
        ) + '\\TestData\\ParameterFile_test_dump_and_load_strat_params.pickle'
        FileUtils.check_file_exists_and_delete(strat_param_file)

        strategy_parameter_dict = {
            'SimplePatternNewsStrategy': {
                'news_threshold': 0.7,
                'german_tagger':
                data_file_path + 'nltk_german_classifier_data.pickle',
                'data_readers': {
                    'TraderfoxNewsDataReader': {
                        'last_check_date_file':
                        data_file_path + 'TestData\\last_date_time.csv',
                        'german_tagger':
                        data_file_path + 'nltk_german_classifier_data.pickle',
                        'reload_data': True,
                        'ticker_needed': False
                    },
                    'HistoricalDataReader': {
                        'weeks_delta': 52,
                        'data_source': 'iex',
                        'reload_data': True,
                        'ticker_needed': False
                    }
                }
            }
        }
        stock_data_file = data_file_path + 'TestData\\stock_data_container_file.pickle'
        other_params = {
            'stock_data_container_file': stock_data_file,
            'dict_with_stock_pages_to_read': {
                'SP500': {
                    'websource_address':
                    "http://en.wikipedia.org/wiki/List_of_S%26P_500_companies",
                    'find_name': 'table',
                    'class_name': 'class',
                    'table_class': 'wikitable sortable',
                    'ticker_column_to_read': 0,
                    'name_column_to_read': 1,
                    'stock_exchange': 'en'
                }
            },
            'RiskModels': {
                'FixedSizeRiskModel': {
                    'OrderTarget': 'order_target_value',
                    'TargetValue': 2500
                }
            }
        }

        params = {
            'Strategies': strategy_parameter_dict,
            'OtherParameters': other_params
        }
        req_params = StrategyFactory.get_required_parameters_with_default_parameters(
        )
        import _pickle as pickle
        with open(strat_param_file, "wb") as f:
            pickle.dump(params, f)