# This program takes a list output of [1,10,100,1000], which are the number of 
# shares to buy in parallel in a day; and an input of number of trials to randomly
# repeat the test. The final results are saved as 4 pdf files to show the distribution
# of daily return and a text file records the mean and standard deviation for the
# 4 different ways of investment. 

import re
import numpy as np
import matplotlib.pyplot as plt
from InvestmentReturn import InvestmentReturn

def main():
	'''Take input from user and calculate results by using the InvestmentReturn Class'''

	positions = raw_input("Please enter a list of number to buy: \n")
	position = [int(pos) for pos in re.findall(r'\d+', positions)]
	if position != [1, 10, 100, 1000]:
		raise InputError
	num_trials = int(raw_input("How many time to randomly repeat the test?\n"))
	if num_trials == 0:
		raise MathError
	experiment = InvestmentReturn(position, num_trials)
	experiment.outcome()

class InputError(Exception):
	'''User-defined exception for undesired input error'''
	def __str__(self):
		return 
class MathError(Exception):
	'''User-defind exception for math error'''
	def __str__(self):
		return 


if __name__ == '__main__':
	try:
		main()
	except ValueError:
		print "Please enter a non-zero integer number for number of trials. "
	except KeyboardInterrupt:
		print "Program ended by Keyboard Interuption"
	except InputError:
		print "This program only takes this list input: [1,10,100,1000], please try again."
	except MathError:
		print "Please enter a non_zero integer number for number of trials."
3f2b9e8e830a188c950cf6b620b7b1830a35e389
# This program takes a list output of [1,10,100,1000], which are the number of 
# shares to buy in parallel in a day; and an input of number of trials to randomly
# repeat the test. The final results are saved as 4 pdf files to show the distribution
# of daily return and a text file records the mean and standard deviation for the
# 4 different ways of investment. 

import re
import numpy as np
import matplotlib.pyplot as plt
from InvestmentReturn import InvestmentReturn

def main():
	'''Take input from user and calculate results by using the InvestmentReturn Class'''

	positions = raw_input("Please enter a list of number to buy: \n")
	position = [int(pos) for pos in re.findall(r'\d+', positions)]
	if position != [1, 10, 100, 1000]:
		raise InputError
	num_trials = int(raw_input("How many time to randomly repeat the test?\n"))
	if num_trials == 0:
		raise MathError
	experiment = InvestmentReturn(position, num_trials)
	experiment.outcome()

class InputError(Exception):
	'''User-defined exception for undesired input error'''
	def __str__(self):
		return 
class MathError(Exception):
	'''User-defind exception for math error'''
	def __str__(self):
		return 


if __name__ == '__main__':
	try:
		main()
	except ValueError:
		print "Please enter a non-zero integer number for number of trials. "
	except KeyboardInterrupt:
		print "Program ended by Keyboard Interuption"
	except InputError:
		print "This program only takes this list input: [1,10,100,1000], please try again."
	except MathError:
		print "Please enter a non_zero integer number for number of trials."