Ejemplo n.º 1
0
    def test_investment_default1(self):

        self.simInfo.theParameters.set('assetSalesFactor', 1.2)   # fudge factor
        self.simInfo.theParameters.set('targetCashProportion', 0.0)

        self.econ.params.set('fireSaleFactor', 5.0)  # large fire sale effect

        for i in range(4):
            # a chain of banks
            self.investments[i].buy(10, self.banks[i])
            self.investments[i].buy(10, self.banks[i + 1])
            self.banks[i + 1].deposits = 15
        self.investments[0].buy(10, self.banks[0])
        self.investments[3].buy(10, self.banks[4])
        self.banks[0].cash = -15
        # at the outset, they all have capital 5
        for b, cap in zip(range(5), [5, 5, 5, 5, 5]):
            bc = self.banks[b].equity_value()
            eq_(cap, bc, "Expected bank %s to have capital %r but has %r" % (b, cap, bc))
            # bank 0 is going to have to sell its investments
        simulator.do_updates(self.simInfo)
        # 2 should have gone bust. bank 0 will have sold a lot of investment 0, which will make bank 1 bust.
        # but bank 1 has no reason to sell, so no other banks feel the effects.
        assert self.banks[0].totalDefault < 1.0, "bank 0 should have defaulted but has not"
        assert self.banks[1].totalDefault < 1.0, "bank 1 should have defaulted but has not"
        balanceSheetHistories, borrowingHistories, defaultHistories = results.collect_bank_histories(self.simInfo)
        investmentHistories = results.collect_investment_histories(self.simInfo)
        eq_(2, len(defaultHistories), "Should be 2 default events but got %r" % len(defaultHistories))
        # and they should be in order
        for b in range(len(defaultHistories)):
            eq_(defaultHistories[b][1], self.banks[b].id_,
                "expected %r to go bust would be %r but it is %r" % (b, self.banks[b], defaultHistories[b][1]))
        pHistories = investmentHistories.prices
        eq_(6, len(pHistories), "expected 6 price records but got %r" % len(pHistories))
        lastPrice = pHistories[-1]
        eq_(2, lastPrice.when, "expected last price record to have time 2 but got %r" % lastPrice.when)
        eq_(self.investments[0].id_, lastPrice.investmentId,
            "expected last price record to be for %r but got %r" % (self.investments[0].id_, lastPrice.investmentId))
        hHistories = investmentHistories.holdings
        lastHolding = hHistories[-1]
        eq_(2, lastHolding.when, "expected last holding change to be at time 2 but got %r" % lastHolding.when)
        eq_(self.investments[0].id_, lastHolding.investmentId,
            "expected last holding record to be for %r but got %r" % (self.investments[0].id_,
                                                                      lastHolding.investmentId))
Ejemplo n.º 2
0
    def test_loan_default(self):

        for i in range(4):
            # a chain of banks
            loanAmount = 5 * (i + 1)
            self.simInfo.loanNetwork.add_edge(self.banks[i + 1], self.banks[i], amount=loanAmount)
            self.banks[i].cash = 6
        self.banks[0].deposits = 2
        self.banks[4].deposits = 19
        # at the outset, bank has capital -1, 1-4 have capital 1,
        for b, cap in zip(range(5), [-1, 1, 1, 1, 1]):
            bc = self.banks[b].equity_value()
            eq_(cap, bc, "Expected bank %s to have capital %r but has %r" % (b, cap, bc))
        simulator.do_updates(self.simInfo)
        bankHistories = results.collect_bank_histories(self.simInfo)
        # they should all have gone bust
        for b in range(5):
            assert self.banks[b].totalDefault < 1.0, "expected bank %s to have defaulted but it has not" % b
        eq_(5, len(bankHistories.defaults), "5 banks should be bust but there are %r" % len(bankHistories.defaults))
        # and they should be in order
        for b in range(5):
            eq_(bankHistories.defaults[b][1], self.banks[b].id_,
                "expected %r to go bust would be %r but it is %r" % (b, self.banks[b], bankHistories.defaults[b][1]))