Beispiel #1
0
    def testReset(self):
        feed = csvfeed.Feed("Date", "%Y-%m-%d")
        feed.addValuesFromCSV(
            common.get_data_file_path("orcl-2000-yahoofinance.csv"))

        disp = dispatcher.Dispatcher()
        disp.addSubject(feed)
        disp.run()

        keys = feed.getKeys()
        key = keys[0]
        values = feed[key]

        feed.reset()
        disp = dispatcher.Dispatcher()
        disp.addSubject(feed)
        disp.run()

        reloadedKeys = feed.getKeys()
        reloadedValues = feed[key]

        self.assertEqual(keys.sort(), reloadedKeys.sort())
        self.assertNotEqual(values, reloadedValues)
        self.assertEqual(len(values), len(reloadedValues))
        for i in range(len(values)):
            self.assertEqual(values[i], reloadedValues[i])
Beispiel #2
0
    def testFeedWithQuandl(self):
        class RowFilter(csvfeed.RowFilter):
            def includeRow(self, dateTime, values):
                return dateTime.year == 2013

        feed = csvfeed.Feed("Date",
                            "%Y-%m-%d",
                            maxLen=40,
                            timezone=marketsession.USEquities.timezone)
        feed.setRowFilter(RowFilter())
        feed.setTimeDelta(datetime.timedelta(hours=23, minutes=59, seconds=59))
        feed.addValuesFromCSV(
            os.path.join("samples", "data", "quandl_gold_2.csv"))

        for col in ["USD", "GBP", "EUR"]:
            self.assertEqual(len(feed[col]), 0)

        disp = dispatcher.Dispatcher()
        disp.addSubject(feed)
        disp.run()

        for col in ["USD", "GBP", "EUR"]:
            self.assertEqual(len(feed[col]), 39)

        self.assertEqual(feed["USD"][-1], 1333.0)
        self.assertEqual(feed["GBP"][-1], 831.203)
        self.assertEqual(feed["EUR"][-1], 986.75)
        self.assertFalse(dt.datetime_is_naive(feed["USD"].getDateTimes()[-1]))
        self.assertEqual(
            feed["USD"].getDateTimes()[-1],
            dt.localize(datetime.datetime(2013, 9, 29, 23, 59, 59),
                        marketsession.USEquities.timezone))
Beispiel #3
0
def main(plot):
    instruments = ["GORO"]

    # Download GORO bars using WIKI source code.
    feed = quandl.build_feed("WIKI", instruments, 2006, 2012, ".")

    # Load Quandl CSV downloaded from http://www.quandl.com/OFDP-Open-Financial-Data-Project/GOLD_2-LBMA-Gold-Price-London-Fixings-P-M
    quandlFeed = csvfeed.Feed("Date", "%Y-%m-%d")
    quandlFeed.setDateRange(datetime.datetime(2006, 1, 1),
                            datetime.datetime(2012, 12, 31))
    quandlFeed.addValuesFromCSV("quandl_gold_2.csv")

    myStrategy = MyStrategy(feed, quandlFeed, instruments[0])

    if plot:
        plt = plotter.StrategyPlotter(myStrategy, True, False, False)
        plt.getOrCreateSubplot("quandl").addDataSeries("USD",
                                                       quandlFeed["USD"])
        plt.getOrCreateSubplot("quandl").addDataSeries("EUR",
                                                       quandlFeed["EUR"])
        plt.getOrCreateSubplot("quandl").addDataSeries("GBP",
                                                       quandlFeed["GBP"])

    myStrategy.run()

    if plot:
        plt.plot()
Beispiel #4
0
    def testFeedWithBars(self):
        feed = csvfeed.Feed("Date", "%Y-%m-%d")
        feed.addValuesFromCSV(
            common.get_data_file_path("orcl-2000-yahoofinance.csv"))

        self.assertEqual(len(feed.getKeys()), 6)
        for col in ["Open", "High", "Low", "Close", "Volume", "Adj Close"]:
            self.assertEqual(len(feed[col]), 0)

        disp = dispatcher.Dispatcher()
        disp.addSubject(feed)
        disp.run()

        for col in ["Open", "High", "Low", "Close", "Volume", "Adj Close"]:
            self.assertEqual(len(feed[col]), 252)

        self.assertEqual(feed["Open"][-1], 30.87)
        self.assertEqual(feed["High"][-1], 31.31)
        self.assertEqual(feed["Low"][-1], 28.69)
        self.assertEqual(feed["Close"][-1], 29.06)
        self.assertEqual(feed["Volume"][-1], 31655500)
        self.assertEqual(feed["Adj Close"][-1], 28.41)
Beispiel #5
0
 def testBaseFeedInterface(self):
     feed = csvfeed.Feed("Date", "%Y-%m-%d")
     feed.addValuesFromCSV(
         common.get_data_file_path("orcl-2000-yahoofinance.csv"))
     feed_test.tstBaseFeedInterface(self, feed)
Beispiel #6
0
from __future__ import print_function

from quantworks.feed import csvfeed

feed = csvfeed.Feed("Date", "%Y-%m-%d")
feed.addValuesFromCSV("quandl_gold_2.csv")
for dateTime, value in feed:
    print(dateTime, value)