def test_NewsDataContainerDecorator_set_historical_stock_data(self): labels = [] for key, value in GlobalVariables.get_stock_data_labels_dict().items(): labels.append(value) data = [('2016-09-13', 90, 90, 100.15, 100.26, 4000)] df = DataFrame.from_records(data, columns=labels) apple_stock_data_container = StockDataContainer( "Apple Inc.", "AAPL", "") apple_stock_data_container.set_historical_stock_data(df) sd = apple_stock_data_container.historical_stock_data() for col in range(0, len(data[0])): cur_val = sd[sd.keys()[col]][0] des_val = data[0][col] self.assertEqual(des_val, cur_val) news_dec = NewsDataContainerDecorator(apple_stock_data_container, 111, 1, "test news") data_2 = [('2017-11-11', 11, 22, 33, 44, 55)] df_2 = DataFrame.from_records(data_2, columns=labels) news_dec.set_historical_stock_data(df_2) sd = news_dec.historical_stock_data() for col in range(0, len(data_2[0])): cur_val = sd[sd.keys()[col]][0] des_val = data_2[0][col] self.assertEqual(des_val, cur_val)
def test_NewsDataContainerDecorator_set_position_size(self): container = StockDataContainer("test1", "t1", "en") container.set_position_size(100) self.assertEqual(100, container.get_position_size()) news_dec = NewsDataContainerDecorator(container, 111, 1, "test news") news_dec.set_position_size(20) self.assertEqual(20, news_dec.get_position_size())
def test_NewsDataContainerDecorator_set_stop_loss(self): container = StockDataContainer("test1", "t1", "en") container.set_stop_loss(10) self.assertEqual(10, container.get_stop_loss()) news_dec = NewsDataContainerDecorator(container, 111, 1, "test news") news_dec.set_stop_loss(20) self.assertEqual(20, news_dec.get_stop_loss())
def test_NewsDataContainerDecorator_get_names_and_values__target_price_111__stockname_test1( self): container = StockDataContainer("test1", "t1", "en") result_container = container.get_names_and_values() self.assertEqual(10, len(result_container)) news_dec = NewsDataContainerDecorator(container, 111, 0.9, "test news") result_news_dec = news_dec.get_names_and_values() self.assertEqual(13, len(result_news_dec)) self.assertEqual({}, result_news_dec["StrategyAndRecommendation"]) self.assertEqual(111, result_news_dec["Target Price"]) self.assertEqual("test1", result_news_dec["Stockname"]) self.assertEqual(0.9, result_news_dec["Pos. Probability Distribution"])
def convert_backtrader_to_asta_data(hist_data, news_data_dict, date_time, stock_data_container_list): """ Converts the backtrader nect-data into asta stock data container format :param hist_data: historical dat in backtrader format :param news_data_dict: dict with all news data :param date_time: current date to look up in news :param stock_data_container_list: list to insert result :return: - return as ref of the data list """ stock_name = hist_data._name dataname = hist_data._dataname curr_news = "" # add the news text because backtrader does not support news # data from pandas do not have a name --> not add news if isinstance(dataname, str): if dataname in news_data_dict: news_data = news_data_dict[dataname] if hasattr(news_data, "NewsText") and hasattr(news_data, "Date"): for currEntry in range(0, len(news_data.Date)): if str(date_time) in news_data.Date[currEntry]: try: curr_news = str(news_data.NewsText[currEntry]) except Exception as e: pass break # convert backtrader format to asta-format df1 = convert_backtrader_to_dataframe(hist_data) # ticker not implemented, but not needed stock_data_container = StockDataContainer(stock_name, "", "") stock_data_container.set_historical_stock_data(df1) news_dec = NewsDataContainerDecorator(stock_data_container, 0, 0, curr_news) stock_data_container_list.append(news_dec)
def test_analyse_single_news_CDAX_companies(self): rhm = NewsDataContainerDecorator( StockDataContainer("RHEINMETALL AG", "RHM", "de"), 0, 0, "05.03.2018, ANALYSE-FLASH: NordLB hebt Rheinmetall auf 'Kaufen' - Ziel 125 Euro" ) bei = NewsDataContainerDecorator( StockDataContainer("BEIERSDORF AG O.N.", "BEI", "de"), 0, 0, "ANALYSE-FLASH: Independent Research senkt Ziel für Beiersdorf auf 118 Euro" ) ads = NewsDataContainerDecorator( StockDataContainer("ADIDAS AG NA O.N.", "ADS", "de"), 0, 0, "ANALYSE-FLASH: Credit Suisse nimmt Adidas mit 'Underperform' wieder auf" ) # acx = NewsDataContainerDecorator(StockDataContainer("BET-AT-HOME.COM AG O.N.", "ACX", "de"), 0, 0, # , 0 # rhhby = NewsDataContainerDecorator(StockDataContainer("Roche Holding AG", "RHHBY", "") # lor = NewsDataContainerDecorator(StockDataContainer("LOrealfuture", "LORFK8.EX", "") stock_data_container_list = [rhm, bei, ads] # TODO, acx, rhhby, lor] analysis = GermanTaggerAnalyseNews( stock_data_container_list, 0.7, GlobalVariables.get_data_files_path() + 'nltk_german_classifier_data.pickle') # CDAX companies result = analysis.analyse_single_news(ads) t1 = round(result.positive_prob_dist(), 2) self.assertGreater(0.7, t1) self.assertEqual(result.get_stock_name(), "ADIDAS AG NA O.N.") self.assertEqual(result.stock_ticker(), "ADS") result = analysis.analyse_single_news(bei) t1 = round(result.positive_prob_dist(), 2) self.assertGreater(0.7, t1) self.assertEqual(result.get_stock_name(), "BEIERSDORF AG O.N.") self.assertEqual("BEI", result.stock_ticker()) result = analysis.analyse_single_news(rhm) t1 = round(result.positive_prob_dist(), 2) self.assertGreater(t1, 0.7) self.assertEqual(result.get_stock_name(), "RHEINMETALL AG") self.assertEqual("RHM", result.stock_ticker())
def test_run_strategy__two_positive_news__both_with_pos_classification( self): labels = [] for key, value in GlobalVariables.get_stock_data_labels_dict().items(): labels.append(value) data = [('2016-09-13', 90, 90, 100.15, 100.26, 4000), ('2016-09-14', 90, 90, 22.95, 100.11, 4000), ('2016-09-15', 90, 90, 100.14, 100.62, 4000)] df = DataFrame.from_records(data, columns=labels) aapl = NewsDataContainerDecorator( StockDataContainer("Apple Inc.", "AAPL", "en"), 0, 0, "ANALYSE-FLASH: Credit Suisse nimmt Apple mit 'Underperform' wieder auf" ) rwe = NewsDataContainerDecorator( StockDataContainer("RWE AG ST O.N.", "RWE", ""), 0, 0, "ANALYSE-FLASH: Credit Suisse nimmt RWE mit 'Outperform' wieder auf" ) aapl.set_historical_stock_data(df) rwe.set_historical_stock_data(df) rwe_stock_data_container = StockDataContainer("RWE AG ST O.N.", "RWE", "") rwe_stock_data_container.set_historical_stock_data(df) stock_data_container_list = [aapl, rwe] analysis_parameters = { 'news_threshold': 0.7, 'german_tagger': filepath + 'nltk_german_classifier_data.pickle' } stock_screener = StrategyFactory() news_strategy = stock_screener.prepare( "SimplePatternNewsStrategy", stock_data_container_list=stock_data_container_list, analysis_parameters=analysis_parameters) results = news_strategy.run_strategy() self.assertEqual(results[0] in stock_data_container_list, True) apple_idx = results.index(aapl) rwe_idx = results.index(rwe) t1 = round(results[apple_idx].positive_prob_dist(), 2) self.assertEqual(results[apple_idx].get_stock_name(), "Apple Inc.") self.assertGreater(0.7, t1) t1 = round(results[rwe_idx].positive_prob_dist(), 2) self.assertEqual(results[rwe_idx].get_stock_name(), "RWE AG ST O.N.") self.assertGreater(t1, 0.7)
def _method_to_execute(self, elm): """ read news from traderfox home page with dpa-afx-compact news :param date_time_format: news datetime format :param date_file: file for last check date :param url: traderfox news page url :return: news as list """ from Utils.FileUtils import FileUtils all_news = [] date_time = (str(elm.footer.span.get_text())) # date and Time date_time = date_time.rsplit(' Uhr')[ 0] # TODO: split because of datetime format article_text = (str(elm.h2.get_text(strip=True)) ) # h2 --> article head line news_text = date_time.replace(',', '.') + ", " + article_text.replace( ',', '.') # TODO REMOVE THAT # THIS IS JUST FOR BACKTESTING NEWS DATA COLLECTION FileUtils.append_textline_to_file( news_text, GlobalVariables.get_data_files_path() + "NewsForBacktesting.txt", True) all_news.append(news_text) prep_news = self.text_analysis.optimize_text_for_german_tagger( news_text) name_ticker_exchange_target_prize = \ self.text_analysis.identify_stock_name_and_stock_ticker_and_target_price_from_news_nltk_german_classifier( news_text) if name_ticker_exchange_target_prize is not None and name_ticker_exchange_target_prize.get_stock_name( ) != "": container = StockDataContainer( name_ticker_exchange_target_prize.get_stock_name(), name_ticker_exchange_target_prize.stock_ticker(), name_ticker_exchange_target_prize.stock_exchange()) if container in self.stock_data_container_list: idx = self.stock_data_container_list.index(container) container_2 = self.stock_data_container_list[idx] if isinstance(container_2, StockDataContainer): container = container_2 self.stock_data_container_list.remove(container_2) news_dec = NewsDataContainerDecorator( container, name_ticker_exchange_target_prize.stock_target_price(), 0, prep_news) self.stock_data_container_list.append(news_dec)
def test_analyse_single_news_with_all_params(self): labels = [] for key, value in GlobalVariables.get_stock_data_labels_dict().items(): labels.append(value) data = [('2016-09-13', 23.6, 23.73, 23.15, 23.26, 31000), ('2016-09-14', 23.33, 23.43, 22.95, 23.11, 31000), ('2016-09-15', 23.15, 23.77, 23.14, 23.62, 31000), ('2016-09-16', 23.57, 23.68, 23.38, 23.5, 31000)] df = DataFrame.from_records(data, columns=labels) rwe_container = NewsDataContainerDecorator( StockDataContainer("RWE AG ST O.N.", "RWE", "de"), 0, 0, "20.07.2018 um 08:02, ANALYSE-FLASH: Morgan Stanley hebt RWE auf \\'Overweight\\' und Ziel auf 26 Euro" ) rwe_container.set_historical_stock_data(df) stock_data_container_list = [ rwe_container, StockDataContainer("RHEINMETALL AG", "RHM", "de"), StockDataContainer("BEIERSDORF AG O.N.", "BEI", "de"), StockDataContainer("ADIDAS AG NA O.N.", "ADS", "de"), StockDataContainer("Apple Inc.", "AAPL", "en"), StockDataContainer("BET-AT-HOME.COM AG O.N.", "ACX", "de"), StockDataContainer("Roche Holding AG", "RHHBY", ""), StockDataContainer("LOrealfuture", "LORFK8.EX", "") ] analysis = GermanTaggerAnalyseNews( stock_data_container_list, 0.7, GlobalVariables.get_data_files_path() + 'nltk_german_classifier_data.pickle') result = analysis.analyse_single_news(rwe_container) t1 = round(result.positive_prob_dist(), 2) self.assertEqual("RWE AG ST O.N.", result.get_stock_name()) self.assertEqual("RWE", result.stock_ticker()) self.assertEqual("de", result.stock_exchange()) self.assertEqual({}, result.get_recommendation_strategies()) self.assertGreater(t1, 0.7)
def test_FixedSizeRiskModel_with_factory_and_Decorator(self): labels = [] for key, value in GlobalVariables.get_stock_data_labels_dict().items(): labels.append(value) data = [('2016-09-30', 23.35, 23.91, 23.24, 23.8, 31000), ('2016-10-03', 23.68, 23.69, 23.39, 23.5, 31000), ('2016-10-04', 23.52, 23.64, 23.18, 23.28, 31000), ('2016-10-05', 23.28, 23.51, 23.27, 23.43, 31000), ('2016-10-06', 23.38, 23.56, 23.29, 23.48, 42000), ('2016-10-07', 23.58, 23.65, 23.37, 23.48, 43000), ('2016-10-10', 23.62, 23.88, 23.55, 23.77, 44000), ('2016-10-11', 23.62, 23.74, 23.01, 23.16, 45000), ('2016-10-12', 23.16, 26, 23.11, 23.18, 46000)] df = DataFrame.from_records(data, columns=labels) stock_data_container = StockDataContainer("Apple Inc.", "AAPL", "") stock_data_container.set_historical_stock_data(df) news_dec = NewsDataContainerDecorator(stock_data_container, 111, 0.9, "test news") stock_data_container_list = [news_dec] rm_factory = RiskModelFactory() parameter_dict = { 'OrderTarget': 'order_target_value', 'TargetValue': 2500 } fsr = rm_factory.prepare( "FixedSizeRiskModel", stock_data_container_list=stock_data_container_list, parameter_dict=parameter_dict) fsr.determine_risk() self.assertEqual( np.math.isclose(26.130, stock_data_container_list[0].get_stop_buy(), abs_tol=0.01), True) self.assertEqual( np.math.isclose(25.35, stock_data_container_list[0].get_stop_loss(), abs_tol=0.01), True) self.assertEqual( np.math.isclose(95, stock_data_container_list[0].get_position_size(), abs_tol=0.01), True) self.assertEqual("FixedSizeRiskModel", stock_data_container_list[0].get_risk_model())
def test_NewsDataContainerDecorator_update_used_strategy_and_recommendation( self): container = StockDataContainer("test1", "t1", "en") news_dec = NewsDataContainerDecorator(container, 111, 0.9, "test news") news_dec.update_used_strategy_and_recommendation("TestStrategy", "BUY") res_dict = news_dec.get_recommendation_strategies() self.assertEqual(1, len(res_dict)) rec_and_datetime = res_dict["TestStrategy"] self.assertEqual(2, len(rec_and_datetime)) rec = rec_and_datetime[0] dt = parser.parse(rec_and_datetime[1]) self.assertEqual("BUY", rec) elapsed = datetime.now() - dt self.assertGreater(timedelta(seconds=0.1), elapsed) news_dec.update_used_strategy_and_recommendation( "TestStrategy_2", "SELL") res_dict = news_dec.get_recommendation_strategies() self.assertEqual(2, len(res_dict)) rec_and_datetime = res_dict["TestStrategy"] self.assertEqual(2, len(rec_and_datetime)) rec = rec_and_datetime[0] dt = parser.parse(rec_and_datetime[1]) self.assertEqual("BUY", rec) elapsed = datetime.now() - dt self.assertGreater(timedelta(seconds=0.01), elapsed) rec_and_datetime = res_dict["TestStrategy_2"] self.assertEqual(2, len(rec_and_datetime)) rec = rec_and_datetime[0] dt = parser.parse(rec_and_datetime[1]) self.assertEqual("SELL", rec) elapsed = datetime.now() - dt self.assertGreater(timedelta(seconds=0.01), elapsed)
def test_run_strategy_with_two_news_for_one_stock(self): name_idx = 0 datetime_idx = 1 w52hi_parameter_dict = { 'check_days': 5, 'min_cnt': 3, 'min_vol_dev_fact': 1.2, 'within52w_high_fact': 0.98 } parameter_dict = { 'news_threshold': 0.7, 'german_tagger': filepath + 'nltk_german_classifier_data.pickle' } labels = [] for key, value in GlobalVariables.get_stock_data_labels_dict().items(): labels.append(value) data = [('2016-09-30', 23.35, 23.91, 23.24, 23.8, 31000), ('2016-10-03', 23.68, 23.69, 23.39, 23.5, 31000), ('2016-10-04', 23.52, 23.64, 23.18, 23.28, 31000), ('2016-10-05', 23.28, 23.51, 23.27, 23.43, 31000), ('2016-10-06', 23.38, 23.56, 23.29, 23.48, 42000), ('2016-10-07', 23.58, 23.65, 23.37, 23.48, 43000), ('2016-10-10', 23.62, 23.88, 23.55, 23.77, 44000), ('2016-10-11', 23.62, 23.74, 23.01, 23.16, 45000), ('2016-10-12', 23.16, 23.8, 23.11, 23.18, 46000)] df = DataFrame.from_records(data, columns=labels) apple_stock_data_container = NewsDataContainerDecorator( StockDataContainer("Apple Inc.", "AAPL", ""), 0, 0, "ANALYSE-FLASH: Credit Suisse nimmt Apple mit 'Underperform' wieder auf" ) apple_stock_data_container_2 = NewsDataContainerDecorator( StockDataContainer("Apple Inc.", "AAPL", ""), 0, 0, "ANALYSE-FLASH: Sparkasse hebt Apple auf 'Buy' und Ziel auf 97 Euro" ) apple_stock_data_container.set_historical_stock_data(df) apple_stock_data_container_2.set_historical_stock_data(df) stock_data_container_list = [ apple_stock_data_container, apple_stock_data_container_2 ] stock_screener = StrategyFactory() news_strategy = stock_screener.prepare( "SimplePatternNewsStrategy", stock_data_container_list=stock_data_container_list, analysis_parameters=parameter_dict) news_strategy.run_strategy() self.assertEqual( "SELL", stock_data_container_list[0].get_recommendation_strategies() ["SimplePatternNewsStrategy"][name_idx]) self.assertEqual( "BUY", stock_data_container_list[1].get_recommendation_strategies() ["SimplePatternNewsStrategy"][name_idx]) # 52 wh strat #################################### w52_hi_strat = stock_screener.prepare( "W52HighTechnicalStrategy", stock_data_container_list=stock_data_container_list, analysis_parameters=w52hi_parameter_dict) w52_hi_strat.run_strategy() self.assertEqual(stock_data_container_list[0].get_stock_name(), "Apple Inc.") self.assertEqual( "BUY", stock_data_container_list[0].get_recommendation_strategies() ["W52HighTechnicalStrategy"][name_idx]) self.assertEqual( "BUY", stock_data_container_list[1].get_recommendation_strategies() ["W52HighTechnicalStrategy"][name_idx]) dt = parser.parse( stock_data_container_list[0].get_recommendation_strategies() ["W52HighTechnicalStrategy"][datetime_idx]) elapsed = datetime.now() - dt self.assertGreater(timedelta(seconds=0.1), elapsed) self.assertEqual( "SELL", stock_data_container_list[0].get_recommendation_strategies() ["SimplePatternNewsStrategy"][name_idx]) self.assertEqual( "BUY", stock_data_container_list[1].get_recommendation_strategies() ["SimplePatternNewsStrategy"][name_idx])
def test_analyse_single_news(self): rwe_cont = NewsDataContainerDecorator( StockDataContainer("RWE AG ST O.N.", "RWE", "de"), 0, 0, "ANALYSE-FLASH: Credit Suisse nimmt RWE mit 'Outperform' wieder auf" ) rwe_cont2 = NewsDataContainerDecorator( StockDataContainer("RWE AG ST O.N.", "RWE", "de"), 0, 0, "19.03.2018 um 08:58, ANALYSE-FLASH: HSBC senkt RWE auf 'Reduce' - Ziel 18 Euro" ) rhm = StockDataContainer("RHEINMETALL AG", "RHM", "de") bei = StockDataContainer("BEIERSDORF AG O.N.", "BEI", "de") ads = StockDataContainer("ADIDAS AG NA O.N.", "ADS", "de") aapl = NewsDataContainerDecorator( StockDataContainer("Apple Inc.", "AAPL", "en"), 0, 0, "ANALYSE-FLASH: Credit Suisse nimmt Apple mit 'Underperform' wieder auf" ) aapl2 = NewsDataContainerDecorator( StockDataContainer("Apple Inc.", "AAPL", "en"), 0, 0, "ANALYSE-FLASH: Independent Research senkt Ziel für Apple auf 118 Euro" ) aapl3 = NewsDataContainerDecorator( StockDataContainer("Apple Inc.", "AAPL", "en"), 0, 0, "05.03.2018, ANALYSE-FLASH: NordLB hebt Apple auf 'Kaufen' - Ziel 125 Euro" ) acx = StockDataContainer("BET-AT-HOME.COM AG O.N.", "ACX", "de") rhhby = StockDataContainer("Roche Holding AG", "RHHBY", "") lor = StockDataContainer("LOrealfuture", "LORFK8.EX", "") stock_data_container_list = [ rwe_cont, rwe_cont2, rhm, bei, ads, aapl, acx, rhhby, lor, aapl2, aapl3 ] analysis = GermanTaggerAnalyseNews( stock_data_container_list, 0.7, GlobalVariables.get_data_files_path() + 'nltk_german_classifier_data.pickle') result = analysis.analyse_single_news(rwe_cont) t1 = round(result.positive_prob_dist(), 2) self.assertEqual("RWE AG ST O.N.", result.get_stock_name()) self.assertEqual("RWE", result.stock_ticker()) self.assertGreater(t1, 0.7) result = analysis.analyse_single_news(rwe_cont2) t1 = round(result.positive_prob_dist(), 2) self.assertEqual(result.get_stock_name(), "RWE AG ST O.N.") self.assertEqual("RWE", result.stock_ticker()) self.assertGreater(0.7, t1) result = analysis.analyse_single_news(aapl) t1 = round(result.positive_prob_dist(), 2) self.assertEqual(result.get_stock_name(), "Apple Inc.") self.assertEqual("AAPL", result.stock_ticker()) self.assertGreater(0.7, t1) result = analysis.analyse_single_news(aapl2) t1 = round(result.positive_prob_dist(), 2) self.assertEqual(result.get_stock_name(), "Apple Inc.") self.assertEqual("AAPL", result.stock_ticker()) self.assertGreater(0.7, t1) result = analysis.analyse_single_news(aapl3) t1 = round(result.positive_prob_dist(), 2) self.assertEqual("AAPL", result.stock_ticker()) self.assertGreater(t1, 0.7)
def test_NewsDataContainerDecorator_test_rank(self): container = StockDataContainer("test1", "t1", "en") pos_prob_dist = 0 news_dec = NewsDataContainerDecorator(container, 111, pos_prob_dist, "test news") news_dec.update_used_strategy_and_recommendation( "TestStrategy", "SELL") self.assertEqual(-3, news_dec.get_rank()) pos_prob_dist = 0.49 news_dec = NewsDataContainerDecorator(container, 111, pos_prob_dist, "test news") news_dec.update_used_strategy_and_recommendation("TestStrategy", "BUY") self.assertEqual(0, news_dec.get_rank()) pos_prob_dist = 0.51 news_dec = NewsDataContainerDecorator(container, 111, pos_prob_dist, "test news") news_dec.update_used_strategy_and_recommendation("TestStrategy", "BUY") self.assertEqual(2, news_dec.get_rank()) pos_prob_dist = 0.76 news_dec = NewsDataContainerDecorator(container, 111, pos_prob_dist, "test news") news_dec.update_used_strategy_and_recommendation("TestStrategy", "BUY") self.assertEqual(3, news_dec.get_rank()) pos_prob_dist = 1 news_dec = NewsDataContainerDecorator(container, 111, pos_prob_dist, "test news") news_dec.update_used_strategy_and_recommendation("TestStrategy", "BUY") self.assertEqual(3, news_dec.get_rank()) pos_prob_dist = 1 news_dec = NewsDataContainerDecorator(container, 111, pos_prob_dist, "test news") news_dec.update_used_strategy_and_recommendation( "TestStrategy", "SELL") self.assertEqual(1, news_dec.get_rank())
def test_StockDataContainer_run_and_fill_with__W52HighTechnicalStrategy_BUY__and_SimplePatternNewsStrategy_BUY( self): w52hi_parameter_dict = { 'check_days': 5, 'min_cnt': 3, 'min_vol_dev_fact': 1.2, 'within52w_high_fact': 0.98 } labels = [] for key, value in GlobalVariables.get_stock_data_labels_dict().items(): labels.append(value) data = [('2016-09-30', 23.35, 23.91, 23.24, 23.8, 31000), ('2016-10-03', 23.68, 23.69, 23.39, 23.5, 31000), ('2016-10-04', 23.52, 23.64, 23.18, 23.28, 31000), ('2016-10-05', 23.28, 23.51, 23.27, 23.43, 31000), ('2016-10-06', 23.38, 23.56, 23.29, 23.48, 42000), ('2016-10-07', 23.58, 23.65, 23.37, 23.48, 43000), ('2016-10-10', 23.62, 23.88, 23.55, 23.77, 44000), ('2016-10-11', 23.62, 23.74, 23.01, 23.16, 45000), ('2016-10-12', 23.16, 26, 23.11, 23.18, 46000)] df = DataFrame.from_records(data, columns=labels) stock_data_container = NewsDataContainerDecorator( StockDataContainer("Apple Inc.", "AAPL", ""), 0, 0, "ANALYSE-FLASH: Credit Suisse nimmt Apple mit 'Outperform' wieder auf, BUY" ) stock_data_container.set_historical_stock_data(df) stock_data_container_list = [stock_data_container] ################################################## # 52 w strategy stock_screener = StrategyFactory() w52_hi_strat = stock_screener.prepare( "W52HighTechnicalStrategy", stock_data_container_list=stock_data_container_list, analysis_parameters=w52hi_parameter_dict) # results = w52_hi_strat.run_strategy() w52_hi_strat.run_strategy() self.assertGreater(len(stock_data_container_list), 0) self.assertEqual( "BUY", stock_data_container_list[0].get_recommendation_strategies() ["W52HighTechnicalStrategy"][0]) dt = parser.parse( stock_data_container_list[0].get_recommendation_strategies() ["W52HighTechnicalStrategy"][1]) elapsed = datetime.now() - dt self.assertGreater(timedelta(seconds=0.011), elapsed) # stock_data_container_list = results ############################## # SimplePatternNewsStrategy parameter_dict = { 'news_threshold': 0.7, 'german_tagger': filepath + 'nltk_german_classifier_data.pickle' } stock_screener = StrategyFactory() news_strategy = stock_screener.prepare( "SimplePatternNewsStrategy", stock_data_container_list=stock_data_container_list, analysis_parameters=parameter_dict) news_strategy.run_strategy() self.assertEqual(stock_data_container_list[0].get_stock_name(), "Apple Inc.") self.assertEqual( "BUY", stock_data_container_list[0].get_recommendation_strategies() ["W52HighTechnicalStrategy"][0]) self.assertEqual( "BUY", stock_data_container_list[0].get_recommendation_strategies() ["SimplePatternNewsStrategy"][0])