예제 #1
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.)
예제 #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.)
예제 #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.)
예제 #4
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.)
예제 #5
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.)
예제 #6
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.)
예제 #7
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()
예제 #8
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()