Constructors for a cost data subclass

Cost data objects have two constructors that you must implement. For each of the two types of constructors already mentioned for the CostData class, there is a variant that you must use if you plan to support multicurrency.

If the rating engine determines that a coverage has a premium, it must create an entirely new cost data. This is the most common situation for needing a new cost data object. In this situation, PolicyCenter creates a cost data object with a constructor that takes effective and expiration dates.

To support this, all CostData subclasses require a constructor that takes the effective and expiration dates and optionally any other subtype-specific data (to set in private variables). The CostData subclass must pass the effective and expiration dates to its superclass constructor. The superclass constructor sets various defaults for cost properties.

Guidewire strongly recommends that the constructor includes any subtype-specific properties in the constructor rather than setting these properties after instantiation.

The following code was taken from the personal auto cost data subtype PersonalAutoCovCostData. This constructor takes the effective and expiration dates as parameters and calls the init method to set local variables.

construct(effDate : Date, expDate : Date, vehicleIDArg : Key, covIDArg : Key) {
  super(effDate, expDate)
  init(vehicleIDArg, covIDArg)
}

private function init(vehicleIDArg : Key, covIDArg : Key) {
  assertKeyType(vehicleIDArg, PersonalVehicle)
  assertKeyType(covIDArg, PersonalAutoCov)
  _vehicleID = vehicleIDArg
  _covID = covIDArg
}

If rating only from the date of change forward, then the rating engine must create cost data objects that represent existing costs prior to the change in effective time. The following steps occur.

  1. The rating engine finds the relevant Cost entities that have an effective date prior to the effective date of the change.
  2. For each cost data object, the rating engine creates a cost data object using the cost data constructor that takes an existing Cost entity. The constructor creates a cost data object that matches the existing cost.
  3. If the CostData object has an expiration date that is later than the effective date of the change, the expiration date is set to the effective date of the change. The rating engine prorates the CostData object using the new expiration date.

For details, see the AbstractRatingEngineBase class in the extractCostDatasFromExistingCosts method.

To support this process, all CostData subclasses requires a constructor that takes a Cost of the appropriate type. Contrast this with the other constructor. The other constructor takes the effective and expiration dates for a new initialized cost data but no existing Cost entity.

For example, if a rating engine’s extractCostDatasFromExistingCosts method creates a CostData subclass, it calls this constructor. This method is only used when rating only from the date of change forward.

The following code was taken from the personal auto cost data subtype PersonalAutoCovCostData. This constructor takes the specific type of Cost entity as a parameter and sets local variables.

construct(c : PersonalAutoCovCost) {
  super(c)
  _vehicleID = c.PersonalVehicle.FixedId
  _covID = c.PersonalAutoCov.FixedId
}

For each of the two types of constructors mentioned for the CostData class, there is a variant that you must use if you plan to support multicurrency.

For the constructor that takes a Cost entity instance, the multicurrency variant takes an argument of type PolicyPeriodFXRateCache. The PolicyPeriodFXRateCache type is a cache of financial exchange rate data. This cache object is stored in every rating engine automatically when you based your rating engine subclass on AbstractRatingEngine. That base class populates a property called RateCache, which contains the PolicyPeriodFXRateCache object.

When your CostData subclass constructor calls its superconstructor, be sure to call the appropriate constructor and pass the multicurrency information. To support the rate cache from your rating engine, reference the RateCache property and pass it to the superclass.

For example, the cost data class for the business auto line (BusinessVehicleCovCostData) has a method signature that takes a PolicyPeriodFXRateCache object as a parameter.

construct(cost : BusinessVehicleCovCost, rateCache : PolicyPeriodFXRateCache) {
  super(cost, rateCache)

  // [ Do other things specific to this cost data subclass ]
}

From your rating engine, reference the cache in the RateCache property of your rating engine, as shown below.

override protected function createCostDataForCost(c : Cost) : CostData {
  switch (typeof c) {
    case BAStateCovVehiclePIPCost: return new BAStateCovVehiclePIPCostData(c, RateCache)
    case BAStateCovVehicleCost:    return new BAStateCovVehicleCostData(c, RateCache)
    case BAStateCovCost:           return new BAStateCovCostData(c, RateCache)
    case BusinessVehicleCovCost:   return new BusinessVehicleCovCostData(c, RateCache)
    case BALineCovCost:            return new BALineCovCostData(c, RateCache)
    case BALineCovNonownedCost:    return new BALineCovNonownedCostData(c, RateCache)
    default: throw "Unexpected cost type ${c.DisplayName}"
  }
}

Similarly, for the constructor that takes an effective date and an expiration date, the multicurrency variant takes two additional arguments.

  • A currency (Currency) for the cost – The as-rated currency, which is the currency that was used for the rate calculation. This is different from settlement currency, which is the currency for billing the customer.
  • A PolicyPeriodFXRateCache exchange rate cache object – The financial exchange rate cache for this rating engine.
construct(effDate : DateTime, expDate : DateTime, c : Currency, rateCache : PolicyPeriodFXRateCache) {
  super(effDate, expDate, c, rateCache)

  // Do initialization specific to your cost data subclass...
}