Exemple #1
0
 def test_adding_preferred_stocks(self, symbol_, last_dividend_,
                                  fixed_dividend_, par_value_):
     c = PreferredStock(symbol_, last_dividend_, fixed_dividend_,
                        par_value_)
     sm = StockManager()
     current_lenght = len(sm)
     sm[symbol_] = c
     self.assertTrue(len(sm) == current_lenght + 1)
Exemple #2
0
class Trade(dict):
    '''
    Class of Trade
    '''
    __sm = StockManager()
    
    BUY = True
    SELL = False
    
    def __init__(self, stock_symbol_, timestamp_, quantity_, buy_or_sell_, trade_price_):
        '''
        Constructor
        
        @stock_symbol_ - Symbol of the given stock
        @timestamp_ - Storing the time of the trade
        @quantity_ - Quantity of the stock
        @buy_or_sell_ - The stocks are bought or sold
        @trade_price_ - The price of the stocks
        '''
        
        try:
            self['stock'] = self.__sm[str(stock_symbol_)]
            self['timestamp'] = Timestamp(timestamp_)
            self['quantity'] = int(quantity_)
            self['buy_or_sell'] = bool(buy_or_sell_)
            self['trade_price'] = int(trade_price_)
        except (KeyError, ValueError) as error:
            raise TradeException(str(error))
        
        if not self.valid():
            raise TradeException('Non-valid input')
            
    @classmethod
    def create_trade(cls, stock_symbol_, quantity_, buy_or_sell_, trade_price_):
        '''
        Trade is created by using the current time
        
        @stock_symbol_ - Symbol of the given stock
        @quantity_ - Quantity of the stock
        @buy_or_sell_ - The stocks are bought or sold
        @trade_price_ - The price of the stocks
        '''
        return cls(stock_symbol_, Timestamp.now(), quantity_, buy_or_sell_, trade_price_)
    
    def valid(self):
        '''
        For validation
        '''
        return self['quantity'] > 0 and self['trade_price'] > 0
Exemple #3
0
 def test_adding_stocks(self, symbol_, last_dividend_, par_value_):
     c = CommonStock(symbol_, last_dividend_, par_value_)
     sm = StockManager()
     current_lenght = len(sm)  #singleton, it was not killed
     sm[symbol_] = c
     self.assertTrue(len(sm) == current_lenght + 1)
Exemple #4
0
 def test_stock_manager_singleton(self):
     sm1 = StockManager()
     sm2 = StockManager()
     self.assertEqual(sm1, sm2)
     StockManager._clear()
Exemple #5
0
    def test_adding_stocks(self, type_, value):
        StockManager._clear()
        sm = StockManager()

        sm.create_stocks(type_, **value)
        self.assertTrue(len(sm) == 1)
Exemple #6
0
# stock's header
HEADER = ['symbol_', 'type', 'last_dividend_', 'fixed_dividend_', 'par_value_']

# stocks
STOCKS = [['TEA', 'Common', 0, '', 100], ['POP', 'Common', 8, '', 100],
          ['ALE', 'Common', 23, '', 60], ['GIN', 'Preferred', 8, 0.02, 100],
          ['JOE', 'Common', 13, '', 250]]

# when the data acquisition is started
SHIFT = 60

NUMBER_OF_TRADES = 1000
QUANTITY_INTERVAL = (1000, 2000)
TRADE_PRICE_INTERVAL = (500, 1000)

_stock_manager = StockManager()
_stock_manager.create_stocks_header(HEADER, STOCKS)

BEGINING_OF_TRADES = Timestamp.now() - Timedelta(seconds=SHIFT)


def generate_trades():
    '''
    Generator of trades (attributes of trades)
    '''
    number_of_stocks = len(_stock_manager)
    list_of_stock_symbol = list(_stock_manager.keys())

    list_of_stocks = [
        list_of_stock_symbol[randint(0, number_of_stocks - 1)]
        for x in range(0, NUMBER_OF_TRADES)
 def setUpClass(cls):
     cls._sm = StockManager()
     cls._sm.create_stocks_header(HEADER, STOCKS)