Reinsurance Structure

The model is intended to permit evaluation of different reinsurance structures in a simulation over time, where reinsurance can change in response to conditions. The model maintains a close structural analogue to how an insurance expert would visualise reinsurance of the risk. The structure can be quickly chamged manually, or the reinsurance structure can change automatically.

ris2.gif (29251 bytes)

The structural analogue also allows very natural reporting of the allocation of risk.

ris2.gif (26567 bytes)

The model is broken up into product categories, and the premium income and risk from these categories goes through layers of reinsurance.

RIProgramV2_4@ Begin

Control@ begin

! Run the simulation NumberOfCycles times
!Simulate@ EQV FORNEST({{iSIM,1,NumberOfCycles}},TestSIM@,MoveSIM@,StartupSIM@,InitialiseSIM@)
!TestSIM@ EQV STOREUNDO(FullCycleChecked@,StartCycle@,LOGSTATE(iSim))

StopConditionsChecked@ EQV CheckRun(StopConditions%,{TestSim@},FinishRun@)
FullCycle@ EQV DEMON(StartCycle@)
StartupFC@ EQV LOGSTATE(iSIM)
FullCycleChecked@ EQV StopConditionsChecked@
iFC = iFC0 -1

! Stop conditions - add condition vars to the list below. If at least one of them is true - the simulation pauses

StopConditions% = {}

! Activate a full cycle - regenerate cats and generate claims for BusinessYears years. Business runoff period is AnalysisYears.

FullCycle@ EQV FORNEST({{iFC,0,BusinessYears}},TestFC@,MoveFC@,StartupFC@,InitialiseFC@)

! In phase 0 - recreate catastrophe events and clear aggrigation lists

if iFC = 0 then ( ReGenerateCats@ EQV Logstate(iFC)) AND (TestFC@ EQV CatsGenerated@ ) AND ClearCashflow@
TotalRecoveriesCashflow% = MAKELIST('',{1..30},'NUMERIC',{1,0})
TotalClaimsCashflow% = MAKELIST('',{1..30},'NUMERIC',{1,0})
TotalPaymentsCashflow% = MAKELIST('',{1..30},'NUMERIC',{1,0})
TotalPremiumsCashflow% = MAKELIST('',{1..30},'NUMERIC',{1,0})
TotalCostsCashflow% = MAKELIST('',{1..30},'NUMERIC',{1,0})
ClearedCashflow@ EQV ClearCashflows(Cashflows%,ClearCashflow@)
Cashflows% = {TotalRecoveriesCashflow%,TotalClaimsCashflow%,TotalPaymentsCashflow%,TotalRunCashflow%,TotalPremiumsCashflow%,TotalCostsCashflow%}

! In each yearly phase, 1 to BusinessYears, regenerate claims, activate RI program and aggregate cashflows

if iFC > 0 then ( RegenerateClaims@ EQV Logstate(ThisYear)) AND (ThisYear = iFC) AND ( TestFC@ EQV Logstate(YearlyWritten) )

! After policies/claims are generated, let them flow into the RI program structure

ASK(ConnectPolicies@) EQV ClaimsGenerated@

! Write out consolidated cashflow

YearlyWritten := WriteYearly(YearlyDetails%,{iSIM, iFC},LOGSTATE(YearlyCashflow%))
YearlyDetails% = {YearlyCashflow%}

! Consolidate yearly cashflows

YearlyCashFlow% = SubtractLists(YearlyRecoveries%,YearlyPayments%)
YearlyRecoveries%:=ASK(TotalRIRecoveries%)
YearlyPayments%:=ASK(TotalRIPayments%)

! Aggregate yearly cashflows

EndRecoveries = CashBalance(TotalRecoveriesCashflow%,YearlyRecoveries%)
EndPayments = CashBalance(TotalPaymentsCashflow%,YearlyPayments%)

! End of cycle

TotalPaids% = SumLists(TotalPaymentsCashflow%,TotalClaimsCashflow%, TotalCostsCashflow%, AggregateCashflows@)
TotalIncome% = SumLists(TotalRecoveriesCashflow%,TotalPremiumsCashflow%, AggregateCashflows@)
TotalRunCashflow% = SubtractLists(TotalIncome%,TotalPaids% , LOGSTATE(TotalPaids%),LOGSTATE(TotalPaids%))
FinishRun@ EQV SEQUENCE(AggregateCashflows@,FullCycle@,True,false)

! Connect to all cats

RegenerateCats@ EQV RegenerateFloods@ and RegenerateStorms@
FloodsGenerated:=ResetVar({ASK(GenerateFloods@)},RegenerateFloods@)
StormsGenerated:=ResetVar({ASK(GenerateStorms@)},RegenerateStorms@)
CatsGenerated@ EQV LogState(FloodsGenerated) AND Logstate(StormsGenerated)

! Connect to all lines of business

