def setUp(self): ensemble_returns = Returns(buildNumericDataFrame(['all'], 10)) returns1 = Returns(buildNumericDataFrame(['a'], 10)) returns2 = Returns(buildNumericDataFrame(['b'], 10)) returns3 = Returns(buildNumericDataFrame(['c'], 10)) sub_returns = [returns1, returns2, returns3] self.strategy = EnsembleStrategy("CC", "C", []) self.strategy.indexer.positions = Mock() self.strategy.market = Mock() lagged_positions = Mock(spec = Position) lagged_positions.applied_to.return_value = ensemble_returns self.strategy.indexer.positions.return_value = lagged_positions sub_strat1 = Mock(spec = Strategy) sub_strat1.returns = Mock(spec = Returns) sub_strat1.returns.collapse_by.return_value = returns1 sub_strat2 = Mock(spec = Strategy) sub_strat2.returns = Mock(spec = Returns) sub_strat2.returns.collapse_by.return_value = returns2 sub_strat3 = Mock(spec = Strategy) sub_strat3.returns = Mock(spec = Returns) sub_strat3.returns.collapse_by.return_value = returns3 self.strategy.strategies = [sub_strat1, sub_strat2, sub_strat3] self.expected_result = ensemble_returns for returns in sub_returns: self.expected_result.data[returns.columns[0]] = returns.data
def setUp(self): ensemble_returns = Returns(buildNumericDataFrame(['all'], 10)) returns1 = Returns(buildNumericDataFrame(['a'], 10)) returns2 = Returns(buildNumericDataFrame(['b'], 10)) returns3 = Returns(buildNumericDataFrame(['c'], 10)) sub_returns = [returns1, returns2, returns3] self.strategy = EnsembleStrategy("CC", "C", []) self.strategy.indexer.positions = Mock() self.strategy.market = Mock() lagged_positions = Mock(spec=Position) lagged_positions.applied_to.return_value = ensemble_returns self.strategy.indexer.positions.return_value = lagged_positions sub_strat1 = Mock(spec=Strategy) sub_strat1.returns = Mock(spec=Returns) sub_strat1.returns.collapse_by.return_value = returns1 sub_strat2 = Mock(spec=Strategy) sub_strat2.returns = Mock(spec=Returns) sub_strat2.returns.collapse_by.return_value = returns2 sub_strat3 = Mock(spec=Strategy) sub_strat3.returns = Mock(spec=Returns) sub_strat3.returns.collapse_by.return_value = returns3 self.strategy.strategies = [sub_strat1, sub_strat2, sub_strat3] self.expected_result = ensemble_returns for returns in sub_returns: self.expected_result.data[returns.columns[0]] = returns.data
def setUp(self): self.strategy = Strategy("OO", "C") self.position_series = buildNumericDataFrame(["ASX", "BHP", "CBA"], 20) self.positions = Position(self.position_series) self.returns = buildNumericDataFrame(["ASX", "BHP", "CBA"], 20) / 10 self.strategy.measure = Mock() self.strategy.positions = self.positions self.strategy.market = Mock() self.strategy.market.returns = Mock() self.strategy.market.returns.return_value = Returns(self.returns)
def setUp(self): self.strategy = Strategy("OO", "C") self.position_series = buildNumericDataFrame(["ASX", "BHP", "CBA"], 20) self.positions = Position(self.position_series) self.returns = buildNumericDataFrame(["ASX", "BHP", "CBA"], 20) / 10 self.strategy.measure = Mock() self.strategy.positions = self.positions self.strategy.market = Mock() self.strategy.market.returns = Mock() self.strategy.market.returns.return_value = Returns(self.returns)
def testReturnsCombinesTogether(self): data2 = buildNumericDataFrame(['a', 'b'], len(self.data)) expected_data = self.returns.data expected_data[data2.columns] = data2 returns2 = Returns(data2) self.returns.append(returns2) self.assertTrue(self.returns.data.equals(expected_data))
def testReturnsCombinesTogether(self): data2 = buildNumericDataFrame(['a', 'b'], len(self.data)) expected_data = self.returns.data expected_data[data2.columns] = data2 returns2 = Returns(data2) self.returns.append(returns2) self.assertTrue(self.returns.data.equals(expected_data))
def setUp(self): self.strategy = Mock(spec = Strategy) self.model = BlockMeanReturnsForecaster(window = 4) self.tickers = ["ASX", "BHP", "CBA"] self.returns = AverageReturns(buildNumericDataFrame(self.tickers, 10)) self.strategy.market_returns = self.returns self.strategy.forecasts = None
def setUp(self): self.strategy = Mock(spec=Strategy) self.model = BlockMeanReturnsForecaster(window=4) self.tickers = ["ASX", "BHP", "CBA"] self.returns = AverageReturns(buildNumericDataFrame(self.tickers, 10)) self.strategy.market_returns = self.returns self.strategy.forecasts = None
def setUp(self): self.tickers = ['ASX', 'BHP', 'CBA'] self.forecast_data = buildNumericDataFrame(self.tickers, 10) self.forecasts = Mock(spec=Forecast) self.forecasts.optF.return_value = self.forecast_data self.strategy = Strategy("OO", "C") self.strategy.forecasts = self.forecasts self.model = SingleLargestF() self.model_results = self.model(self.strategy)
def setUp(self): self.tickers = ['ASX', 'BHP', 'CBA'] self.forecast_data = buildNumericDataFrame(self.tickers, 10) self.forecasts = Mock(spec = Forecast) self.forecasts.optF.return_value = self.forecast_data self.strategy = Strategy("OO", "C") self.strategy.forecasts = self.forecasts self.model = SingleLargestF() self.model_results = self.model(self.strategy)
def testStrategyCallsIndexerForPositions(self): position_series = buildNumericDataFrame(["ASX", "BHP"], 10) positions = Position(position_series) self.strategy.indexer.positions = Mock() self.strategy.indexer.positions.return_value = positions self.strategy.positions = positions result = self.strategy.lagged_positions self.assertIsInstance(result, Position) expected_calls = [call(positions)] self.strategy.indexer.positions.assert_has_calls(expected_calls)
def setUp(self): self.tickers = ['ASX', 'BHP', 'CBA', 'MOC', 'QBE'] self.forecast_data = buildNumericDataFrame(self.tickers, 10) self.forecasts = Mock(spec=Forecast) self.forecasts.optF.return_value = self.forecast_data self.strategy = Strategy("OO", "C") self.strategy.forecasts = self.forecasts self.num_positions = 3 self.select_positions = HighestRankedFs(self.num_positions) self.positions = self.select_positions(self.strategy)
def testStrategyCallsIndexerForPositions(self): position_series = buildNumericDataFrame(["ASX", "BHP"], 10) positions = Position(position_series) self.strategy.indexer.positions = Mock() self.strategy.indexer.positions.return_value = positions self.strategy.positions = positions result = self.strategy.lagged_positions self.assertIsInstance(result, Position) expected_calls = [call(positions)] self.strategy.indexer.positions.assert_has_calls(expected_calls)
def setUp(self): self.tickers = ['ASX', 'BHP', 'CBA', 'MOC', 'QBE'] self.forecast_data = buildNumericDataFrame(self.tickers, 10) self.forecasts = Mock(spec = Forecast) self.forecasts.optF.return_value = self.forecast_data self.strategy = Strategy("OO", "C") self.strategy.forecasts = self.forecasts self.num_positions = 3 self.select_positions = HighestRankedFs(self.num_positions) self.positions = self.select_positions(self.strategy)
def testModelProducesResultsForAllData(self): tickers = ["ASX", "BHP", "CBA"] indicator_data = buildTextDataFrame(tickers, 10) self.strategy.lagged_indicator = Indicator(indicator_data) self.strategy.market_returns = buildNumericDataFrame(tickers, 10) forecast = self.model(self.strategy) self.assertEqual(indicator_data.shape, forecast.mean.shape) self.assertEqual(indicator_data.shape, forecast.sd.shape) self.assertTrue(all(indicator_data.index == forecast.mean.index)) self.assertTrue(all(indicator_data.index == forecast.sd.index)) self.assertEqual(tickers, list(forecast.mean.columns)) self.assertEqual(tickers, list(forecast.sd.columns))
def testModelProducesResultsForAllData(self): tickers = ["ASX", "BHP", "CBA"] indicator_data = buildTextDataFrame(tickers, 10) self.strategy.lagged_indicator = Indicator(indicator_data) self.strategy.market_returns = buildNumericDataFrame(tickers, 10) forecast = self.model(self.strategy) self.assertEqual(indicator_data.shape, forecast.mean.shape) self.assertEqual(indicator_data.shape, forecast.sd.shape) self.assertTrue(all(indicator_data.index == forecast.mean.index)) self.assertTrue(all(indicator_data.index == forecast.sd.index)) self.assertEqual(tickers, list(forecast.mean.columns)) self.assertEqual(tickers, list(forecast.sd.columns))
def setUp(self): self.prices = buildNumericDataFrame(["ASX", "BHP", "CBA"], 10).abs() self.strategy = Mock() self.strategy.get_indicator_prices = Mock(return_value = self.prices) self.crossover = Crossover(5, 3) self.indicator = self.crossover(self.strategy)
def setUp(self): self.trade_timing = "OO" self.ind_timing = "C" self.strategy = Strategy(self.trade_timing, self.ind_timing) self.dummy_timeSeries = buildNumericDataFrame(["ASX", "BHP", "CBA"], 10)
def setUp(self): self.tickers = ['ASX', 'BHP', 'CBA'] self.position_data = buildNumericDataFrame(self.tickers, 10) self.position = Position(self.position_data)
def testStrategyContainerElementImplementsShift(self): time_series = buildNumericDataFrame(["ASX", "BHP", "CBA"], 10) indicator = StrategyContainerElement() indicator.data = time_series lagged_indicator = indicator.shift(2) self.assertTrue(time_series.shift(2).equals(lagged_indicator.data))
def setUp(self): self.data = buildNumericDataFrame(["ASX", "BHP", "CBA"], 20) / 10 self.returns = Returns(self.data)
def setUp(self): self.prices = buildNumericDataFrame(["ASX", "BHP", "CBA"], 10).abs() self.strategy = Mock() self.strategy.get_indicator_prices = Mock(return_value=self.prices) self.crossover = Crossover(5, 3) self.indicator = self.crossover(self.strategy)
def testStrategyContainerElementImplementsShift(self): time_series = buildNumericDataFrame(["ASX", "BHP", "CBA"], 10) indicator = StrategyContainerElement() indicator.data = time_series lagged_indicator = indicator.shift(2) self.assertTrue(time_series.shift(2).equals(lagged_indicator.data))
def setUp(self): self.trade_timing = "OO" self.ind_timing = "C" self.strategy = Strategy(self.trade_timing, self.ind_timing) self.dummy_timeSeries = buildNumericDataFrame(["ASX", "BHP", "CBA"], 10)
def setUp(self): self.data = buildNumericDataFrame(["ASX", "BHP", "CBA"], 20) / 10 self.returns = Returns(self.data)
def setUp(self): self.tickers = ['ASX', 'BHP', 'CBA'] self.position_data = buildNumericDataFrame(self.tickers, 10) self.position = Position(self.position_data)