def test_single_agent(self): a1 = AssetFundNetwork.Asset(price=1, daily_volume=100, symbol='a1') a2 = AssetFundNetwork.Asset(price=1, daily_volume=100, symbol='a1') f1 = AssetFundNetwork.Fund('f1', {'a2': 10}, 100, 1, 1) f2 = AssetFundNetwork.Fund('f2', {'a1': 20}, 100, 1, 1) mi_calc = MarketImpactCalculator() mi_calc.get_updated_price = MagicMock() mi_calc.get_updated_price.side_effect = update_price_side_effects network = AssetFundNetwork.AssetFundsNetwork(funds={ 'f1': f1, 'f2': f2 }, assets={ 'a1': a1, 'a2': a2 }, mi_calc=mi_calc, limit_trade_step=True) f1.marginal_call = MagicMock(return_value=False) f2.marginal_call = MagicMock() f2.marginal_call.side_effect = f1_margin_call_side_effect actions_mgr = ActionsManager(network.assets, 0.1, 2) result = single_agent(actions_mgr, network, 200) print(result.value) print(result.actions) self.assertEqual(result.value, -1) self.assertListEqual(result.actions, [[Sell('a1', 20)], ['MARKET']])
def not_test_solver_finds_best_attack_integration(self): a1 = AssetFundNetwork.Asset(50, 2, 'a1') a2 = AssetFundNetwork.Asset(20, 2, 'a2') a3 = AssetFundNetwork.Asset(30, 2, 'a3') f1 = AssetFundNetwork.Fund('f1', {'a1': 10}, {'a2': 10}, 1000, 1, 1) f2 = AssetFundNetwork.Fund('f2', {'a2': 10}, {'a3': 10}, 1000, 1, 1) network = AssetFundNetwork.AssetFundsNetwork(funds=[f1, f2], assets=[a1, a2, a3]) solver = SingleAgentDynamicProgrammingSolver(network, 10, 0.5) print(solver.results.value) print(solver.results.actions)
def test_solution2(self): a1 = AssetFundNetwork.Asset(price=2, daily_volume=500, symbol='a1') a2 = AssetFundNetwork.Asset(price=2, daily_volume=1000, symbol='a2') f1 = AssetFundNetwork.Fund('f1', {'a1': 10, 'a2': 10}, 16, 1, 1) f2 = AssetFundNetwork.Fund('f2', {'a1': 5, 'a2': 4}, 5, 2, 0.25) network = AssetFundNetwork.AssetFundsNetwork(funds = {'f1':f1, 'f2':f2}, assets={'a1':a1, 'a2':a2}, mi_calc=MockMarketImpactTestCalculator(), intraday_asset_gain_max_range=None, limit_trade_step=False ) actions,cost = single_fund_attack_optimal_attack_generator(network, 'f1', MockMarketImpactTestCalculator(),0.25,3) self.assertEqual(cost, 500) self.assertEqual(actions, [Sell('a1', 125),Sell('a1', 125)])