コード例 #1
0
    def test1(self):
        
        dirc = '/Users/Zibin/NYU/twriter.gz'

        w = TradeWriter(dirc, 1) # Create a .gz file on directory
        
        r = TAQTradesReader('/Users/Zibin/Documents/R/trades/20070620/NVDA_trades.binRT') # Read a file
        # Using tested readers, test for expected values
        baseTS = r.getSecsFromEpocToMidn() * 1000       
        ts = baseTS + r.getMillisFromMidn(0)
 
        s = r.getSize(0) 
        p = r.getPrice(0)
        
        w.writer(r,1,1) # write to the file
        
        b = BinReader(dirc, '>QIIf', 100) # use binreader to read
        ts0, _, size0, p0 = b.next()
        b.close()
        
        self.assertEquals( ts0, ts ) # Check if time stamps are equal
        self.assertEquals( size0, s ) # Check if numbers of shares are equal
        self.assertAlmostEquals( p0, p ) # Check if prices are equal
コード例 #2
0
    def test1(self):
        # Stocks and trades
        s_p500 = '/media/louis/DATA/documents/cours/NYU/SPRING_18/ATQS/HK1/s_p500.xlsx'
        stackedTrades = np.array(
            [['20070620', 34241000, 106.5, 85200.0],
             ['20070621', 57596000, 106.61000061035156, 500.0],
             ['20070621', 57596000, 106.61000061035156, 200.0],
             ['20070621', 57597000, 106.5999984741211, 200.0],
             ['20070621', 57597000, 106.5999984741211, 200.0],
             ['20070621', 57597000, 106.5999984741211, 200.0]])
        stackedQuotes = np.array(
            [['20070620', 34241000, 106.5, 85200.0, 106.1, 8200.0],
             ['20070621', 57597000, 106.5, 85200.0, 106.1, 800.0],
             ['20070621', 57597000, 106.5, 85200.0, 106.1, 800.0],
             ['20070621', 57597000, 106.5, 85200.0, 106.1, 800.0],
             ['20070621', 57597000, 106.5, 85200.0, 106.1, 800.0]])

        # Directories where to store
        filepathadj = '/media/louis/DATA/documents/cours/NYU/SPRING_18/ATQS/HK1/adj/'
        filepathcln = '/media/louis/DATA/documents/cours/NYU/SPRING_18/ATQS/HK1/cln/'

        # Multipliers map
        multmap = AdjustingHashmap(s_p500)

        # Write after reading and adjusting
        adjuster = TAQAdjust(stackedQuotes, stackedTrades, 'IBM', multmap)
        adjuster.setPriceMult("20070621", 2.0)
        adjuster.setVolMult("20070621", 4.0)
        adjuster.adjustQuote()
        adjuster.adjustTrade()
        adjuster.storeAdjustedQuotes(filepathadj)
        adjuster.storeAdjustedTrades(filepathadj)

        # Write after reading and cleaning
        cleaner = TAQCleaner(stackedQuotes, stackedTrades, 'IBM')
        stackedQuotes = stackedQuotes[cleaner.cleanQuotesIndices() == True, :]
        stackedTrades = stackedTrades[cleaner.cleanTradesIndices() == True, :]
        cleaner.storeCleanedQuotes(filepathcln)
        cleaner.storeCleanedTrades(filepathcln)

        # Read results
        readerclnQ = TAQQuotesReader(
            '/media/louis/DATA/documents/cours/NYU/SPRING_18/ATQS/HK1/cln/quotes/20070620/IBM_quotes.binRQ'
        )
        readerclnT = TAQTradesReader(
            '/media/louis/DATA/documents/cours/NYU/SPRING_18/ATQS/HK1/cln/trades/20070620/IBM_trades.binRT'
        )
        readeradjQ = TAQQuotesReader(
            '/media/louis/DATA/documents/cours/NYU/SPRING_18/ATQS/HK1/adj/quotes/20070620/IBM_quotes.binRQ'
        )
        readeradjT = TAQTradesReader(
            '/media/louis/DATA/documents/cours/NYU/SPRING_18/ATQS/HK1/adj/trades/20070620/IBM_trades.binRT'
        )

        # Using previously tested readers, test for expected values
        self.assertEquals(readerclnQ.getN(), 5)
        self.assertEquals(readerclnQ.getSecsFromEpocToMidn(), 0)
        self.assertEquals(readerclnQ.getMillisFromMidn(readerclnQ.getN() - 1),
                          57597000)
        self.assertEquals(readerclnQ.getBidSize(readerclnQ.getN() - 1), 21300)
        self.assertEquals(readerclnQ.getAskSize(readerclnQ.getN() - 1), 200)
        self.assertAlmostEquals(readerclnQ.getAskPrice(readerclnQ.getN() - 1),
                                53.0499, 3)
        self.assertAlmostEquals(readerclnQ.getBidPrice(readerclnQ.getN() - 1),
                                53.25, 3)

        # Using previously tested readers, test for expected values
        self.assertEquals(readeradjQ.getN(), 5)
        self.assertEquals(readeradjQ.getSecsFromEpocToMidn(), 0)
        self.assertEquals(readeradjQ.getMillisFromMidn(readeradjQ.getN() - 1),
                          57597000)
        self.assertEquals(readeradjQ.getBidSize(readeradjQ.getN() - 1), 21300)
        self.assertEquals(readeradjQ.getAskSize(readeradjQ.getN() - 1), 200)
        self.assertAlmostEquals(readeradjQ.getAskPrice(readeradjQ.getN() - 1),
                                53.0499, 3)
        self.assertAlmostEquals(readeradjQ.getBidPrice(readeradjQ.getN() - 1),
                                53.25, 3)

        # Using previously tested readers, test for expected values
        self.assertEquals(readerclnT.getN(), 6)
        self.assertEquals(readerclnT.getSecsFromEpocToMidn(), 0)
        self.assertEquals(readerclnT.getMillisFromMidn(readerclnT.getN() - 1),
                          57597000)
        self.assertEquals(readerclnT.getSize(readerclnT.getN() - 1), 50)
        self.assertAlmostEquals(readerclnT.getPrice(readerclnT.getN() - 1),
                                53.29999, 3)

        # Using previously tested readers, test for expected values
        self.assertEquals(readeradjT.getN(), 6)
        self.assertEquals(readeradjT.getSecsFromEpocToMidn(), 0)
        self.assertEquals(readeradjT.getMillisFromMidn(readeradjT.getN() - 1),
                          57597000)
        self.assertEquals(readeradjT.getSize(readeradjT.getN() - 1), 50)
        self.assertAlmostEquals(readerclnT.getPrice(readeradjT.getN() - 1),
                                53.29999, 3)