Exemplo n.º 1
0
    def test_react_to_pe(self):
        investor1 = Investor(18., init_cash=100., shares=0., income=100.)

        investor1.react_to_pe(20., 20.)  # don't buy
        self.assertEqual(investor1.shares, 0.)
        self.assertEqual(investor1.cash, 100.)

        investor1.react_to_pe(15., 20.)  # buy
        self.assertEqual(investor1.shares, 5.)
        self.assertEqual(investor1.cash, 0.)

        investor1.react_to_pe(15., 20.)  # hold (no cash)
        self.assertEqual(investor1.shares, 5.)
        self.assertEqual(investor1.cash, 0.)

        investor1.react_to_pe(20., 30.)  # sell
        self.assertEqual(investor1.shares, 0.)
        self.assertEqual(investor1.cash, 150.)

        investor1.get_paid()  # cash is now 250.
        investor1.react_to_pe(15., 10.)  # buy
        self.assertEqual(investor1.shares, 25.)
        self.assertEqual(investor1.cash, 0.)

        investor2 = Investor(18.,
                             sell_at=22.,
                             init_cash=100.,
                             shares=10.,
                             income=100.)

        investor2.react_to_pe(20., 20.)  # hold
        self.assertEqual(investor2.shares, 10.)
        self.assertEqual(investor2.cash, 100.)

        investor2.react_to_pe(23., 20.)  # sell
        self.assertEqual(investor2.shares, 0.)
        self.assertEqual(investor2.cash, 300.)

        investor2.react_to_pe(19., 20.)  # hold
        self.assertEqual(investor2.shares, 0.)
        self.assertEqual(investor2.cash, 300.)

        investor2.react_to_pe(15., 30.)  # buy
        self.assertEqual(investor2.shares, 10.)
        self.assertEqual(investor2.cash, 0.)
Exemplo n.º 2
0
    def test_react_to_pe(self):
        investor1 = Investor(18., init_cash=100., shares=0., income=100.)

        investor1.react_to_pe(20., 20.)  # don't buy
        self.assertEqual(investor1.shares, 0.)
        self.assertEqual(investor1.cash, 100.)

        investor1.react_to_pe(15., 20.)  # buy
        self.assertEqual(investor1.shares, 5.)
        self.assertEqual(investor1.cash, 0.)

        investor1.react_to_pe(15., 20.)  # hold (no cash)
        self.assertEqual(investor1.shares, 5.)
        self.assertEqual(investor1.cash, 0.)

        investor1.react_to_pe(20., 30.)  # sell
        self.assertEqual(investor1.shares, 0.)
        self.assertEqual(investor1.cash, 150.)

        investor1.get_paid()  # cash is now 250.
        investor1.react_to_pe(15., 10.)  # buy
        self.assertEqual(investor1.shares, 25.)
        self.assertEqual(investor1.cash, 0.)

        investor2 = Investor(18., sell_at=22., init_cash=100., shares=10.,
                             income=100.)

        investor2.react_to_pe(20., 20.)  # hold
        self.assertEqual(investor2.shares, 10.)
        self.assertEqual(investor2.cash, 100.)

        investor2.react_to_pe(23., 20.)  # sell
        self.assertEqual(investor2.shares, 0.)
        self.assertEqual(investor2.cash, 300.)

        investor2.react_to_pe(19., 20.)  # hold
        self.assertEqual(investor2.shares, 0.)
        self.assertEqual(investor2.cash, 300.)

        investor2.react_to_pe(15., 30.)  # buy
        self.assertEqual(investor2.shares, 10.)
        self.assertEqual(investor2.cash, 0.)