def testGetOvernightTrades(self): ''' The only way to automate this is to just figure all the same data and compare it. ''' indir = "data/" for infile in self.infiles: inpathfile = os.path.join(indir, infile) os.path.exists(inpathfile) dframe = pd.read_csv(inpathfile) sl = list() # Total up the shares found for each unique ticker/account to create our own # list of overnight trades (unbalanced trades are overnight) Then verify its # the same list as that from getOvernightTrades for symbol in dframe['Symb'].unique(): # print(symbol) df = dframe[dframe['Symb'] == symbol] for account in df['Account'].unique(): df1 = df[df['Account'] == account] buy = 0 for dummy, row in df1.iterrows(): # print(row['Side'], row['Qty']) if row['Side'].startswith('S'): buy = buy - row['Qty'] elif row['Side'].startswith('B'): buy = buy + row['Qty'] else: print('error', 'Side is ', row['Side']) if buy != 0: # Create the same data format used in getOvernightTrades sl.append({ 'ticker': symbol, 'shares': buy, 'before': 0, 'after': 0, 'acct': account }) idf = InputDataFrame() dframe = idf.mkShortsNegative(dframe) st = idf.getOvernightTrades(dframe) self.assertEqual(len(sl), len(st)) for trade in sl: self.assertTrue(trade in st)
def test_MkShortNegative(self): ''' Test the method Statement_DAS.mkShortsNegative ''' rc = ReqCol() for dummy in range(random.randint(2, 10)): side, mult, shares = getTestSet(random.randint(4, 20)) testSet = list(zip(side, shares)) apd = pd.DataFrame(testSet, columns=[rc.side, rc.shares]) for i in range(len(side)): # self.assertEqual(apd[rc.shares][i], shares[i]) self.assertEqual(apd[rc.shares][i], shares[i]) idf = InputDataFrame() apd = idf.mkShortsNegative(apd) for i in range(len(side)): self.assertEqual(apd[rc.shares][i], shares[i] * mult[i])