RegenerateClaims@ EQV ( ReGenerateCPPolicies@ AND ReGenerateHHPolicies@ AND ReGenerateACCPolicies@ AND ReGenerateMOTPolicies@ )
CPPoliciesGenerated:=ResetVar({ASK(GenerateCPPolicies@)},ReGenerateCPPolicies@)
HHPoliciesGenerated:=ResetVar({ASK(GenerateHHPolicies@)},ReGenerateHHPolicies@)
ACCPoliciesGenerated:=ResetVar({ASK(GenerateACCPolicies@)},ReGenerateACCPolicies@)
MOTPoliciesGenerated:=ResetVar({ASK(GenerateMOTPolicies@)},ReGenerateMOTPolicies@)
ClaimsGenerated@ EQV ( Logstate(CPPoliciesGenerated) AND Logstate(HHPoliciesGenerated) AND Logstate(ACCPoliciesGenerated) AND Logstate(MOTPoliciesGenerated) )

! Need to resample only after the data sources have changed

ResampleCatDistributions@ EQV ASK(setStormNumberEvent@) AND ASK(setFloodNumberEvent@)

End !Control@

RIProgram@ begin

! Connect to the policies generators

ConnectPolicies@ EQV (CPPolicies% = ASK(CPPolicies%)) AND (HHPolicies% = ASK(HHPolicies%)) AND (ACCPolicies% = ASK(ACCPolicies%)) AND (MOTPolicies% = ASK(MOTPolicies%))
ThisYear:=ASK(ThisYear)

! Add program here
! Quota on Household

HHAfterQuota% = RIQuota(HHPolicies%,HHQuotaVars%,HHQuotaAttributes%,HHQuotaTrigger@)
HHQuotaVars% = {HHQuotaRecoveries%,HHQuotaPayments%,HHQuotaCommission}
HHQuotaRecoveries% = MAKELIST('',{1..30},'NUMERIC',{1,0})
HHQuotaPayments% = MAKELIST('',{1..30},'NUMERIC',{1,0})
HHQuotaAttributes% = {HHQuotaFraction, HHQuotaUpperLimit, HHQuotaROI, HHQuotaDelay, HHQuotaInterest , ThisYear}

! Surplus on Commercial Property

CPAfterSurplus% = RISurplus(CPPolicies%,CPSurplusVars%,CPSurplusAttributes%,RISurplusTrigger@)
CPSurplusVars% = {CPSurplusRecoveries%, CPSurplusPayments%}
CPSurplusRecoveries% = MAKELIST('',{1..30},'NUMERIC',{1,0})
CPSurplusPayments% = MAKELIST('',{1..30},'NUMERIC',{1,0})
CPSurplusAttributes% = {CPSurplusRetention, CPSurplusLines, CPSurplusDelay, CPSurplusInterest, ThisYear}

! Second layer RiskXs on Commercial Property

CPSurplusRiskXs% = RIXLR(CPAfterSurplus%,CPRXVars%,CPRXAttributes%,CPRXTrigger@)
CPRXVars% = {CPRXRecoveries%, CPRXPayments%}
CPRXRecoveries% = MAKELIST('',{1..30},'NUMERIC',{1,0})
CPRXPayments% = MAKELIST('',{1..30},'NUMERIC',{1,0})
CPRXAttributes% = {CPRXRetention, CPRXUpperLimit, CPRXRate,CPRXDelay, CPRXInterest, ThisYear}

! Cat on Household and Commercial Property
! Combine streams

HHandCP%:=CombineLists(CPSurplusRiskXs%,HHAfterQuota%)

! into a Cat

HHCPCatPolicies% = RICat(HHandCP%,HHCPCatVars%,HHCPCatAttributes%,HHCPCatTrigger@)
HHCPCatVars% = {HHCPCatRecoveries%, HHCPCatPayments%}
HHCPCatRecoveries% = MAKELIST('',{1..30},'NUMERIC',{1,0})
HHCPCatPayments% = MAKELIST('',{1..30},'NUMERIC',{1,0})
HHCPCatAttributes% = {HHCPCatRetention, HHCPCatUpperLimit, HHCPCatRate,HHCPCatDelay, HHCPCatInterest, ThisYear}

! Quota on Motor

MOTAfterQuota% = RIQuota(MOTPolicies%,MOTQuotaVars%,MOTQuotaAttributes%,MOTQuotaTrigger@)
MOTQuotaVars% = {MOTQuotaRecoveries%,MOTQuotaPayments%,MOTQuotaCommission}
MOTQuotaRecoveries% = MAKELIST('',{1..30},'NUMERIC',{1,0})
MOTQuotaPayments% = MAKELIST('',{1..30},'NUMERIC',{1,0})
MOTQuotaAttributes% = {MOTQuotaFraction, MOTQuotaUpperLimit, MOTQuotaROI, MOTQuotaDelay, MOTQuotaInterest , ThisYear}

! Umbrella on all, including Accidents
! Combine

Combination1%:=CombineLists(ACCPolicies%,MOTAfterQuota%,HHCPCatPolicies%)

! Into a cat

Umbrella1% = RICat(Combination1%,Umbrella1Vars%,Umbrella1Attributes%,Umbrella1Trigger@)
Umbrella1Vars% = {Umbrella1Recoveries%, Umbrella1Payments%}
Umbrella1Recoveries% = MAKELIST('',{1..30},'NUMERIC',{1,0})
Umbrella1Payments% = MAKELIST('',{1..30},'NUMERIC',{1,0})
Umbrella1Attributes% = {Umbrella1Retention, Umbrella1UpperLimit, Umbrella1Rate,Umbrella1Delay, Umbrella1Interest, ThisYear}

! Interface structures - add Recoveries and payments structures to lists, final structures to FinalStructures%

