Ejemplo n.º 1
0
 def test_simulation(self):
     '''
     Test the simulation class
     '''
     self.assertIn(simulation(1,1000).outcome(),[0,2000])
     self.assertIn(simulation(10,100).outcome(),list(range(0,2002,200)))
     self.assertIn(simulation(100,10).outcome(),list(range(0,2002,20)))
     self.assertIn(simulation(1000,1).outcome(),list(range(0,2001,2)))
     self.assertEqual(len(simulation(1000,1).outcome_total(10)),10)
Ejemplo n.º 2
0
def investment_simulation():
    '''
    This is the main function of the simulation
    Args:
    Returns:
    Raises:
        QuitSimulation
    '''
    print('This is a simulation of investments.')
    print('You can exit with "QUIT".')
    print("Please input a list of the number of shares to buy in parallel.")
    print('You can purchase it in $1, $10, $100, and $1000 denominations.')
    while True:
        try:
            positions = input("List of Numbers (Format as [1,10,100,1000]): ")
            if positions.upper() == 'QUIT':
                raise QuitSimulation
            num_trials = input('How many times to randomly repeat the test? ')
            if num_trials.upper() == 'QUIT':
                raise QuitSimulation
            num_shares, num_trials = reading_in(positions,num_trials)
            break
        except InputError:
            print('Invalid Input!\n Please according to the instruction!')
    file=open('results.txt','w')
    for pos in num_shares:
        cumu_ret=simulation(pos,1000/pos).outcome_total(num_trials)
        cumu_ret=np.array(cumu_ret)
        daily_ret=(cumu_ret/1000) - 1
        generate_report(file,daily_ret,pos)
    file.close()
    print('Finish!')