C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
TargetCurrencyDefault.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
9
11{
15 {
18 public TargetCurrencyDefault() : base(true) { }
19
23 public override object GetDefaultValue(object owner)
24 {
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 || layer is DelayedPayment || layer is FixedDatePayment)
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}
Attribute used to define the default value assigned to the target_currency property by the server whe...
static string GetDefaultTargetCurrency(IAPIResource resource)
Determine what the default target currency will be based on the resource type and properties.
TargetCurrencyDefault()
Attribute which can determine the server-generated default target currency assigned to a IAPIResource...
override object GetDefaultValue(object owner)
Returns the expected default value for the property based on the owner.
Indicates that the property, if left null, will have a default value generated and filled in by the s...
Representation of an Aggregate Catastrophe Excess of Loss layer.
Definition AggXL.cs:8
Representation of a Quota Share contract that is limited in annual payouts.
Acts as a replacement for IAPIResourceView.back_allocations. Computes the proportion of some sink str...
Representation of a Catastrophe Excess of Loss (CatXL) layer.
Definition CatXL.cs:9
A "delayed payment" payment pattern models claims being paid in instalments at fixed delays after the...
Filter is like a layer whose 'terms' are to filter events out of the loss sources....
Definition Filter.cs:13
A "delayed payment" payment pattern models claims being paid in instalments at specific dates followi...
A structure that can be used to change the currency of a loss stream from one currency to another at ...
Representation of an Industry Loss Warranty, which is a layer that triggers a payout (currently expre...
The LossRank layer allows one to select a subset of occurrences in a trial year based on the relative...
Definition LossRank.cs:12
Allows one or more source layers or layer_views to be attached as loss sources to some other layer de...
Definition Nested.cs:22
The No Claims Bonus applies a payout to trials which contain no losses. (i.e. when there are no occur...
Representation of a Quota Share contract.
Definition QuotaShare.cs:9
Representation of a Surplus Share contract.
Surfaces the value-allocator specialty structure (which is treated as a "layer definition" by the API...
Representation of a set of Optimization Parameters.
Represents the Analysis of a Portfolio.
Interface for Base class used by all resources.
Represents the Analysis of a Layer.
Abstract representation of a layer.
Definition ILayer.cs:7
Base interface for all reference entities.
T GetValue(IEnumerable< Parameter > requestParameters=null, int? timeout=null, bool updateCache=false)
Gets the resource that this reference refers to by requesting it from the server.