FinalStructures%={Umbrella1%}
RecoveriesStructure% := {Umbrella1Recoveries%, MOTQuotaRecoveries%, HHCPCatRecoveries%, CPRXRecoveries%, CPSurplusRecoveries%, HHQuotaRecoveries%}
PaymentsStructures%:={Umbrella1Payments%,MOTQuotaPayments%,HHCPCatPayments%,CPRXPayments%,CPSurplusPayments%,HHQuotaPayments%}
PropagationFinished=Sum(FinalStructures%)

! Keep PropagationFinished as an argument so that it can trigger SumLists

RecoveriesInput%:= RecoveriesStructure% + {Logstate(PropagationFinished)}
TotalRIRecoveries%:= SumLists(ListLink(RecoveriesInput%))
PaymentsInput%:=PaymentsStructures%+{Logstate(PropagationFinished)}
TotalRIPayments%:=SumLists(ListLink(PaymentsInput%))

End !RIProgram@

CatGenerator@ begin

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Storm cats !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Generate Storm cats. Activate by GenerateFloods@, finish by StormsGenerated@

DoneGenSTStep1@ EQV SEQUENCE(GenSTStep1@, GenerateStorms@,True,False)
DoneGenSTStep2@ EQV SEQUENCE(GenSTStep2@, DoneGenSTStep1@,True,False)
StormsGenerated@ EQV DoneGenSTStep2@

! Save the Storm highest and lowest event number for later use (need it while the variable itself is set to another value)

MaxStormEventNumber = LATCH(HIGHEST(ASK(EventNumber)), SetStormNumberEvent@)
MinStormEventNumber = LATCH(LOWEST(ASK(EventNumber)), SetStormNumberEvent@)

! Activate the generation number of Storms per year. Activated by the SEQUENCE control structure

StartupStormsReset := ResetVar({StartupStorms@},GenSTStep1@)
GenerateStormsNum@ EQV Demon(StartupStormsReset)

! generate number of yearly Storms based on the distribution of NumberOfStorms

GenerateStormsNum@ eqv FORNEST({{iStorms,0,AnalysisYears}},TestStorms@,MoveStorms@,StartupStorms@,InitialiseStorms@)
NumberOfStorms:= RANDOM(1,logstate(iStorms))
If InitialiseStorms@ then NewNumberOfStorms% = {} else NewNumberOfStorms% = OldNumberOfStorm% + {EVAL(NumberOfStorms)}
TestStorms@ EQV GETPUT(NewNumberOfStorms%,OldNumberOfStorm%,UNIQUE(NumberOfStorms),{YearlyNumberOfStorms%},{})

! Activate the generation of storms structures. Activated by the SEQUENCE control structure

StartupSTCatReset := ResetVar({StartupSTCat@},GenSTStep2@)
GenerateStormCats@ EQV Demon(StartupSTCatReset)

! Generate yearly Storm catastrophes - severity and extra damage - based on the number of events and the Storms histogram

GenerateStormCats@ EQV FORNEST({{iSTCat,0,AnalysisYears}},TestSTCat@,MoveSTCat@,StartupSTCat@,InitialiseSTCat@)

! Connect to the histograms block variables to trigger the random and extract the likelihood and extra amount

ThisStormSeverity= UNIQUE(ASK(Likelihood))
Logstate(UNIQUE(ThisStormSeverity)) EQV ( ThisStormCPDamage:= UNIQUE(ASK(Amount)) ) AND ( ThisStormHHDamage:= UNIQUE(ASK(Amount)))

! trigger the RANDOM only after the number of events is set

logstate(UNIQUE(ASK(EventNumber))) EQV (ASK(TriggerRandom):=iSTCat)

! First, set the number of events - if higher than the highest value modeled, use the highest value modeled (ie, for 2 and up use 2)

logstate(iSTCat) EQV ( ASK(EventNumber):=STActualEventNumber) AND (ASK(EventNumber):=STActualEventNumber)
STActualEventNumber:= MAX( MinStormEventNumber, MIN( MaxStormEventNumber,YearlyNumberOfStorms%[iSTCatInd]) )
iSTCatInd = max(iSTCat, 1)

! Concatenate to lists

If InitialiseSTCat@ then NewStormSeverity%= {} else NewStormSeverity%=OldStormSeverity% + {EVAL(ThisStormSeverity)}
If InitialiseSTCat@ then NewStormCPDamage%= {} else NewStormCPDamage%=OldStormCPDamage% + {EVAL(ThisStormCPDamage)}
If InitialiseSTCat@ then NewStormHHDamage%= {} else NewStormHHDamage%=OldStormHHDamage% + {EVAL(ThisStormHHDamage)}
SeverityDone@ EQV GETPUT(NewStormSeverity%,OldStormSeverity%,ThisStormSeverity,{YearlyStormSeverity%},{})
DamageCPDone@ EQV GETPUT(NewStormCPDamage%,OldStormCPDamage%,ThisStormHHDamage,{YearlyStormCPDamage%},{})
DamageHHDone@ EQV GETPUT(NewStormHHDamage%,OldStormHHDamage%,ThisStormCPDamage,{YearlyStormHHDamage%},{})
TestSTCat@ EQV SeverityDone@ AND DamageCPDone@ AND DamageHHDone@

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Flood cats !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Generate Flood cats. Activate by GenerateFloods@, finish by FloodsGenerated@

