Пример #1
0
 def testTotal_gain2(self):
     self.assertTrue(total_gain(100,3)[0] <= 1 and total_gain(100,3)[0] >= -1)  
     self.assertTrue(total_gain(10,10)[9] <= 1 and total_gain(10,10)[9] >= -1)  
     self.assertTrue(total_gain(1, 10)[5] <= 1 and total_gain(1, 10)[5] >= -1)   
Пример #2
0
    except Not_a_Valid_Position: #Custom exception
        print('A position must be either of these values: 1, 10, 100, 1000')  

while True:
    '''This while gets the number of trials and makes sure the input is valid.'''
    num_trials = input('How many times to randomly repeat the test? ')
    if num_trials.isdigit():
        if int(num_trials) == 0:
            print('Zero is not a valid number. Please Try again.')
        else:
            num_trials = int(num_trials)
            break
    else: 
        print('Number of trials must be apositive integer. Please Try again.')

        
results = open("results.txt", "w")
for position in positions_revised:
    total_gain_postion = total_gain(position, num_trials) #find the total gain for any position in the input list
    expected_gain_total = mean(total_gain_postion) 
    std_postion = std(total_gain_postion)
    
    with open('results.txt', 'a') as myfile:
        myfile.write('mean and standard deviation for postion ' + str(position) + 
                    ' are: ' + str(expected_gain_total) + ' and ' + str(std_postion) + "\n")
        plt.clf()
        plt.hist(total_gain_postion, 100, range=[-1,1])
        plt.xlabel('daily gain')
        plt.title('Daily gain frequencies over ' + str(num_trials)+ ' days, for position ' + str(position))
        filename = 'histogram_' + str(position) + '_pos.pdf'
        plt.savefig(filename)
Пример #3
0
 def testTotal_gain1(self):
     #Again because this function's output is random, instead of testing the output directly, we test some properties of the output.
     self.assertTrue(total_gain(100,3).shape == (3,1))  
     self.assertTrue(total_gain(10,31).shape == (31,1))  
     self.assertTrue(total_gain(1,10000).shape == (10000,1))  
Пример #4
0
while True:
    '''This while gets the number of trials and makes sure the input is valid.'''
    num_trials = input('How many times to randomly repeat the test? ')
    if num_trials.isdigit():
        if int(num_trials) == 0:
            print('Zero is not a valid number. Please Try again.')
        else:
            num_trials = int(num_trials)
            break
    else:
        print('Number of trials must be apositive integer. Please Try again.')

results = open("results.txt", "w")
for position in positions_revised:
    total_gain_postion = total_gain(
        position,
        num_trials)  #find the total gain for any position in the input list
    expected_gain_total = mean(total_gain_postion)
    std_postion = std(total_gain_postion)

    with open('results.txt', 'a') as myfile:
        myfile.write('mean and standard deviation for postion ' +
                     str(position) + ' are: ' + str(expected_gain_total) +
                     ' and ' + str(std_postion) + "\n")
        plt.clf()
        plt.hist(total_gain_postion, 100, range=[-1, 1])
        plt.xlabel('daily gain')
        plt.title('Daily gain frequencies over ' + str(num_trials) +
                  ' days, for position ' + str(position))
        filename = 'histogram_' + str(position) + '_pos.pdf'
        plt.savefig(filename)