Exemple #1
0
    def testResampleNinjaTraderDay(self):
        common.init_temp_path()

        # Resample.
        feed = ninjatraderfeed.Feed(ninjatraderfeed.Frequency.MINUTE)
        feed.addBarsFromCSV("spy", common.get_data_file_path("nt-spy-minute-2011.csv"))
        resampledBarDS = resampled.ResampledBarDataSeries(feed["spy"], bar.Frequency.DAY)
        resampledFile = os.path.join(common.get_temp_path(), "day-nt-spy-minute-2011.csv")
        resample.resample_to_csv(feed, bar.Frequency.DAY, resampledFile)
        resampledBarDS.pushLast()  # Need to manually push the last stot since time didn't change.

        # Load the resampled file.
        feed = csvfeed.GenericBarFeed(bar.Frequency.DAY)
        feed.addBarsFromCSV("spy", resampledFile, marketsession.USEquities.getTimezone())
        feed.loadAll()

        self.assertEqual(len(feed["spy"]), 25)
        self.assertEqual(
            feed["spy"][0].getDateTime(),
            dt.localize(datetime.datetime(2011, 1, 3), marketsession.USEquities.getTimezone()),
        )
        self.assertEqual(
            feed["spy"][-1].getDateTime(),
            dt.localize(datetime.datetime(2011, 2, 1), marketsession.USEquities.getTimezone()),
        )

        self.assertEqual(len(resampledBarDS), len(feed["spy"]))
        self.assertEqual(resampledBarDS[0].getDateTime(), dt.as_utc(datetime.datetime(2011, 1, 3)))
        self.assertEqual(resampledBarDS[-1].getDateTime(), dt.as_utc(datetime.datetime(2011, 2, 1)))
    def testResampleNinjaTraderHour(self):
        common.init_temp_path()

        # Resample.
        feed = ninjatraderfeed.Feed(ninjatraderfeed.Frequency.MINUTE)
        feed.addBarsFromCSV("spy", common.get_data_file_path("nt-spy-minute-2011.csv"))
        resampledBarDS = resampled_ds.ResampledBarDataSeries(feed["spy"], bar.Frequency.HOUR)
        resampledFile = os.path.join(common.get_temp_path(), "hour-nt-spy-minute-2011.csv")
        resample.resample_to_csv(feed, bar.Frequency.HOUR, resampledFile)
        resampledBarDS.pushLast()  # Need to manually push the last stot since time didn't change.

        # Load the resampled file.
        feed = csvfeed.GenericBarFeed(bar.Frequency.HOUR, marketsession.USEquities.getTimezone())
        feed.addBarsFromCSV("spy", resampledFile)
        feed.loadAll()

        self.assertEqual(len(feed["spy"]), 340)
        self.assertEqual(feed["spy"][0].getDateTime(), dt.localize(datetime.datetime(2011, 1, 3, 9), marketsession.USEquities.getTimezone()))
        self.assertEqual(feed["spy"][-1].getDateTime(), dt.localize(datetime.datetime(2011, 2, 1, 1), marketsession.USEquities.getTimezone()))
        self.assertEqual(feed["spy"][0].getOpen(), 126.35)
        self.assertEqual(feed["spy"][0].getHigh(), 126.45)
        self.assertEqual(feed["spy"][0].getLow(), 126.3)
        self.assertEqual(feed["spy"][0].getClose(), 126.4)
        self.assertEqual(feed["spy"][0].getVolume(), 3397.0)
        self.assertEqual(feed["spy"][0].getAdjClose(), None)

        self.assertEqual(len(resampledBarDS), len(feed["spy"]))
        self.assertEqual(resampledBarDS[0].getDateTime(), dt.as_utc(datetime.datetime(2011, 1, 3, 9)))
        self.assertEqual(resampledBarDS[-1].getDateTime(), dt.as_utc(datetime.datetime(2011, 2, 1, 1)))
    def testBaseFeedInterface(self):
        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "trades-mgtox-usd-2013-01-01.csv")
        tools.download_trades_by_day("usd", 2013, 1, 1, path)

        bf = barfeed.CSVTradeFeed()
        bf.addBarsFromCSV(path)
        feed_test.tstBaseFeedInterface(self, bf)
