Example #1
0
    def testCalendar(self):
        """
        Coverage test of Calendar module methods
        """

        with self.subTest(msg="calendarNames() test"):
            names = Calendars.calendarNames(
            )  # should at least return default name...
            self.assertTrue(isinstance(names, list) and len(names) > 0)
            print("calendarNames() values {}".format(names))

        name = None
        with self.subTest(msg="getDefaultName() test"):
            name = Calendars.getDefaultName()
            self.assertIsNotNone(name)  # just in case?

        with self.subTest(msg="calendar() construction"):
            junk = Calendars.calendar(
            )  # should return the default calendar instance?
            self.assertIsNotNone(junk)  # just in case?

        with self.subTest(msg="calendar(invalid name) construction"):
            self.assertRaises(RuntimeError, Calendars.calendar, "garbage_name")

        with self.subTest(msg="calendar(valid name) construction"):
            junk = Calendars.calendar(
                name)  # NB: this will fail if getDefaultName() does
            self.assertIsNotNone(junk)  # just in case?
Example #2
0
    def testAxisMethods(self):
        """
        Test suite for methods inherited from Axis - do these apply said methods to every axis? Seems silly.
        """

        figure = figure_wrapper.FigureWrapper()
        # How do I get it to select an axes?

        with self.subTest(msg="axisColor(string)"):
            figure = figure.axisColor("#000000")
        with self.subTest(msg="axisColor(Paint)"):
            figure = figure.axisColor(Plot.colorRGB(0, 0, 255))
        with self.subTest(msg="axisFormatPattern()"):
            figure = figure.axisFormat(
                "###,###.00")  # decimal formatting pattern
        with self.subTest(msg="axisLabel(string)"):
            figure = figure.axisLabel("axis")  # decimal formatting pattern
        with self.subTest(msg="axisLabelFont(string, string, int)"):
            figure = figure.axisLabelFont("Arial", "P", 11)

        with self.subTest(msg="businessTime()"):
            figure = figure.businessTime()

        with self.subTest(msg="businessTime(calendar)"):
            figure = figure.businessTime(Calendars.calendar())

        with self.subTest(msg="min(double)"):
            figure = figure.min(1.0)
        with self.subTest(msg="max(double)"):
            figure = figure.max(10.0)
        with self.subTest(msg="range(double, double)"):
            figure = figure.range(1.0, 10.0)
        with self.subTest(msg="ticks(double)"):
            figure = figure.ticks(1.0)
        with self.subTest(msg="ticks(double[])"):
            figure = figure.ticks([1.0, 2.5, 5.0, 7.5, 10.0])
        with self.subTest(msg="tickFont(string, string, int)"):
            figure = figure.ticksFont("Arial", "I", 9)
        with self.subTest(msg="ticksVisible(boolean)"):
            figure = figure.ticksVisible(True)
        with self.subTest(msg="tickLabelAngle(double)"):
            figure = figure.tickLabelAngle(45.0)  # I'm guessing degrees?
        with self.subTest(msg="minorTicks(int)"):
            figure = figure.minorTicks(2)
        with self.subTest(msg="minorTicksVisible(boolean)"):
            figure = figure.minorTicksVisible(True)

        with self.subTest(msg="log()"):
            figure = figure.log()
        # TODO: where would I get an AxisTransform object?
        # with self.subTest(msg="transform(AxisTransform)"):
        #     figure = figure.transform(what)

        with self.subTest(msg="invert()"):
            figure = figure.invert()
        with self.subTest(msg="invert(boolean)"):
            figure = figure.invert(False)

        del figure
Example #3
0
##  Deephaven - XY Series Plotting Notebook - Python
##  https://docs.deephaven.io/

from deephaven import Plot
# See print(sorted(dir())) or help('deephaven') for full namespace contents.

# note that we are constraining the data to NYSE business time
import deephaven.Calendars as Calendars
cal = Calendars.calendar("USNYSE")
trades = db.t("LearnIris", "StockTrades").where("Date=`2017-08-25`")
trades = trades.where("cal.isBusinessTime(ExchangeTimestamp)")

# ************* XY SERIES PLOTTING *************

# XY SERIES - SINGLE SERIES

t1 = db.t("LearnDeephaven", "StockTrades")\
    .where("Date=`2017-08-24`", "USym=`AAPL`")

PlotSingle = Plot.plot("AAPL", t1.where("USym = `AAPL`"), "Timestamp", "Last")\
    .xBusinessTime()\
    .show()

# XY SERIES - MULTIPLE SERIES

t2 = db.t("LearnDeephaven", "StockTrades")\
    .where("Date=`2017-08-24`", "USym in `INTC`,`CSCO`")

plotSharedAxis = Plot.plot("INTC", t2.where("USym = `INTC`"), "Timestamp", "Last")\
    .plot("CSCO", t2.where("USym = `CSCO`"), "Timestamp", "Last")\
    .xBusinessTime()\
Example #4
0
numSyms = 5
numDays = 3
buckets = 30

# Running average function
def rAvg(vals):
    arr = jpy.array('double', vals.size())
    avg = 0.0

    for i in range(vals.size()):
        arr[i] = (i*arr[i-1] + vals.get(i))/(i+1) if i > 0 else vals.get(i)

    return arr

import deephaven.Calendars as Calendars
cal = Calendars.calendar('USNYSE')
cutoffDate = cal.previousBusinessDay(cal.currentDay(), numDays - 1)

# Get trade data (filter out exchange aggregate)
trades = db.i("FeedOS", "EquityTradeL1")\
    .where("Date >= cutoffDate")\
    .where("LocalCodeStr not in `SPY`")

# Bin by minute and rename columns
countAndVolumeData = trades.view("TimeBin = upperBin(Timestamp, buckets*MINUTE)", 
    "Sym = LocalCodeStr", "TradeCount = 1", "Shares = (int) Size",
    "Price", "Dollars = (int) (Size * Price)")\
    .lastBy("TimeBin", "Sym")

# Get distinct syms
syms = countAndVolumeData.selectDistinct("Sym").head(numSyms)