Introducing Deephaven’s new calendar API | Deephaven

Introducing Deephaven's new calendar API | Deephaven


Deephaven 0.32.0 introduced a number of new features, as well as improvements to old ones. Key features of the overhauled calendar API include:

  • An updated Java calendar API that boosts performance in table operations.
  • A streamlined Python API designed to minimize the chances of calling Python from query strings.
  • Simple and intuitive naming conventions for ease of use.
  • Support for user-defined calendars.
  • Conversion between Deephaven and NumPy calendar formats.

The new Python API is designed to be minimal, and facilitate the use of the Java API in query strings. The new calendar class provides the following methods:

Method Description
add_calendar Adds a new business calendar to the set of available options.
calendar Retrieves the calendar with the given name.
calendar_name Returns the name of the default calendar.
calendar_names Returns the names of all available calendars.
remove_calendar Removes the given business calendar from the set of available options.
set_calendar Sets the default calendar.

Deephaven provides three example calendars: USBANK_EXAMPLE, USNYSE_EXAMPLE, and UTC.

from deephaven.calendar import calendar_names
print(calendar_names())

These example calendars are intended for learning, demonstration, and testing purposes – not production. Deephaven makes no guarantees about the accuracy of these calendars.

Deephaven now allows users to create their own business calendars. First, create an XML file for the calendar.

To view the example calendar’s XML format, click here.
<calendar>
<name>TestCalendar_2024</name>
<timeZone>America/New_York</timeZone>
<language>en</language>
<country>US</country>
<firstValidDate>2024-01-01</firstValidDate>
<lastValidDate>2024-12-31</lastValidDate>
<description>
Test calendar for the year 2024.
This calendar uses two business periods instead of one.
The periods are separated by a one hour lunch break.
This calendar file defines standard business hours, weekends, and holidays.
</description>
<default>
<businessTime><open>08:00</open><close>12:00</close><open>13:00</open><close>17:00</close></businessTime>
<weekend>Saturday</weekend>
<weekend>Sunday</weekend>
</default>
<holiday>
<date>2024-01-01</date>
</holiday>
<holiday>
<date>2024-01-15</date>
</holiday>
<holiday>
<date>2024-02-19</date>
</holiday>
<holiday>
<date>2024-03-29</date>
</holiday>
<holiday>
<date>2024-04-01</date>
<businessTime><open>08:00</open><close>12:00</close></businessTime>
</holiday>
<holiday>
<date>2024-05-27</date>
</holiday>
<holiday>
<date>2024-07-04</date>
</holiday>
<holiday>
<date>2024-09-02</date>
</holiday>
<holiday>
<date>2024-10-31</date>
<businessTime><open>08:00</open><close>12:00</close></businessTime>
</holiday>
<holiday>
<date>2024-11-28</date>
</holiday>
<holiday>
<date>2024-11-29</date>
</holiday>
<holiday>
<date>2024-12-25</date>
</holiday>
<holiday>
<date>2024-12-26</date>
</holiday>
</calendar>

Now add it to the list of available calendars:

from deephaven.calendar import add_calendar, calendar

add_calendar("/data/examples/Calendar/TestCalendar_2024.calendar")

test_cal_2024 = calendar("TestCalendar_2024")

Deephaven’s numpy module has been updated with the to_np_busdaycalendar method, which converts a Deephaven calendar to a numpy business calendar:

from deephaven.calendar import calendar
from deephaven.numpy import to_np_busdaycalendar

cal = calendar()

result = to_np_busdaycalendar(cal)

print(type(result))

Our Community documentation has all of the resources you need to become a Deephaven power user. Our Slack community continues to grow, and we’d love to have you join us! If you have any questions, comments, or suggestions, please reach out to us there.



Source link
lol

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.