Exemple #4
0
    def testBaseFeedInterface(self):
        common.init_temp_path()
        path = os.path.join(common.get_temp_path(),
                            "trades-mgtox-usd-2013-01-01.csv")
        tools.download_trades_by_day("usd", 2013, 1, 1, path)

        bf = barfeed.CSVTradeFeed()
        bf.addBarsFromCSV(path)
        feed_test.tstBaseFeedInterface(self, bf)
Exemple #5
0
    def testDownloadAndParseDaily(self):
        instrument = "orcl"

        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "orcl-2010.csv")
        googlefinance.download_daily_bars(instrument, 2010, path)
        bf = googlefeed.Feed()
        bf.addBarsFromCSV(instrument, path)
        bf.loadAll()
        self.assertEqual(bf[instrument][-1].getOpen(), 31.22)
        self.assertEqual(bf[instrument][-1].getClose(), 31.30)
Exemple #6
0
    def testDownloadAndParseDaily(self):
        instrument = "orcl"

        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "orcl-2010.csv")
        yahoofinance.download_daily_bars(instrument, 2010, path)
        bf = yahoofeed.Feed()
        bf.addBarsFromCSV(instrument, path)
        bf.loadAll()
        self.assertEqual(bf[instrument][-1].getOpen(), 31.22)
        self.assertEqual(bf[instrument][-1].getClose(), 31.30)
    def testDownloadAndParseWeekly(self):
        instrument = "aapl"

        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "aapl-weekly-2013.csv")
        yahoofinance.download_weekly_bars(instrument, 2013, path)
        bf = yahoofeed.Feed(frequency=bar.Frequency.WEEK)
        bf.addBarsFromCSV(instrument, path)
        bf.loadAll()
        self.assertEqual(round(bf[instrument][-1].getOpen(), 2), 557.46)
        self.assertEqual(round(bf[instrument][-1].getHigh(), 2), 561.28)
        self.assertEqual(round(bf[instrument][-1].getLow(), 2), 540.43)
        self.assertEqual(round(bf[instrument][-1].getClose(), 2), 540.98)
        self.assertTrue(bf[instrument][-1].getVolume() in (9852500, 9855900, 68991600))
    def testDownloadAndParseDaily(self):
        instrument = "ORCL"

        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "quandl-daily-orcl-2010.csv")
        quandl.download_daily_bars("WIKI", instrument, 2010, path, auth_token)
        bf = quandlfeed.Feed()
        bf.addBarsFromCSV(instrument, path)
        bf.loadAll()
        self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31))
        self.assertEquals(bf[instrument][-1].getOpen(), 31.22)
        self.assertEquals(bf[instrument][-1].getHigh(), 31.33)
        self.assertEquals(bf[instrument][-1].getLow(), 30.93)
        self.assertEquals(bf[instrument][-1].getClose(), 31.3)
        self.assertEquals(bf[instrument][-1].getVolume(), 11716300)
        self.assertEquals(bf[instrument][-1].getAdjClose(), 30.23179912467581)
    def testDownloadAndParse(self):
        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "trades-mgtox-usd-2013-01-01.csv")
        tools.download_trades_by_day("usd", 2013, 1, 1, path)

        bf = barfeed.CSVTradeFeed()
        bf.addBarsFromCSV(path)
        bf.loadAll()
        ds = bf["BTC"]
        self.assertTrue(len(ds) > 0)
        self.assertEqual(ds[-1].getOpen(), ds[-1].getHigh())
        self.assertEqual(ds[-1].getHigh(), ds[-1].getLow())
        self.assertEqual(ds[-1].getLow(), ds[-1].getClose())
        self.assertEqual(ds[-1].getClose(), 13.30413)
        self.assertEqual(ds[-1].getVolume(), 0.01)
        self.assertEqual(ds[-1].getTradeType(), "ask")
        self.assertEqual(ds[-1].getDateTime().date(), datetime.date(2013, 1, 1))
    def testDownloadAndParseDailyNoAdjClose(self):
        instrument = "ORCL"

        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "quandl-daily-orcl-2013.csv")
        quandl.download_daily_bars("GOOG", "NASDAQ_ORCL", 2013, path, auth_token)
        bf = quandlfeed.Feed()
        bf.setNoAdjClose()
        bf.addBarsFromCSV(instrument, path)
        bf.loadAll()
        self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2013, 12, 31))
        self.assertEquals(bf[instrument][-1].getOpen(), 37.94)
        self.assertEquals(bf[instrument][-1].getHigh(), 38.34)
        self.assertEquals(bf[instrument][-1].getLow(), 37.88)
        self.assertEquals(bf[instrument][-1].getClose(), 38.26)
        self.assertEquals(bf[instrument][-1].getVolume(), 11747517)
        self.assertEquals(bf[instrument][-1].getAdjClose(), None)