DoneGenFLStep1@ EQV SEQUENCE(GenFLStep1@, GenerateFloods@,True,False)
DoneGenFLStep2@ EQV SEQUENCE(GenFLStep2@, DoneGenFLStep1@,True,False)
FloodsGenerated@ EQV DoneGenFLStep2@

! Save the fire highest and lowest event number for later use (need it while the variable itself is set to another value)

MaxFloodEventNumber = LATCH(HIGHEST(ASK(EventNumber)), SetFloodNumberEvent@)
MinFloodEventNumber = LATCH(LOWEST(ASK(EventNumber)), SetFloodNumberEvent@)

! Activate the generation number of floods per year. Activated by the SEQUENCE control structure

StartupFLSIReset := ResetVar({StartupFlood@},GenFLStep1@)
GenerateFloodsNum@ EQV Demon(StartupFLSIReset)

! generate number of yearly Floods based on a distribution operator

GenerateFloodsNum@ eqv FORNEST({{iFlood,0,AnalysisYears}},TestFlood@,MoveFlood@,StartupFlood@,InitialiseFlood@)
NumberOfFloods:= RANDOM(1,logstate(iFlood))
if InitialiseFlood@ then NewNumberOfFloods% = {} else NewNumberOfFloods% = OldNumberOfFloods% + {EVAL(NumberOfFloods)}
TestFlood@ EQV GETPUT(NewNumberOfFloods%,OldNumberOfFloods%,NumberOfFloods,{YearlyNumberOfFloods%},{})

! Activate the generation of floods Structures. Activated by the SEQUENCE control structure

StartupFlCatReset := ResetVar({StartupFlCat@},GenFLStep2@)
GenerateFloodCats@ EQV Demon(StartupFlCatReset)

! Generate yearly Flood cataFLrophes - severity and extra damage - based on the number of events and the Floods hiFLogram

GenerateFloodCats@ EQV FORNEST({{iFLCat,0,AnalysisYears}},TestFLCat@,MoveFLCat@,StartupFLCat@,InitialiseFLCat@)

! Connect to the histograms block variables to trigger the random and extract the likelihood and extra amount

ThisFloodSeverity:= UNIQUE(ASK(Likelihood))
Logstate(UNIQUE(ThisFloodSeverity)) EQV ( ThisFloodCPDamage:= UNIQUE(ASK(Amount)) ) AND ( ThisFloodHHDamage:= UNIQUE(ASK(Amount)))

! trigger the RANDOM only after the number of events is set

logstate(UNIQUE(ASK(EventNumber))) EQV (ASK(TriggerRandom):=iFLCat)

! First, set the number of events - if higher than the highest value modeled, use the highest value modeled (ie, for 2 and up use 2)

logstate(iFLCat) EQV ( ASK(EventNumber):=FLActualEventNumber) AND (ASK(EventNumber):=FLActualEventNumber)
FLActualEventNumber:= MAX( MinFloodEventNumber, MIN( MaxFloodEventNumber,YearlyNumberOfFloods%[iFLCatInd]) )
iFLCatInd = max(iFLCat, 1)

! Concatenate to lists

If InitialiseFLCat@ then NewFloodSeverity%= {} else NewFloodSeverity%=OldFloodSeverity% + {EVAL(ThisFloodSeverity)}
If InitialiseFLCat@ then NewFloodCPDamage%= {} else NewFloodCPDamage%=OldFloodCPDamage% + {EVAL(ThisFloodCPDamage)}
If InitialiseFLCat@ then NewFloodHHDamage%= {} else NewFloodHHDamage%=OldFloodHHDamage% + {EVAL(ThisFloodHHDamage)}
SeverityDone@ EQV GETPUT(NewFloodSeverity%,OldFloodSeverity%,ThisFloodSeverity,{YearlyFloodSeverity%},{})
DamageCPDone@ EQV GETPUT(NewFloodCPDamage%,OldFloodCPDamage%,ThisFloodCPDamage,{YearlyFloodCPDamage%},{})
DamageHHDone@ EQV GETPUT(NewFloodHHDamage%,OldFloodHHDamage%,ThisFloodHHDamage,{YearlyFloodHHDamage%},{})
TestFLCat@ EQV SeverityDone@ AND DamageCPDone@ AND DamageHHDone@

End !CatGenerator@

! Commercial Property - - sums insured are taken from a distribution, claims affected by floods and stroms based on cats histograms

CPClaimsGenerator@ begin

! Re-generate Commercial Property policies/claims . Triggered by GenerateCPPolicies@, finish by CPPoliciesGenerated@

DoneGenCPStep1@ EQV SEQUENCE(GenCPStep1@,GenerateCPPolicies@,True,False)
DoneGenCPStep2@ EQV SEQUENCE(GenCPStep2@,DoneGenCPStep1@,True,False)
CPPoliciesGenerated@ EQV DoneGenCPStep2@

! Connect to CatGenerator@ block

ConnectStorms@ eqv ( YearlyNumberOfStorms% = ASK(YearlyNumberOfStorms%)) AND ( YearlyStormCPDamage% = ASK(YearlyStormCPDamage%) )
ConnectFloods@ eqv ( YearlyNumberOfFloods% = ASK(YearlyNumberOfFloods%) ) AND ( YearlyFloodCPDamage% = ASK(YearlyFloodCPDamage%) )
ConnectAnalysisYears@ eqv AnalysisYears = ASK(AnalysisYears)

