Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for merged enum #525

Open
lolabeis opened this issue Apr 27, 2023 · 6 comments · May be fixed by #833
Open

Support for merged enum #525

lolabeis opened this issue Apr 27, 2023 · 6 comments · May be fixed by #833
Labels
enhancement New feature or request subject: syntax This issue is about the syntax of Rosetta

Comments

@lolabeis
Copy link
Contributor

lolabeis commented Apr 27, 2023

Enumeration supports extension, where an extended enum adds enumerated values to a base enum. However those values have to be directly listed in the extended enum.

For reporting purposes, we would like the DSL to support extending an enum with the values of another enum rather than having to specify those values individually.

This applies in the CDM in the context of a rate option which can either be a floating rate (FloatingRateIndexEnum) or an inflation rate (InflationRateIndexEnum). For reporting purposes this may have to be reported as a single enum which is a merge of the two.

@lolabeis
Copy link
Contributor Author

lolabeis commented Apr 27, 2023

As part of this issue, we would also like the DSL to support asserting whether the value of a merged enum belongs to one or the other base enum - i.e. whether a rate option is a floating rate option or an inflation rate option in our use case - without having to assert against each possible value.

@lolabeis lolabeis changed the title Support for super-enum Support for merged enum Apr 28, 2023
@lolabeis lolabeis added enhancement New feature or request subject: syntax This issue is about the syntax of Rosetta labels Apr 28, 2023
@SimonCockx
Copy link
Contributor

In a way, I think this may be partially supported already.

This could be modelled with an empty super enum:

enum RateIndexEnum:

... from which FloatingRateIndexEnum and InflationRateIndexEnum can then extend:

enum FloatingRateIndexEnum extends RateIndexEnum:
	AED_EBOR_Reuters displayName "AED-EBOR-Reuters" <"Per 2006 ISDA Definitions or Annex to the 2000 ISDA Definitions, Section 7.1 Rate Options, as amended and supplemented through the date on which parties enter into the relevant transaction.">
	AED_EIBOR displayName "AED-EIBOR" <"Per 2021 ISDA Interest Rate Derivatives Definitions Floating Rate Matrix, as amended through the date on which parties enter into the relevant transaction.">
	...

enum InflationRateIndexEnum extends RateIndexEnum:
	AUD_CPI displayName "AUD-CPI" <"Australia: AUD - Non-revised Consumer Price Index (CPI)">
	AUS_CPI displayName "AUS-CPI" <"Austria: AUS - Non-revised Consumer Price Index (CPI)">
	...

A RateOption could then be modelled as

type RateOption:
    rateIndex RateIndexEnum (1..1)
    ...

There is a related issue that might sometimes lead to static compilation issues though: #531.

@SimonCockx
Copy link
Contributor

SimonCockx commented May 2, 2023

As part of this issue, we would also like the DSL to support asserting whether the value of a merged enum belongs to one or the other base enum - i.e. whether a rate option is a floating rate option or an inflation rate option in our use case - without having to assert against each possible value.

We can potentially generalize this to have an operation that can assert whether a value is of some type, not just for enums. (much like Java's instanceof operator) Use cases include distinguishing between specific subtypes of a more general type.

On the other hand - we have also discussed introducing a concept such as dynamic dispatch for functions (much like how method overriding works in Java), or having a concept similar to Haskell's type classes (somewhat more extensible than dynamic dispatch). Taking this route might make the above operation superfluous.

Something worth discussing.

@hugohills-regnosys
Copy link
Contributor

hugohills-regnosys commented May 26, 2023

On the other hand - we have also discussed introducing a concept such as dynamic dispatch for functions (much like how method overriding works in Java)

Dynamic dispatch functions are discussed in issue #546

@hugohills-regnosys
Copy link
Contributor

hugohills-regnosys commented Jun 6, 2023

In a way, I think this may be partially supported already.

This could be modelled with an empty super enum:

enum RateIndexEnum:

... from which FloatingRateIndexEnum and InflationRateIndexEnum can then extend:

enum FloatingRateIndexEnum extends RateIndexEnum:
	AED_EBOR_Reuters displayName "AED-EBOR-Reuters" <"Per 2006 ISDA Definitions or Annex to the 2000 ISDA Definitions, Section 7.1 Rate Options, as amended and supplemented through the date on which parties enter into the relevant transaction.">
	AED_EIBOR displayName "AED-EIBOR" <"Per 2021 ISDA Interest Rate Derivatives Definitions Floating Rate Matrix, as amended through the date on which parties enter into the relevant transaction.">
	...

enum InflationRateIndexEnum extends RateIndexEnum:
	AUD_CPI displayName "AUD-CPI" <"Australia: AUD - Non-revised Consumer Price Index (CPI)">
	AUS_CPI displayName "AUS-CPI" <"Austria: AUS - Non-revised Consumer Price Index (CPI)">
	...

A RateOption could then be modelled as

type RateOption:
    rateIndex RateIndexEnum (1..1)
    ...

I think this is the correct solution. However it would require a significant amount of Java code generation work to implement because Rosetta enums are currently generated as native Java enums. This is a problem because Java enums do not support inheritance, so to implement this the Java code generation would need to generate an enum abstraction (e.g. wrap it in a class).

@hugohills-regnosys
Copy link
Contributor

hugohills-regnosys commented Jun 6, 2023

An interim solution which would be useful in other scenarios would be to provide a to-string and to-enum utility methods to enums, as described in #570

  • The code InflationRateIndexEnum -> AUD_CPI to-string would result in a string "AUD-CPI" (uses the displayName if specified).
  • The code "AUD-CPI" to-enum InflationRateIndexEnum would result in a enum InflationRateIndexEnum -> AUD_CPI.

A RateOption could then be modelled as string:

type RateOption:
    rateIndex string (1..1)
    ...

@SimonCockx SimonCockx linked a pull request Sep 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request subject: syntax This issue is about the syntax of Rosetta
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants