Example #1
0
def read_result(pos_list, num_tests):
    np.random.seed(777)
    invest(pos_list, num_tests).bet()

    with open('results.txt', 'r') as string:
        read_result = string.read()
    return read_result
Example #2
0
def inpt():
    
    #### part 1 input positions list
    position_input = input('Please enter a list of the number of shares (positions) to buy, for example, 1,10,100,1000; Or enter Q to quit \n')
    
    indicator_1 = 1   # first, give an indicator for input, 0 means incorrect input and 1 means correct 
    
    # if user doesn't input 'Q' to quit, we first convert the user input (e.g. "1,10,100") to what we need (e.g., ['1','10','100'])
    # And, check whether the input is correct or not
    if position_input != 'Q':
        convert_input = pos_input_correct(position_input)
        for i in range(len(convert_input)):
            ind = convert_input[i]
            if num_input_correct(ind) == -9999:  # if any element in the list is invalid, indicator=0
                indicator_1 = 0
                break
    
    # this while loop will check whether the user input is correct again and again until the input is correct
    while position_input != 'Q' and indicator_1 == 0:
        position_input = input('Your input is incorrect. Please enter a list of the number of shares (positions) to buy, for example, 1,10,100,1000; Or enter Q to quit \n')
        
        if position_input != 'Q':
            convert_input = pos_input_correct(position_input)
            for i in range(len(convert_input)):
                ind = convert_input[i]
                if num_input_correct(ind) == -9999:
                    indicator_1 = 0
                    break
                else:
                    indicator_1 = 1
                    
    #### part 2 input number of trials and check the correct
    # this part will be executed when part 1 complete and not enter 'Q'
    if position_input != 'Q':
        indicator_2 = 1;      # again, first set an indicator to indicate correct (1) or incorrect input (0) 
        trials_input = input('Enter the number of times to randomly repeat the test; Or enter Q to quit \n')
        
        if num_input_correct(trials_input) == -9999:
            indicator_2 = 0
        
        while trials_input != 'Q' and indicator_2 == 0:
            indicator_2 = 1
            print('Invalid input')   # print invalid when incorrect input occur and ask user input again 
            trials_input = input('Enter the number of times to randomly repeat the test; Or enter Q to quit \n')
            if num_input_correct(trials_input) == -9999:
                indicator_2 = 0
            if trials_input == 'Q':
                break
            
    #### part 3, if there is no invalid input we will output the histogram and results.txt 
    if position_input != 'Q' and trials_input != 'Q':
        new_position_list = []
        for position in pos_input_correct(position_input):
            new_position_list.append(int(position))
        final_position_list = new_position_list
        invest(final_position_list,int(trials_input)).bet() # use the class invest to get plots and results
Example #3
0
def inpt():

    #### part 1 input positions list
    position_input = input(
        'Please enter a list of the number of shares (positions) to buy, for example, 1,10,100,1000; Or enter Q to quit \n'
    )

    indicator_1 = 1  # first, give an indicator for input, 0 means incorrect input and 1 means correct

    # if user doesn't input 'Q' to quit, we first convert the user input (e.g. "1,10,100") to what we need (e.g., ['1','10','100'])
    # And, check whether the input is correct or not
    if position_input != 'Q':
        convert_input = pos_input_correct(position_input)
        for i in range(len(convert_input)):
            ind = convert_input[i]
            if num_input_correct(
                    ind
            ) == -9999:  # if any element in the list is invalid, indicator=0
                indicator_1 = 0
                break

    # this while loop will check whether the user input is correct again and again until the input is correct
    while position_input != 'Q' and indicator_1 == 0:
        position_input = input(
            'Your input is incorrect. Please enter a list of the number of shares (positions) to buy, for example, 1,10,100,1000; Or enter Q to quit \n'
        )

        if position_input != 'Q':
            convert_input = pos_input_correct(position_input)
            for i in range(len(convert_input)):
                ind = convert_input[i]
                if num_input_correct(ind) == -9999:
                    indicator_1 = 0
                    break
                else:
                    indicator_1 = 1

    #### part 2 input number of trials and check the correct
    # this part will be executed when part 1 complete and not enter 'Q'
    if position_input != 'Q':
        indicator_2 = 1
        # again, first set an indicator to indicate correct (1) or incorrect input (0)
        trials_input = input(
            'Enter the number of times to randomly repeat the test; Or enter Q to quit \n'
        )

        if num_input_correct(trials_input) == -9999:
            indicator_2 = 0

        while trials_input != 'Q' and indicator_2 == 0:
            indicator_2 = 1
            print(
                'Invalid input'
            )  # print invalid when incorrect input occur and ask user input again
            trials_input = input(
                'Enter the number of times to randomly repeat the test; Or enter Q to quit \n'
            )
            if num_input_correct(trials_input) == -9999:
                indicator_2 = 0
            if trials_input == 'Q':
                break

    #### part 3, if there is no invalid input we will output the histogram and results.txt
    if position_input != 'Q' and trials_input != 'Q':
        new_position_list = []
        for position in pos_input_correct(position_input):
            new_position_list.append(int(position))
        final_position_list = new_position_list
        invest(final_position_list, int(trials_input)).bet(
        )  # use the class invest to get plots and results