ISDA CDM: What does an 'Optional' label mean?

Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful Daml Script. We now recommend using that for all purposes. For more information, and to learn how to use Script please check out @Andreas’ post on our blog.

I am working with the ISDA CDM model. The scenario in the ex-cdm-swaps example is for a CDS and I want to write a scenario for a FixedFloat swap. To do this, I have to reformat the Contract.daml found here. I am using the JSON representation of the FixedFloat swap from here.

My question is regarding the linter in VS-code. While building the FloatingRateSpecification constructor the linter is telling me that attributes labeled ‘Optional’ in the the Classes.daml file found here are strictly required.

The result is code with many more attributes than I intended, many of which are empty.

rateSpecification =
    RateSpecification with
        inflationRate = None
        floatingRate = Some
            (FloatingRateSpecification with
            averagingMethod = None
            capRateSchedule = []
            finalRateRounding = None
            floatingRateIndex = fieldWithEmptyMeta FloatingRateIndexEnum_USD_LIBOR_ISDA
            floatingRateMultiplierSchedule = None
            floorRateSchedule = []
            id = None
            indexTenor = None
            negativeInterestRateTreatment = None
            rateTreatment = None                                            
            spreadSchedule =  
                [SpreadSchedule with
                id = None
                initialValue = 0.005000
                step = []
                _type = None]
            initialRate = 0.032753
            )
        fixedRate = None

Is this something that has been fixed in subsequent SDK releases (CDM is 0.13.22)?

3 Likes

Hi @jamesljaworski85. It might help if you give the exact linter message you’re seeing - are you referring to a message from DLint?

From what you’re saying though it sounds like the typechecker itself was telling you that the rateSpecification record was missing fields with an Optional type. This might be confusing as the fields themselves are not “optional” in the sense that you can omit them, but you can supply them with a value None. This makes constructing your record much more verbose with the possible benefit of being more explicit about the contained values.

Let me know if that makes sense, as I may have misinterpreted your issue.

3 Likes

Hi @rohanjr. This makes sense now. I thought that the word optional meant that you could omit the attribute entirely. Thanks for your help!

4 Likes

Hi @jamesljaworski85!

As @rohanjr answered, you can’t omit optional fields when constructing a record from scratch.

There is a pattern that you might find useful, however, which is to have a “default” version of the record lying around, and use that as a starting point to build the record you want. That way you only have to specify the non-optional fields.

First, you would need a “default” version of the record, where all the fields are initialized with None or an appropriate default value. You may need to supply some field values that aren’t optional, as I do here, by passing a parameter:

defaultFloatingRateSpecification : FieldWithMeta FloatingRateIndexEnum -> FloatingRateSpecification
defaultFloatingRateSpecification floatingRateIndex =
    FloatingRateSpecification with
        averagingMethod = None
        capRateSchedule = []
        finalRateRounding = None
        floatingRateIndex = floatingRateIndex
        floatingRateMultiplierSchedule = None
        floorRateSchedule = []
        id = None
        indexTenor = None
        initialRate = None
        negativeInterestRateTreatment = None
        rateTreatment = None
        spreadSchedule = []

Then, you can construct a value more easily, since you can use defaultFloatingRateSpecification and you only need to specify the fields that deviate from your default:

rateSpecification =
    RateSpecification with
        inflationRate = None
        floatingRate = Some ((defaultFloatingRateSpecification (fieldWithEmptyMeta FloatingRateIndexEnum_USD_LIBOR_ISDA)) with
            spreadSchedule =
                [SpreadSchedule with
                id = None
                initialValue = 0.005000
                step = []
                _type = None]
            initialRate = Some 0.032753)
        fixedRate = None
3 Likes