Exemple #11
0
    def testDownloadAndParse(self):
        common.init_temp_path()
        path = os.path.join(common.get_temp_path(),
                            "trades-mgtox-usd-2013-01-01.csv")
        tools.download_trades_by_day("usd", 2013, 1, 1, path)

        bf = barfeed.CSVTradeFeed()
        bf.addBarsFromCSV(path)
        bf.loadAll()
        ds = bf["BTC"]
        self.assertTrue(len(ds) > 0)
        self.assertEqual(ds[-1].getOpen(), ds[-1].getHigh())
        self.assertEqual(ds[-1].getHigh(), ds[-1].getLow())
        self.assertEqual(ds[-1].getLow(), ds[-1].getClose())
        self.assertEqual(ds[-1].getClose(), 13.30413)
        self.assertEqual(ds[-1].getVolume(), 0.01)
        self.assertEqual(ds[-1].getTradeType(), "ask")
        self.assertEqual(ds[-1].getDateTime().date(),
                         datetime.date(2013, 1, 1))
    def testDownloadAndParseWeekly(self):
        instrument = "AAPL"

        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "quandl-aapl-weekly-2010.csv")
        quandl.download_weekly_bars("WIKI", instrument, 2010, path, auth_token)
        bf = quandlfeed.Feed(frequency=bar.Frequency.WEEK)
        bf.addBarsFromCSV(instrument, path)
        bf.loadAll()
        self.assertEquals(bf[instrument][0].getDateTime(), datetime.datetime(2010, 1, 3))
        self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 26))
        self.assertEquals(bf[instrument][-1].getOpen(), 325.0)
        self.assertEquals(bf[instrument][-1].getHigh(), 325.15)
        self.assertEquals(bf[instrument][-1].getLow(), 323.17)
        self.assertEquals(bf[instrument][-1].getClose(), 323.6)
        self.assertEquals(bf[instrument][-1].getVolume(), 7969900)
        # Not checking against a specific value since this is going to change
        # as time passes by.
        self.assertNotEquals(bf[instrument][-1].getAdjClose(), None)
Exemple #13
0
    def testResampleNinjaTraderHour(self):
        common.init_temp_path()

        # Resample.
        feed = ninjatraderfeed.Feed(ninjatraderfeed.Frequency.MINUTE)
        feed.addBarsFromCSV(
            "spy", common.get_data_file_path("nt-spy-minute-2011.csv"))
        resampledBarDS = resampled_ds.ResampledBarDataSeries(
            feed["spy"], bar.Frequency.HOUR)
        resampledFile = os.path.join(common.get_temp_path(),
                                     "hour-nt-spy-minute-2011.csv")
        resample.resample_to_csv(feed, bar.Frequency.HOUR, resampledFile)
        resampledBarDS.pushLast(
        )  # Need to manually push the last stot since time didn't change.

        # Load the resampled file.
        feed = csvfeed.GenericBarFeed(bar.Frequency.HOUR,
                                      marketsession.USEquities.getTimezone())
        feed.addBarsFromCSV("spy", resampledFile)
        feed.loadAll()

        self.assertEqual(len(feed["spy"]), 340)
        self.assertEqual(
            feed["spy"][0].getDateTime(),
            dt.localize(datetime.datetime(2011, 1, 3, 9),
                        marketsession.USEquities.getTimezone()))
        self.assertEqual(
            feed["spy"][-1].getDateTime(),
            dt.localize(datetime.datetime(2011, 2, 1, 1),
                        marketsession.USEquities.getTimezone()))
        self.assertEqual(feed["spy"][0].getOpen(), 126.35)
        self.assertEqual(feed["spy"][0].getHigh(), 126.45)
        self.assertEqual(feed["spy"][0].getLow(), 126.3)
        self.assertEqual(feed["spy"][0].getClose(), 126.4)
        self.assertEqual(feed["spy"][0].getVolume(), 3397.0)
        self.assertEqual(feed["spy"][0].getAdjClose(), None)

        self.assertEqual(len(resampledBarDS), len(feed["spy"]))
        self.assertEqual(resampledBarDS[0].getDateTime(),
                         dt.as_utc(datetime.datetime(2011, 1, 3, 9)))
        self.assertEqual(resampledBarDS[-1].getDateTime(),
                         dt.as_utc(datetime.datetime(2011, 2, 1, 1)))
