Esempio n. 1
0
 def test_buy_all(self):
     investor = Investor(18., init_cash=100., shares=0., income=100.)
     investor.buy_all(20.)
     self.assertEqual(investor.shares, 5.)
     self.assertEqual(investor.cash, 0.)
     investor.get_paid()
     investor.buy_all(40.)
     self.assertEqual(investor.shares, 7.5)
     self.assertEqual(investor.cash, 0.)
     investor.buy_all(20.)
     self.assertEqual(investor.shares, 7.5)
     self.assertEqual(investor.cash, 0.)
Esempio n. 2
0
 def test_get_net_worth(self):
     investor = Investor(18., init_cash=10., income=2., shares=0.)
     self.assertEqual(investor.get_net_worth(20.), 10.)
     investor.get_paid()
     self.assertEqual(investor.get_net_worth(20.), 12.)
     investor.shares = 5.
     self.assertEqual(investor.get_net_worth(20.), 112.)
Esempio n. 3
0
 def test_buy_all(self):
     investor = Investor(18., init_cash=100., shares=0., income=100.)
     investor.buy_all(20.)
     self.assertEqual(investor.shares, 5.)
     self.assertEqual(investor.cash, 0.)
     investor.get_paid()
     investor.buy_all(40.)
     self.assertEqual(investor.shares, 7.5)
     self.assertEqual(investor.cash, 0.)
     investor.buy_all(20.)
     self.assertEqual(investor.shares, 7.5)
     self.assertEqual(investor.cash, 0.)
Esempio n. 4
0
    def test_init(self):
        investor1 = Investor(15.)
        self.assertEqual(investor1.buy_at, 15.)
        self.assertEqual(investor1.sell_at, 15.)
        self.assertEqual(investor1.init_cash, 10000.)
        self.assertEqual(investor1.cash, 10000.)
        self.assertEqual(investor1.shares, 0.)
        self.assertEqual(investor1.income, 2000.)

        investor2 = Investor(16., 20., 5000., 22., 1000.)
        self.assertEqual(investor2.buy_at, 16.)
        self.assertEqual(investor2.sell_at, 20.)
        self.assertEqual(investor2.init_cash, 5000.)
        self.assertEqual(investor2.cash, 5000.)
        self.assertEqual(investor2.shares, 22.)
        self.assertEqual(investor2.income, 1000.)
Esempio n. 5
0
 def test_get_net_worth(self):
     investor = Investor(18., init_cash=10., income=2., shares=0.)
     self.assertEqual(investor.get_net_worth(20.), 10.)
     investor.get_paid()
     self.assertEqual(investor.get_net_worth(20.), 12.)
     investor.shares = 5.
     self.assertEqual(investor.get_net_worth(20.), 112.)
Esempio n. 6
0
 def test_sell_all(self):
     investor = Investor(18., init_cash=10., shares=0.)
     investor.sell_all(20.)
     self.assertEqual(investor.cash, investor.init_cash)
     self.assertEqual(investor.shares, 0.)
     investor.shares = 5.
     investor.sell_all(20.)
     self.assertEqual(investor.cash, 110.)
     self.assertEqual(investor.shares, 0.)
Esempio n. 7
0
 def test_sell_all(self):
     investor = Investor(18., init_cash=10., shares=0.)
     investor.sell_all(20.)
     self.assertEqual(investor.cash, investor.init_cash)
     self.assertEqual(investor.shares, 0.)
     investor.shares = 5.
     investor.sell_all(20.)
     self.assertEqual(investor.cash, 110.)
     self.assertEqual(investor.shares, 0.)
Esempio n. 8
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.)
Esempio n. 9
0
 def test_get_paid(self):
     investor = Investor(18., init_cash=10., income=2.)
     for i in range(5):
         self.assertEqual(investor.cash, 10. + i * 2.)
         investor.get_paid()
Esempio n. 10
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.)
Esempio n. 11
0
 def test_get_paid(self):
     investor = Investor(18., init_cash=10., income=2.)
     for i in range(5):
         self.assertEqual(investor.cash, 10. + i * 2.)
         investor.get_paid()