! The variable ThisYear is taken from the index of the FORNEST in the control block

ThisYear := ASK(ThisYear)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Commercial Proper
! Input variables for Commercial Property policies. PMLMean is in percent of the premium. CPSizeDev is a percentage in fraction.

CommercialPropertyInfo% = {CPNum, CPSizeDev, CPPatternMeans%, CPPatternsDevs%, CPPremiumMean, CPPremiumDev, CPCostMean, CPCostDev, CPPMLMean, CPPMLDev}

! Input vars for household claims - catastrophy impact on claims sizes is in percentage

CPClaimsGeneralInfo% = {CPClaimSizeMean,CPClaimSizeDev}

! Activate the generation of the policies sums insured. Activated by the SEQUENCE strucure controling the policies generation

StartupCPSIReset := ResetVar({StartupCPSI@},GenCPStep1@)
GenerateCPSumsInsured@ EQV Demon(StartupCPSIReset)

! Policies attributes

GenerateCPSumsInsured@ eqv FORNEST({{iCPSI,0,CPNum}},TestCPSI@,MoveCPSI@,StartupCPSI@,InitialiseCPSI@)
CPSumInsured:= RANDOM(1,logstate(iCPSI))
CPSIDev:=CPSumInsured * CPSizeDev
CPActualSumInsured= Randg(Unique(CPSumInsured),Unique(CPSIDev))
if InitialiseCPSI@ then NewCPSumsInsured% = {} else NewCPSumsInsured% = OldCPSumsInsured% + {EVAL(CPActualSumInsured)}
TestCPSI@ EQV GETPUT(NewCPSumsInsured%,OldCPSumsInsured%,CPActualSumInsured,{CPSumsInsured%},{})
CPNumPolicies%:=MAKELIST('',{1..CPNum},'NUMERIC',{CPNumPolicies%, 1})
CPPatterns% := genRandGManyLists(CPPatternMeans%, CPPatternsDevs%, CPNum, GenCPStep2@)
CPPremiums% = genRandGList(CPPremiumMean, CPPremiumDev, CPNum, Logstate(CPPatterns%))
CPActualPremiums%:=MultLists(CPPremiums%,CPSumsInsured%)
TotalPremiums=SUM(CPActualPremiums%)
CPCosts% = genRandGList(CPCostMean, CPCostDev, CPNum, Logstate(CPActualPremiums%))
CPActualCosts% =MultLists(CPCosts%,CPActualPremiums%)
TotalCosts=SUM(CPActualCosts%)
CPPMLs% = genRandGList(CPPMLMean, CPPMLDev, CPNum, Logstate(CPActualCosts%))
CPActualPMLs%:=MultLists(CPPMLs%,CPActualPremiums%)

! The excess damage caused by floods per analysis year

CPYearlyFloodsImpact%:=MultLists( YearlyNumberOfFloods%,YearlyFloodCPDamage% )

! The excess damage caused by fires per analysis year

CPYearlyStormsImpact%:= MultLists(YearlyNumberOfStorms%,YearlyStormCPDamage% )

! Total

CPCatImpact%:=SumLists(CPYearlyFloodsImpact%,CPYearlyStormsImpact%)

! Generate a list of yearly claims for every analysis year

CPClaimSizes% = genRandGList(CPClaimSizeMean,CPClaimSizeDev,CPNum, Logstate(CPActualPMLs%))
CPBasicClaims% = MultLists(CPActualPremiums%,CPClaimSizes%)
ThisYearImpact := CPCatImpact%[ThisYear] * 1000000
CPClaims% =AmplifyClaims(CPBasicClaims%,ThisYearImpact )
AddedClaims@ EQV ClaimsToCash(ASK(TotalClaimsCashflow%),CPClaims%,CPPatterns%,ThisYear)
AddedPremiums@ EQV AddToCashflow(ASK(TotalPremiumsCashflow%), TotalPremiums,ThisYear,AddedClaims@ )
AddedCosts@ EQV AddToCashflow(ASK(TotalCostsCashflow%),TotalCosts,ThisYear,AddedPremiums@)
IF AddedCosts@ then CPRets%:= DuplicateList(CPClaims%)

! Pack policies and claims in a tructure

CPPolicies% = MembersReady(CPSumsInsured%, CPNumPolicies%,CPPatterns%, CPActualPremiums%, CPActualCosts%, CPActualPMLs%, CPClaims%, CPRets%)

End !CPClaimsGenerator@

! Household - sums insured are taken from a distribution, claims affected by floods and stroms based on cats histograms

HHClaimsGenerator@ begin

! Re-generate Household policies/claims . Triggered by GenerateHHPolicies@, finish by HHPoliciesGenerated@

DoneGenHHStep0@ EQV SEQUENCE(GenHHStep0@,GenerateHHPolicies@,True,False)
DoneGenHHStep1@ EQV SEQUENCE(GenHHStep1@,DoneGenHHStep0@,True,False)
DoneGenHHStep2@ EQV SEQUENCE(GenHHStep2@,DoneGenHHStep1@,True,False)
HHPoliciesGenerated@ EQV DoneGenHHStep2@

