Exemplo n.º 1
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)
Exemplo n.º 2
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])
Exemplo n.º 3
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)
Exemplo n.º 4
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]
         ])
Exemplo n.º 5
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]
         ])
Exemplo n.º 6
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]]
         )
Exemplo n.º 7
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]]
         )
Exemplo n.º 8
0
def prompt_positions():
    '''
    Prompt user and read in keyboard input of investment positions
    Raises InvalidListError, InvalidPositionError, ValueError for incorrect inputs
    '''
    
    while True:
        try:
            userinput = input("Enter the positions as a list with one space after each comma.")
            return InvestmentPositions.parse_positions(userinput)
        
        except (InvalidListError, InvalidPositionError, ValueError) as e:
            print(e)
Exemplo n.º 9
0
 def test_parse_positions_invalid_format(self):
     '''
     Test parse_positions raises InvalidListError if list_as_string is not in "list" format.
     '''
     with self.assertRaises(InvalidListError):
         InvestmentPositions.parse_positions("1, 10, 100, 1000")
Exemplo n.º 10
0
 def test_parse_invalid_positions(self):
     '''
     Invalid position value (5) raises InvalidPositionError
     '''
     with self.assertRaises(InvalidPositionError):
         InvestmentPositions.parse_positions("[1, 5, 100, 1000]")
Exemplo n.º 11
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])
Exemplo n.º 12
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)
Exemplo n.º 13
0
 def test_parse_positions_invalid_format(self):
     '''
     Test parse_positions raises InvalidListError if list_as_string is not in "list" format.
     '''
     with self.assertRaises(InvalidListError):
         InvestmentPositions.parse_positions("1, 10, 100, 1000")
Exemplo n.º 14
0
 def test_parse_invalid_positions(self):
     '''
     Invalid position value (5) raises InvalidPositionError
     '''
     with self.assertRaises(InvalidPositionError):
         InvestmentPositions.parse_positions("[1, 5, 100, 1000]")
Exemplo n.º 15
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)