def test_tree(self): a1 = AssetFundNetwork.Asset(price=1, daily_volume=100, symbol='a1') f1 = Fund('f1', {'a1': 10}, 100, 1, 1) f2 = 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}, mi_calc=mi_calc, limit_trade_step=False) action_manager = ActionsManager(network.assets, 0.5, 1, [50, 30]) SysConfig.set("STEP_ORDER_SIZE", 0.5) f1.marginal_call = MagicMock(return_value=False) f2.marginal_call = MagicMock() f2.marginal_call.side_effect = f1_margin_call_side_effect actual_tree = PortfolioFlashCrashRootChanceGameState( action_manager, af_network=network, defender_budget=50) expected_tree = self.gen_tree() self.assertEqual(actual_tree.chance_prob(), {'p1': 0.75, 'p2': 0.25}) self.assertEqual(actual_tree.tree_size, 8) self.cmp_tree(expected_tree, actual_tree)
def test_marginal_call_true(self): assets = { 'XXX': Asset(1, 20, 1.5, 'XXX'), 'YYY': Asset(1, 20, 1.5, 'yyy') } fund = Fund('F1', {'XXX': 10, 'YYY': 10}, 5, 2, 3) self.assertTrue(True, fund.marginal_call(assets))