! Connect to CatGenerator@ block

ConnectStorms@ eqv ( YearlyNumberOfStorms% = ASK(YearlyNumberOfStorms%)) AND ( YearlyStormHHDamage% = ASK(YearlyStormHHDamage%) )
ConnectFloods@ eqv ( YearlyNumberOfFloods% = ASK(YearlyNumberOfFloods%) ) AND ( YearlyFloodHHDamage% = ASK(YearlyFloodHHDamage%) )
ConnectAnalysisYears@ eqv AnalysisYears = ASK(AnalysisYears)

! The variable ThisYear is taken from the index of the FORNEST in the control block

ThisYear := ASK(ThisYear)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Household

! Input variables for Household policies. PMLMean is in percent of the premium. CPSizeDev is a percentage in fraction.

HouseholdInfo% = {HHSizeDev, HHPatternMeans%, HHPatternsDevs%, HHPremiumMean, HHPremiumDev, HHCostMean, HHCostDev, HHPMLMean, HHPMLDev}

! Input vars for household claims - catastrophy impact on claims sizes is in percentage

HHClaimsGeneralInfo% = {HHClaimSizeMean,HHClaimSizeDev}

! Create a list out of the range of the sums insured distribution. It will be used in the generation.

GotList@ EQV GETPUT(NewSumsInsuredList%,OldSumsInsuredList%,GenHHStep0@,{HHSumInsuredLevels%},{})
if Logstate(OldSumsInsuredList%) then NewSumsInsuredList% = LIST(HHSumInsured)
HHNUM :=SIZE(HHSumInsuredList%)

! Activate the generation of the policies sums insured. Activated by the SEQUENCE strucure controling the policies generation

StartupHHSIReset := ResetVar({StartupHHSI@},GenHHStep1@)
GenerateHHSumsInsured@ EQV Demon(StartupHHSIReset)

! Policies attributes -
! Sums insured - here, a distribution on HHSumsInsured is used to create SumsInsured

GenerateHHSumsInsured@ eqv FORNEST({{iHHSI,0,HHNum}},TestHHSI@,MoveHHSI@,StartupHHSI@,InitialiseHHSI@)
logstate(iHHSI) EQV ( MAX(1,iHHSI) = iHHSIind ) AND ( HHSumInsured:= HHSumInsuredLevels%[iHHSIind] ) AND (HHSIDev:=HHSumInsured * HHSizeDev) AND ( HHNumberPolicies:=EXTRACT(HHSumInsured,'MAX',1) ) AND (HHActualSumInsured:=Randg(HHSumInsured,HHSIDev) * HHNumberPolicies)
if InitialiseHHSI@ then NewHHNumberOfPolicies% = {} else NewHHNumberOfPolicies% = OldHHNumberOfPolicies% + {EVAL(HHNumberPolicies)}
TestHHSI@ EQV GETPUT(NewHHNumberOfPolicies%,OldHHNumberOfPolicies%,HHNumberPolicies,{HHNumberOfPolicies%},{})

!HHSumTotal=sum(HHSumsInsured%)

! The rest of the attributes

HHSumsInsured%:=MultLists(HHSumInsuredLevels%,HHNumberOfPolicies%)
HHPatterns% := genRandGManyLists(HHPatternMeans%, HHPatternsDevs%, HHNum, GenHHStep2@)
HHPremiums% = genRandGList(HHPremiumMean, HHPremiumDev, HHNum, Logstate(HHPatterns%))
HHActualPremiums%:=MultLists(HHPremiums%,HHSumsInsured%)
TotalPremiums=SUM(HHActualPremiums%)
HHCosts% = genRandGList(HHCostMean, HHCostDev, HHNum, Logstate(HHActualPremiums%))
HHActualCosts% =MultLists(HHCosts%,HHActualPremiums%)
TotalCosts=SUM(HHActualCosts%)
HHPMLs% = genRandGList(HHPMLMean, HHPMLDev, HHNum, Logstate(HHActualCosts%))
HHActualPMLs%:=MultLists(HHPMLs%,HHActualPremiums%)

! The excess damage caused by floods per analysis year

HHYearlyFloodsImpact%:=MultLists( YearlyNumberOfFloods%,YearlyFloodHHDamage% )

! The excess damage caused by fires per analysis year

HHYearlyStormsImpact%:= MultLists(YearlyNumberOfStorms%,YearlyStormHHDamage%)

! Total

HHCatImpact%:=SumLists(HHYearlyFloodsImpact%,HHYearlyStormsImpact%)

! Generate a list of yearly claims for every analysis year

HHClaimSizes% = genRandGList(HHClaimSizeMean,HHClaimSizeDev,HHNum, Logstate(HHActualPMLs%))
HHBasicClaims% = MultLists(HHActualPremiums%,HHClaimSizes%)
ThisYearImpact := HHCatImpact%[ThisYear] * 1000000
HHClaims% =AmplifyClaims(HHBasicClaims%,ThisYearImpact )
AddedClaims@ EQV ClaimsToCash(ASK(TotalClaimsCashflow%),HHClaims%,HHPatterns%,ThisYear)
AddedPremiums@ EQV AddToCashflow(ASK(TotalPremiumsCashflow%), TotalPremiums,ThisYear,AddedClaims@ )
AddedCosts@ EQV AddToCashflow(ASK(TotalCostsCashflow%),TotalCosts,ThisYear,AddedPremiums@)
IF AddedCosts@ then HHRets%:= DuplicateList(HHClaims%)

