In the ever-evolving world of financial transactions, the Common Domain Model (CDM) is now available in Python. Explore how this initiative is evolving to enhance data consistency and interoperability in the financial industry.
The Common Domain Model (CDM) is an initiative, managed by FINOS, designed to provide a standard representation of events and actions that occur during the lifecycle of a financial transaction. The goal of the CDM is to enhance the consistency and interoperability of data and processes across various platforms, systems, and solutions in the financial market.
The CDM is developed using a Domain Specific Language (DSL) and it is distributed across the financial industry in multiple languages, including Java, DAML, Scala, C#, Go, and TypeScript. The level of completeness of the distributions across these languages varies, being Java the most complete CDM distribution.
CDM was missing a Python distribution. We, as TradeHeader, saw having a CDM Python distribution in the critical path for being able to support many use cases using CDM. Python is heavily used in applications such as Machine Learning (ML) and pricing and risk libraries. In addition, the community of Python developers is huge and growing exponentially.
We decided to fill out the gap and implement a fully open source CDM Python Generator in collaboration with two other fintech firms, CloudRisk and FT Advisory.
The CDM Python Generator successfully converts Rosetta Objects, their expressions, and enumerated lists (Enums), ensuring a smooth transition between Rosetta and Python environments. This integration offers developers the ability to leverage Python's extensive libraries and tools, while still maintaining the consistency and standardization that CDM brings. We completed this first phase in August of 2023 when FINOS released the Python CDM distribution using the Generator.
At the heart of our generator is the `PythonCodeGenerator.java` main class. This class encompasses other crucial generators, such as the `ObjectGenerator`, `EnumGenerator`, and `FunctionGenerator`.
This is a simple example of an object in CDM defined using the functional DSL (Domain Specific Language) syntax:
As the functional code specifies, the PeriodRange type contains two optional attributes: lowerBound and upperBound. In addition, there is a condition that checks that at least one of the two attributes is present in the CDM object.
Python boasts simplicity in its syntax, making it easy to read and understand. This is the conversion from the CDM DSL object to Python:
One of the pivotal challenges in transitioning CDM's logic to Python is addressing the intricacies of cardinality. The CDM's cardinality representations do not have a direct counterpart in Python's type system. To navigate this challenge we use the Pydantic Library in the Generator. The Pydantic Library is a data validation and settings management tool for Python. Pydantic has been instrumental in defining clear data structures in Python that mirror the cardinality constraints present in CDM. This ensures data integrity and consistency when working with Rosetta Objects in Python.
We are already working on a second phase of the project further enhancing the capabilities of the CDM Python Generator. Here are the detailed next steps we are following:
Last month the winning team of the RepoHack 2023, The London Reporting House, used our CDM Python Generator as the basis for their solution. This was also a “victory” for us at TradeHeader since our initial goal was to provide a framework that could be used for many different CDM implementations.
Our aim isn't just to provide a tool once, but to refine it continuously and ensure that it becomes a reliable asset for developers working using CDM in Python.
David, Manuel, and Marc work are the current CDM Python team at TradeHeader.