Example #1
0
 def test_n_days_return(self):
     '''
     Test that n_days_returns() generates the correct list of values
     '''
     position_1000 = InvestmentPositions(1, 1000)
     self.assertEqual(position_1000.n_days_return(10),
                      [2000, 0, 0, 2000, 2000, 0, 2000, 2000, 0, 0])
Example #2
0
 def test_simulate_one_share(self):
     '''
     Test that simulation of 1-day-return for 1 share returns 2 * value when
     randnum is fixed as > 0.49 (doubles your investment)
     '''
     position_1000 = InvestmentPositions(1, 1000)
     self.assertEqual(position_1000.simulate_one_share(), 2000)
Example #3
0
 def test_parse_positions_valid_repeated_vals(self):
     '''
     Test that parse_positions accepts repeated valid positions and returns list of InvestmentPosition objects.
     '''
     self.assertEqual(
         InvestmentPositions.parse_positions("[1, 10, 10, 100, 1000, 1]"), [
             InvestmentPositions(position, int(1000 / position))
             for position in [1, 10, 10, 100, 1000, 1]
         ])
Example #4
0
 def test_parse_valid_positions(self):
     '''
     Test that parse_positions on a list_as_string returns a list of InvestmentPosition objects.
     '''
     self.assertEqual(
         InvestmentPositions.parse_positions("[1, 10, 100, 1000]"), [
             InvestmentPositions(position, int(1000 / position))
             for position in [1, 10, 100, 1000]
         ])
Example #5
0
 def test_one_day_return(self):
     '''
     Test that one_day_return() generates the correct sum of returns from 1 day of holding
     '''
     position_1000 = InvestmentPositions(1, 1000)
     self.assertEqual(position_1000.one_day_return(), 0)