def getSymbolDataInstanceForDateDictionaryDataPoints(symbol_key_list_tuple): """ :param list symbol_data_list: This is a list whose elements are tuples of the form (Key, Value) where each Key is a stock symbol and each Value is a list of comma-delimited strings, each representing a date's worth of stock data :return: tuple (key, value)|None: The returned key is a stock's symbol while the returned value is an object of type SymbolData. The symbol data object will contain the data which was contained in the list of comma-delimited strings. However if the list is empty, a value of None will be returned """ # Index 1 of the symbol_key_list_tuple contains the list of comma-delimited strings symbol_data_list = symbol_key_list_tuple[1] if len(symbol_data_list) < 1: # If the stock had no data points within the time-frame specified by dateIntervalDictionary, return a # None value return SymbolData(None) # Index 0 of the symbol_key_list_tuple contains the stock symbol symbol_code = symbol_key_list_tuple[0] # Instantiate the SymbolData object symbolDataInstance = SymbolData(symbol_code) # Iterate over the strings of stock-date data in the list for symbol_date_data in symbol_data_list: # We have an eventual data point which will operate on the stock's close price and percentage delta, # so record those values if this symbol_date_data string is specific to today's date date = symbol_date_data[StockRdd.DATE_INDEX] if date == today_date: symbolDataInstance.setTodayPrice(symbol_date_data[StockRdd.CLOSE_PRICE_INDEX]) symbolDataInstance.setTodayDeltaPercentage(symbol_date_data[StockRdd.DELTA_PERCENTAGE_INDEX]) # Get all of the time spans which the date for this row belongs to date_interval_codes_for_date = dateIntervalDictionary.getIntervalCodesByDate(date) if not(date_interval_codes_for_date is None): for date_interval_code in date_interval_codes_for_date: # Add a value row for each span that this date belongs to symbolDataInstance.addSpanValueByCode(date_interval_code, date_interval_code, symbol_date_data[StockRdd.CLOSE_PRICE_INDEX], symbol_date_data[StockRdd.OPEN_PRICE_INDEX], symbol_date_data[StockRdd.HIGH_PRICE_INDEX], symbol_date_data[StockRdd.LOW_PRICE_INDEX], symbol_date_data[StockRdd.DELTA_INDEX], symbol_date_data[StockRdd.DELTA_PERCENTAGE_INDEX]) # Return a tuple comprised of the stock symbol and the SymbolData object return (symbol_code, symbolDataInstance)
def test_getTodayPrice(self): expected_today_price = 12.4 symbolDataTest = SymbolData('A') symbolDataTest.setTodayPrice(expected_today_price) test_today_price = symbolDataTest.getTodayPrice() self.assertEqual(expected_today_price, test_today_price, 'A SymbolData object did not return the expected value when calling getTodayPrice(), expected {0} but returned {1}'.format(expected_today_price, test_today_price))