! Pack policies and claims in a tructure

HHPolicies% = MembersReady(HHSumInsuredLevels%,HHNumberOfPolicies%, HHPatterns%, HHActualPremiums%, HHActualCosts%, HHActualPMLs%, HHClaims%, HHRets%)

End !HHClaimsGenerator@

! Accidents - normally distributed sums insured and claims

ACCClaimsGenerator@ begin

! Re-generate Accident policies/claims . Triggered by GenerateACCPolicies@, finish by ACCPoliciesGenerated@

GenerateACCPolicies@ EQV GenACCStep1@
ACCPoliciesGenerated@ EQV Logstate(ACCPolicies%)

! Connect to CatGenerator@ block

ConnectAnalysisYears@ eqv AnalysisYears = ASK(AnalysisYears)

! The variable ThisYear is taken from the index of the FORNEST in the control block

ThisYear := ASK(ThisYear)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Accident
! Input variables for Accident policies. PMLMean is in percent of the premium. CPSizeDev is a percentage in fraction.

AccidentInfo% = {ACCNum, ACCSizeMean, ACCSizeDev, ACCPatternMeans%, ACCPatternsDevs%, ACCPremiumMean, ACCPremiumDev, ACCCostMean, ACCCostDev, ACCPMLMean, ACCPMLDev}

! Input vars for Accident claims - catastrophy impact on claims sizes is in percentage

ACCClaimsGeneralInfo% = {ACCClaimSizeMean,ACCClaimSizeDev}

! Policies attributes

ACCSumsInsured%:=genRandGList(ACCSizeMean,ACCSizeDev,ACCNum,GenACCStep1@)
ACCNumPolicies%:=MakeList('',{1..ACCNum},'NUMERIC',{ACCNumPolicies%,1})
ACCPatterns% := genRandGManyLists(ACCPatternMeans%, ACCPatternsDevs%, ACCNum, Logstate(ACCSumsInsured%))
ACCPremiums% = genRandGList(ACCPremiumMean, ACCPremiumDev, ACCNum, Logstate(ACCPatterns%))
ACCActualPremiums%:=MultLists(ACCPremiums%,ACCSumsInsured%)
TotalPremiums=SUM(ACCActualPremiums%)
ACCCosts% = genRandGList(ACCCostMean, ACCCostDev, ACCNum, Logstate(ACCActualPremiums%))
ACCActualCosts% =MultLists(ACCCosts%,ACCActualPremiums%)
TotalCosts=SUM(ACCActualCosts%)
ACCPMLs% = genRandGList(ACCPMLMean, ACCPMLDev, ACCNum, Logstate(ACCActualCosts%))
ACCActualPMLs%:=MultLists(ACCPMLs%,ACCActualPremiums%)

! Generate a list of yearly claims for every analysis year

ACCClaimSizes% = genRandGList(ACCClaimSizeMean,ACCClaimSizeDev,ACCNum, Logstate(ACCActualPMLs%))
ACCClaims% = MultLists(ACCActualPremiums%,ACCClaimSizes%)
AddedPremiums@ EQV AddToCashflow(ASK(TotalPremiumsCashflow%), TotalPremiums,ThisYear,AddedClaims@ )
AddedCosts@ EQV AddToCashflow(ASK(TotalCostsCashflow%),TotalCosts,ThisYear,AddedPremiums@)
if AddedCosts@ then ACCRets%:=DuplicateList(ACCClaims%)
AddedClaims@ EQV ClaimsToCash(ASK(TotalClaimsCashflow%),ACCClaims%,ACCPatterns%,ThisYear)

! Pack policies and claims in a tructure

ACCPolicies% = MembersReady(ACCSumsInsured%,ACCNumPolicies%, ACCPatterns%, ACCActualPremiums%, ACCActualCosts%, ACCActualPMLs%, ACCClaims%, ACCRets%)

End !ACCClaimsGenerator@

! Motor - sums insured taken from a history distribution, normally distributed claims

MTClaimsGenerator@ begin

! Re-generate Motor policies/claims . Triggered by GenerateMOTPolicies@, finish by MOTPoliciesGenerated@

DoneGenMOTStep0@ EQV SEQUENCE(GenMOTStep0@,GenerateMOTPolicies@,True,False)
DoneGenMOTStep1@ EQV SEQUENCE(GenMOTStep1@,DoneGenMOTStep0@,True,False)
DoneGenMOTStep2@ EQV SEQUENCE(GenMOTStep2@,DoneGenMOTStep1@,True,False)
MOTPoliciesGenerated@ EQV DoneGenMOTStep2@

! Connect to CatGenerator@ block

ConnectAnalysisYears@ eqv AnalysisYears = ASK(AnalysisYears)

! The variable ThisYear is taken from the index of the FORNEST in the control block

ThisYear := ASK(ThisYear)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Motor

MotorInfo% = {MOTSizeDev, MOTPatternMeans%, MOTPatternsDevs%, MOTPremiumMean, MOTPremiumDev, MOTCostMean, MOTCostDev, MOTPMLMean, MOTPMLDev}