Exemple #14
0
    def testDownloadAndParseDaily_UseAdjClose(self):
        instrument = "ORCL"

        common.init_temp_path()
        path = os.path.join(common.get_temp_path(), "quandl-daily-orcl-2010.csv")
        quandl.download_daily_bars("WIKI", instrument, 2010, path, auth_token)
        bf = quandlfeed.Feed()
        bf.addBarsFromCSV(instrument, path)
        # Need to setUseAdjustedValues(True) after loading the file because we
        # can't tell in advance if adjusted values are there or not.
        bf.setUseAdjustedValues(True)
        bf.loadAll()
        self.assertEquals(bf[instrument][-1].getDateTime(), datetime.datetime(2010, 12, 31))
        self.assertEquals(bf[instrument][-1].getOpen(), 31.22)
        self.assertEquals(bf[instrument][-1].getHigh(), 31.33)
        self.assertEquals(bf[instrument][-1].getLow(), 30.93)
        self.assertEquals(bf[instrument][-1].getClose(), 31.3)
        self.assertEquals(bf[instrument][-1].getVolume(), 11716300)
        self.assertEquals(bf[instrument][-1].getAdjClose(), 30.23179912467581)
        self.assertEquals(bf[instrument][-1].getPrice(), 30.23179912467581)
Exemple #15
0
    def testResampleNinjaTraderDay(self):
        common.init_temp_path()

        # Resample.
        feed = ninjatraderfeed.Feed(ninjatraderfeed.Frequency.MINUTE)
        feed.addBarsFromCSV(
            "spy", common.get_data_file_path("nt-spy-minute-2011.csv"))
        resampledBarDS = resampled_ds.ResampledBarDataSeries(
            feed["spy"], bar.Frequency.DAY)
        resampledFile = os.path.join(common.get_temp_path(),
                                     "day-nt-spy-minute-2011.csv")
        resample.resample_to_csv(feed, bar.Frequency.DAY, resampledFile)
        resampledBarDS.pushLast(
        )  # Need to manually push the last stot since time didn't change.

        # Load the resampled file.
        feed = csvfeed.GenericBarFeed(bar.Frequency.DAY)
        feed.addBarsFromCSV("spy", resampledFile,
                            marketsession.USEquities.getTimezone())
        feed.loadAll()

        self.assertEqual(len(feed["spy"]), 25)
        self.assertEqual(
            feed["spy"][0].getDateTime(),
            dt.localize(datetime.datetime(2011, 1, 3),
                        marketsession.USEquities.getTimezone()))
        self.assertEqual(
            feed["spy"][-1].getDateTime(),
            dt.localize(datetime.datetime(2011, 2, 1),
                        marketsession.USEquities.getTimezone()))

        self.assertEqual(len(resampledBarDS), len(feed["spy"]))
        self.assertEqual(resampledBarDS[0].getDateTime(),
                         dt.as_utc(datetime.datetime(2011, 1, 3)))
        self.assertEqual(resampledBarDS[-1].getDateTime(),
                         dt.as_utc(datetime.datetime(2011, 2, 1)))