Data Science for CTRM using TradeCube

Get started with data analytics using TradeCube's API - samples included.

Trading organisations are increasingly using data science as a discipline to optimise and analyse the wealth of data available from CTRM platforms and elsewhere. 

Traditionally, CTRM vendors have provided both standardised and customised reports as a primary data output from the system. The outputs were typically quite rigid and designed for an age where printed paper was the target medium. 

Resourceful end-users would want to perform their own analysis, and it was not uncommon for them to fill the gap by using cut and paste report from extracts or screen grabs, dumping the output into Excel, and then performing their own analysis. Often, these “bolt-on” spreadsheets grow a life of their own, expand, and become integral to the operation of the organisation. 

With the advancement of data science as a discipline and the improvement in analytical tools, the data scientist role bridges the gap between a full-blown software development approach and the plucky end-user spreadsheet. 

Tools such as pandas (python) and R have become increasingly popular due to their speed, power, community support and knowledge base. They provide a more structured environment than Excel – no need for giant grids of formulae.   

TradeCube provides the perfect environment for the CTRM data scientist, as data is accessible through standardised web services. All that is needed is a read-only API key which can be generated from the TradeCube platform, and with one web service request, the data is at your fingertips in your favourite data analysis tool. 

The examples below show how simple it is to get started. Using an API key from a test database, the code snippets call a data query web service, retrieves price data for a month, loads the data into a data frame and performs some basic aggregations:  

Pandas example

					import requests
import pandas as pd

query = {
    "Cube": "UKPowerSett",
    "DataItem": "SBP",
    "StartDate": "2021-08-01T00:00:00Z",
    "EndDate": "2021-08-08T00:00:00Z",
    "OutputFormat": "Vector"

headers = {'apikey': 'Thxra0CvHvJX4litvYWd8Rp561CzH2pH',
           'Content-Type': 'application/json'}

response ='',

df = pd.json_normalize(response.json().get('CubeDataQueryResult', {}).get('Vector')[0].get('Values'))

print(f'Minimum {df.Value.min()}')
print(f'Maximum {df.Value.max()}')
print(f'Mean    {df.Value.mean()}')
print(f'Median  {df.Value.median()}')
print(f'Std Dev {df.Value.std()}')

R example

					# install.packages('httr')
# install.packages('jsonlite')
response <- POST(
  url = '',
  body = '{
    "Cube": "UKPowerSett",
    "DataItem": "SBP",
    "StartDate": "2021-08-01T00:00:00Z",
    "EndDate": "2021-08-08T00:00:00Z",
    "OutputFormat": "Vector"
  add_headers('apikey' = 'Thxra0CvHvJX4litvYWd8Rp561CzH2pH', 'Content-Type' = 'application/json')
char <- rawToChar(response$content)
df <- fromJSON(char)
df <- df$CubeDataQueryResult$Vector$Values[[1]]
sprintf('Minimum %s', min(df$Value))
sprintf('Maximum %s', max(df$Value))
sprintf('Mean    %s', mean(df$Value))
sprintf('Median  %s', median(df$Value))
sprintf('Std Dev %s', sd(df$Value))

Both languages (helpfully!) return the same results:

Minimum -18.66
Maximum 144.41089
Mean 93.28408018181818
Median 114.75
Std Dev 40.15535131334942

CTRM Cubed Limited registered in England and Wales (number 10728615) Registered address: Lake View House, Wilton Drive, Tournament Fields, Warwick, CV34 6RG.