def initial_stocks(): tea = ('common', 'TEA', 0, None, 100) pop = ('common', 'POP', 8, None, 100) ale = ('common', 'ALE', 23, None, 60) gin = ('preferred', 'GIN', 8, 0.02, 100) joe = ('common', 'JOE', 13, None, 250) for item in [tea, pop, ale, gin, joe]: stock_factory(*item)
def create_stock(): stock_type = input("Is the new stock [c]ommon or [p]referred? (c/p) ") if stock_type.lower() not in ('c', 'p'): return "You must choose 'c' or 'p' as the stock type" else: stock_type = 'common' if stock_type == 'c' else 'preferred' stock_symbol = input("What is the new stock's string identifier (eg 'TEA')? ") last_dividend = int(input("What was the new stock's last dividend in whole pennies? ")) fixed_dividend = input("What is the new stock's fixed dividend if applicable (eg 0.02 for 2%)? ") if fixed_dividend: fixed_dividend = float(fixed_dividend) par_value = int(input("What is the new stock's par value? ")) stock_factory(stock_type, stock_symbol, last_dividend, fixed_dividend, par_value) return list_stocks()
def setUp(self): self.common_stock = stock_factory( stock_type='common', stock_symbol='Tea', last_dividend=7, par_value=100 ) self.preferred_stock = stock_factory( stock_type='preferred', stock_symbol='Gin', last_dividend=8, fixed_dividend=0.02, par_value=100 ) for count in range(15): for stock in [self.common_stock, self.preferred_stock]: record_trade( stock.stock_symbol, time=datetime.datetime.now() - datetime.timedelta(minutes=count), quantity=(count+1), direction='buy', traded_price=10 )