Skip to main content

Creating Timeseries

· 6 min read
Colin Hartley

Easily Create Custom Timeseries

In this blog, we show examples of the different types of timeseries which you can create in OpenDataDSL.

What are timeseries?

Timeseries are a collection of observations recorded at a point in time. They have many uses including but not limited to:

  • Financial pricing and trading information
  • Fundamental and statistical information
  • Metrics collected from IOT devices
  • Power plant outage information

Timeseries generally are associated with a calendar which normalises the dates/times when observations are recorded. If a timeseries does not have a calendar, we call it a sparse timeseries.

OpenDataDSL Timeseries

There are 4 different types of timeseries in OpenDataDSL:

  • Regular timeseries
  • Smart timeseries
  • Event timeseries
  • Curve tenor timeseries

Regular timeseries

A regular timeseries is a self-contained timeseries with actual stored values, this is the most common timeseries for low-frequency (daily, monthly etc.) real data collected and stored in the database.

An example of creating a regular timeseries

This example shows you how to create regular timeseries starting on the 1st of November using a business (Mon-Fri) calendar. We add an array of values which represent the values for the business days from the 1st of November - the calendar determines which days they represent.

// Create 2 regular timeseries starting on the 1st of November 
// using a business (Mon-Fri) calendar
ts1 = TimeSeries("2022-11-01", "BUSINESS", [12.5,12.6,12.7,12.8,12.9])
ts2 = TimeSeries("2022-11-01", "BUSINESS", [12.3,12.45,12.62,12.72,12.81])

// Add to an object
MYOBJ = Object()
MYOBJ.TS1 = ts1
MYOBJ.TS2 = ts2

// Save the object
save MYOBJ
Excel Addin

NOTE: You can easily create the above timeseries using our Excel Add-in - Working with timeseries

Visualising the timeseries

Below you can see a chart from the portal showing the 2 timeseries we have created

note

Notice how the 5 values we loaded align to the business (weekday) calendar such that the 5th value is stored against Monday 7th November 2022.

Adding more values

To add a new value for the 8th November 2022, we simply need to send the data for that date and OpenDataDSL merges that data into the timeseries, e.g.

// Add 1 value for the 8th November
ts1 = TimeSeries("2022-11-08", "BUSINESS", 13)
ts2 = TimeSeries("2022-11-08", "BUSINESS", 12.92)

// Add to an object
MYOBJ = Object()
MYOBJ.TS1 = ts1
MYOBJ.TS2 = ts2

// Save the object
save MYOBJ

Smart timeseries

A smart timeseries is a combination of one or more regular timeseries and an expression which is evaluated on the fly. An example of a smart timeseries is a spread which is the difference between 2 timeseries.

An example of creating a smart timeseries

This example shows you how to create a smart timeseries from the 2 regular timeseries we created in the section above.

The formula is simply BASE-OTHER

Where BASE is the TS1 timeseries and OTHER is the TS2 timeseries, we reference them using the ref() function

// Create a spread smart timeseries
MYOBJ = Object()
MYOBJ.SPREAD = SmartTimeSeries(ref("data", "MYOBJ:TS1"), "BASE-OTHER")
MYOBJ.SPREAD.OTHER = ref("data", "MYOBJ:TS2")

// Save the object
save MYOBJ

Visualising the spread smart timeseries

Below you can see the generated smart timeseries in the web portal

Event timeseries

An event timeseries is a timeseries that is constructed using a value from a set of documents called events. You could see an event as a timeseries observation stored in its own document.

Event timeseries are extremely useful when either the data is high frequency (hourly, 15 minutely etc.) or we need to store more information than just a time and value about the observation.

An example of creating a event timeseries

This example shows creating 2 events and then using them with an event timeseries.

// Create an object
MYOBJ = Object()

// Create some events - trade orders
ev1 = Event("2022-06-23T10:24:21")
ev1.type = "ASK"
ev1.price = 12.31
ev1.volume = 200

ev2 = Event("2022-06-23T10:24:22")
ev2.type = "BID"
ev2.price = 12.29
ev2.volume = 200

// Add the orders to the object
MYOBJ.ORDERS = [ev1, ev2]

// Create an event timeseries for the order prices
MYOBJ.ETS_PRICE = EventTimeSeries("MYOBJ:ORDERS", "price")

// Create an event timeseries for the order volumes
MYOBJ.ETS_VOLUME = EventTimeSeries("MYOBJ:ORDERS", "volume")

// Save the object
save MYOBJ

Curve tenor timeseries

Curve tenor timeseries show the history of a specific curve tenor and are dynamically generated when requested - so we don't need to create them.

To retrieve a curve tenor timeseries, we simply need to request the curve code suffixed with : and the tenor name, e.g.

#DCE.AG.CN.A.NO1_SOYBEAN.FUT:SETTLE:M01

TS = ${data:"#DCE.AG.CN.A.NO1_SOYBEAN.FUT:SETTLE:M01"}
print TS.values

Conclusion

Timeseries are an important and useful data component for all types of businesses. Aside from the typical financial and fundamental tracking uses, you can see that we can store anything against a timeline to create valuable insights into how things change over time.

Next steps

Do you want to see this in action and see how you can benefit from OpenDataDSL?

Fill out the form below, we will contact you to arrange a personally tailored demo.

How about a demo?

Our team is here to find the right solution for you, contact us to see this in action.

info@opendatadsl.com

+44 1245 555053

Fill out your details below and somebody will be in contact with you very shortly.

We'll never share your email address
Enter information about your area of interest, include your telephone number if you would like us to call you.

More information or free trial?

Tell us about your project, and we can let you know how we can help.

Contact us at info@opendatadsl.com

Further Reading