def test_different_mappings(self): """ Tests: Evaluator#inspect_over_time and #inspect_over_time_with_mappings Compares if both methods return the same values """ stock_market_data = read_stock_market_data( [CompanyEnum.COMPANY_A], [PERIOD_1, PERIOD_2, PERIOD_3]) portfolio_1 = Portfolio(20000, [SharesOfCompany(CompanyEnum.COMPANY_A, 200)]) portfolio_2 = Portfolio(20000, [SharesOfCompany(CompanyEnum.COMPANY_A, 200)]) portfolios = [portfolio_1, portfolio_2] perfect_predictor = PerfectPredictor(CompanyEnum.COMPANY_A) trader_1 = SimpleTrader(perfect_predictor, perfect_predictor) trader_2 = SimpleTrader(perfect_predictor, perfect_predictor) trader_3 = SimpleTrader(RandomPredictor(), RandomPredictor()) traders = [trader_1, trader_2] portfolio_trader_mappings = list( zip(portfolios, traders, [None] * len(portfolios))) evaluator_1 = PortfolioEvaluator([trader_1, trader_1]) evaluator_2 = PortfolioEvaluator([]) evaluator_3 = PortfolioEvaluator([trader_3, trader_3]) # 1 Use evaluator that is initialized *with* traders and call `#inspect_over_time` (i.e. without traders) result_1 = evaluator_1.inspect_over_time(stock_market_data, portfolios, 100) # 2 Use evaluator that is initialized *without* traders and call `#inspect_over_time_with_mapping` # (i.e. with traders) result_2 = evaluator_2.inspect_over_time_with_mapping( stock_market_data, portfolio_trader_mappings, 100) # 3 Use evaluator that is initialized *with* traders and call `#inspect_over_time_with_mapping` # (i.e. with traders) - this should be no problem, because the traders given at initialization time are ignored result_3 = evaluator_3.inspect_over_time_with_mapping( stock_market_data, portfolio_trader_mappings, 100) assert result_1 == result_2 == result_3
('Simple Trader (Team Blue prediction)', Traders.SimpleTrader_with_team_blue_prediction()), ('Simple Trader (Team Green prediction)', Traders.SimpleTrader_with_team_green_prediction()), ('Simple Trader (Team Pink prediction)', Traders.SimpleTrader_with_team_pink_prediction()), ('Simple Trader (Team Red prediction)', Traders.SimpleTrader_with_team_red_prediction()), # Code-Camp Task 2 traders ('Team Blue DQL Trader (perfect prediction)', Traders.TeamBlueDqlTrader_with_perfect_prediction()), ('Team Green DQL Trader (perfect prediction)', Traders.TeamGreenDqlTrader_with_perfect_prediction()), ('Team Pink DQL Trader (perfect prediction)', Traders.TeamPinkDqlTrader_with_perfect_prediction()), ('Team Red DQL Trader (perfect prediction)', Traders.TeamRedDqlTrader_with_perfect_prediction()) ] # Define portfolios for the traders and create a portfolio/trader mapping portfolio_trader_mappings = initialize_portfolios( 10000.0, portfolio_name_trader_mappings) # Evaluate their performance over the testing period evaluator = PortfolioEvaluator([], True) evaluator.inspect_over_time_with_mapping(stock_market_data, portfolio_trader_mappings, date_offset=datetime.date( 2012, 1, 3))