! Input vars for Motor claims - catastrophy impMOTt on claims sizes is in percentage

MOTClaimsGeneralInfo% = {MOTClaimSizeMean,MOTClaimSizeDev}

! Create a list out of the range of the sums insured distribution. It will be used in the generation.

GotList@ EQV GETPUT(NewSumsInsuredList%,OldSumsInsuredList%,GenMOTStep0@,{MOTSumInsuredList%},{})
if Logstate(OldSumsInsuredList%) then NewSumsInsuredList% = LIST(MOTSumInsured)
MOTNum :=SIZE(MOTSumInsuredList%)

! Activate the generation of the policies sums insured. Activated by the SEQUENCE strucure controling the policies generation

StartupMOTSIReset := ResetVar({StartupMOTSI@},GenMOTStep1@)
GenerateMOTSumsInsured@ EQV Demon(StartupMOTSIReset)

! Policies attributes -
! Sums insured - here, a distribution on MOTSumsInsured is used to create SumsInsured

GenerateMOTSumsInsured@ eqv FORNEST({{iMOTSI,0,MOTNum}},TestMOTSI@,MoveMOTSI@,StartupMOTSI@,InitialiseMOTSI@)
logstate(iMOTSI) EQV ( MAX(1,iMOTSI) = iMOTSIind ) AND ( MOTSumInsured:= MOTSumInsuredList%[iMOTSIind] ) AND (MOTSIDev:=MOTSumInsured * MOTSizeDev) AND ( MOTNumberPolicies:=EXTRACT(MOTSumInsured,'MAX',1) ) AND (MOTActualSumInsured:=Randg(MOTSumInsured,MOTSIDev) * MOTNumberPolicies)
if InitialiseMOTSI@ then NewMOTNumberOfPolicies% = {} else NewMOTNumberOfPolicies% = OldMOTNumberOfPolicies% + {EVAL(MOTNumberPolicies)}
TestMOTSI@ EQV GETPUT(NewMOTNumberOfPolicies%,OldMOTNumberOfPolicies%,MOTNumberPolicies,{MOTNumberOfPolicies%},{})
MOTSumsInsured%:=MultLists(MOTSumInsuredList%,MOTNumberOfPolicies%)
MOTPatterns% := genRandGManyLists(MOTPatternMeans%, MOTPatternsDevs%, MOTNum, GenMOTStep2@)
MOTPremiums% = genRandGList(MOTPremiumMean, MOTPremiumDev, MOTNum, Logstate(MOTPatterns%))
MOTActualPremiums%:=MultLists(MOTPremiums%,MOTSumsInsured%)
TotalPremiums=SUM(MOTActualPremiums%)
MOTCosts% = genRandGList(MOTCostMean, MOTCostDev, MOTNum, Logstate(MOTActualPremiums%))
MOTActualCosts% =MultLists(MOTCosts%,MOTActualPremiums%)
TotalCosts=SUM(MOTActualCosts%)
MOTPMLs% = genRandGList(MOTPMLMean, MOTPMLDev, MOTNum, Logstate(MOTActualCosts%))
MOTActualPMLs%:=MultLists(MOTPMLs%,MOTActualPremiums%)

! Generate a list of yearly claims for every analysis year

MOTClaimSizes% = genRandGList(MOTClaimSizeMean,MOTClaimSizeDev,MOTNum, Logstate(MOTActualPMLs%))
MOTClaims% = MultLists(MOTActualPremiums%,MOTClaimSizes%)
if AddedCosts@ then MOTRets%:=DuplicateList(MOTClaims%)
AddedClaims@ EQV ClaimsToCash(ASK(TotalClaimsCashflow%),MOTClaims%,MOTPatterns%,ThisYear)
AddedPremiums@ EQV AddToCashflow(ASK(TotalPremiumsCashflow%), TotalPremiums,ThisYear,AddedClaims@ )
AddedCosts@ EQV AddToCashflow(ASK(TotalCostsCashflow%),TotalCosts,ThisYear,AddedPremiums@)

! PMOTk policies and claims in a tructure

MOTPolicies% = MembersReady(MOTSumInsuredList%,MOTNumberOfPolicies%, MOTPatterns%, MOTActualPremiums%, MOTActualCosts%, MOTActualPMLs%, MOTClaims%, MOTRets%)

End !MTClaimsGenerator@

MSACCESS1@ Begin

FloodCP@ Begin

! triggering by the Cat generator block

Likelihood:=RANDOM(1,LOGSTATE(TriggerRandom))

End !FloodCP@

FloodHH@ Begin

Likelihood=ASK(Likelihood)

End !FloodHH@

StormCP@ Begin

! triggering by the Cat generator block

Likelihood:=RANDOM(1,LOGSTATE(TriggerRandom))

End !StormCP@

StormHH@ Begin

! triggering by the Cat generator block

Likelihood=ASK(Likelihood)

End !StormHH@

End !MSACCESS1@

! Complex structures views

Views@ begin

Views% = {Retentions_vs_Time%, Retentions_vs_Policies%, Retentions_vs_Groups%}
Retentions_vs_Time% = Retentions_vs_time(Ret_Time_Input%)
Retentions_vs_Policies% = Retentions_vs_Pol(Ret_Pol_Input%)

End !Views@

End !RIProgramV2_4@