C# Client Library
A C# Client Library for the AnalyzeRe REST API
TargetCurrencyDefault.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 
6 using AnalyzeRe.Layers;
8 using AnalyzeRe.Utilities;
9 
10 namespace AnalyzeRe.APIResourceView
11 {
15  {
18  public TargetCurrencyDefault() : base(true) { }
19 
23  public override object GetDefaultValue(object owner)
24  {
25  return GetDefaultTargetCurrency(owner as IAPIResource);
26  }
27 
32  public static string GetDefaultTargetCurrency(IAPIResource resource)
33  {
34  if (resource == null)
35  throw new NotSupportedException("An resource instance must be " +
36  "supplied to determine what its default target currency would be.");
37  if (resource is ILayerView asLayerView)
38  return asLayerView.target_currency ??
39  GetDefaultFromLayer(asLayerView.layer, asLayerView.analysis_profile);
40  if (resource is OptimizationView ov)
41  return ov.analysis_profile.GetValue()?.exchange_rate_profile.GetValue()
42  .exchange_rate_table.GetValue().base_currency;
43  if (!(resource is PortfolioView pv))
44  throw new NotSupportedException("Unexpected APIResourceView type: " +
45  resource.GetType().NiceTypeName() + ". Could not determine the " +
46  "default target currency.");
47  // The default is determined by the most frequent currency encountered
48  IEnumerable<string> currencies;
49  // If this uses a reference to a portfolio, look at its list of layers
50  if (pv.portfolio != null)
51  currencies = pv.portfolio.GetValue().layers
52  .Select(layer => GetDefaultFromLayer(layer.GetValue(), pv.analysis_profile));
53  // Otherwise, look at the referenced list of layer_views
54  else if (pv.layer_views != null && pv.layer_views.Any())
55  currencies = pv.layer_views.Select(lv => lv.GetValue()).Select(GetDefaultTargetCurrency);
56  else
57  throw new NotSupportedException("PortfolioView is invalid.");
58  // Select the currency that appears most frequently in the portfolio
59  return currencies.GroupBy(ccy => ccy)
60  .Select(group => new { ccy = group.Key, count = group.Count() })
61  .OrderByDescending(group => group.count)
62  .Select(group => group.ccy).First();
63  }
64 
71  private static string GetDefaultFromLayer(ILayer layer,
72  IReference<AnalysisProfile> analysis_profile)
73  {
74  if (layer == null)
75  throw new NotSupportedException("The layer reference that determines " +
76  "the default target currency is null.");
77  if (layer is AggregateQuotaShare aggregateQuotaShare)
78  return aggregateQuotaShare.aggregate_limit.currency;
79  if (layer is AggXL aggXL)
80  return aggXL.aggregate_limit.currency;
81  if (layer is CatXL catXL)
82  return catXL.limit.currency;
83  if (layer is QuotaShare quotaShare)
84  return quotaShare.event_limit.currency;
85  if (layer is SurplusShare surplusShare)
86  return surplusShare.retained_line.currency;
87  if (layer is IndustryLossWarranty industryLossWarranty)
88  return industryLossWarranty.payout.currency;
89  if (layer is Nested nested)
90  {
91  IAPIResource sinkValue = nested.sink.GetValue();
92  return sinkValue is ILayer asLayer ? GetDefaultFromLayer(asLayer, analysis_profile) :
93  GetDefaultTargetCurrency(sinkValue);
94  }
95  if (layer is ValueAllocator valueAllocator)
96  {
97  IAPIResource sourceValue = valueAllocator.source.GetValue();
98  return sourceValue is ILayer asLayer ? GetDefaultFromLayer(asLayer, analysis_profile) :
99  GetDefaultTargetCurrency(sourceValue);
100  }
101  if (layer is BackAllocatedLayer backAllocatedLayer)
102  {
103  IAPIResource sinkValue = backAllocatedLayer.sink.GetValue();
104  return sinkValue is ILayer asLayer ? GetDefaultFromLayer(asLayer, analysis_profile) :
105  GetDefaultTargetCurrency(sinkValue);
106  }
107  if (layer is Filter || layer is LossRank)
108  return analysis_profile.GetValue().exchange_rate_profile.GetValue()
109  .exchange_rate_table.GetValue().base_currency;
110  if (layer is FixedRateCurrencyConverter fixedRateCurrency)
111  return fixedRateCurrency.out_currency;
112  if (layer is NoClaimsBonus noClaimsBonus)
113  return noClaimsBonus.payout_amount.currency;
114  throw new NotSupportedException("Unexpected layer type: " + layer.GetType() +
115  ". Could not determine the default target currency.");
116  }
117  }
118 }
Representation of an Aggregate Catastrophe Excess of Loss layer.
Definition: AggXL.cs:7
override object GetDefaultValue(object owner)
Returns the expected default value for the property based on the owner.
TargetCurrencyDefault()
Attribute which can determine the server-generated default target currency assigned to a IAPIResource...
Representation of a Quota Share contract.
Definition: QuotaShare.cs:8
Representation of a Surplus Share contract.
Definition: SurplusShare.cs:8
Represents the Analysis of a Layer
Definition: ILayerView.cs:5
Abstract representation of a layer.
Definition: ILayer.cs:7
The LossRank layer allows one to select a subset of occurrences in a trial year based on the relative...
Definition: LossRank.cs:11
Indicates that the property, if left null, will have a default value generated and filled in by the s...
Represents the Analysis of a Portfolio
static string GetDefaultTargetCurrency(IAPIResource resource)
Determine what the default target currency will be based on the resource type and properties...
Surfaces the value-allocator specialty structure (which is treated as a "layer definition" by the API...
Representation of an Industry Loss Warranty, which is a layer that triggers a payout (currently expre...
A structure that can be used to change the currency of a loss stream from one currency to another at ...
The No Claims Bonus applies a payout to trials which contain no losses. (i.e. when there are no occur...
Filter is like a layer whose &#39;terms&#39; are to filter events out of the loss sources. By referencing some loss sets filters, the result is that only the losses that meet the criteria of the filters are emitted.
Definition: Filter.cs:12
Base interface for all reference entities.
Definition: IReference.cs:7
Representation of a Catastrophe Excess of Loss (CatXL) layer.
Definition: CatXL.cs:8
Acts as a replacement for IAPIResourceView.back_allocations. Computes the proportion of some sink str...
Representation of a Quota Share contract that is limited in annual payouts.
Representation of a set of Optimization Parameters.
Allows one or more source layers or layer_views to be attached as loss sources to some other layer de...
Definition: Nested.cs:21
Attribute used to define the default value assigned to the target_currency property by the server whe...
Interface for Base class used by all resources.
Definition: IAPIResource.cs:8