fcmpact addRoutines

Large-Scale Use Case: Appending Functions to a Financial Risk Library

Scénario de test & Cas d'usage

Business Context

A financial institution is building a centralized library of risk calculation functions. The library is built incrementally, with new functions being added by different teams. The final library must be persisted for use in nightly risk assessment jobs.
About the Set : fcmpact

Execution of SAS FCMP functions within the CAS environment.

Discover all actions of fcmpact
Data Preparation

Create a sample table of financial instruments with metrics needed for risk calculations.

Copied!
1DATA casuser.portfolio_assets(promote=yes);
2 LENGTH assetId $ 8;
3 INFILE DATALINES dsd;
4 INPUT assetId $ value volatility_pct liquidity_score;
5 DATALINES;
6EQT45,1200000,25,0.9
7BND01,5000000,8,0.98
8DER99,750000,60,0.7
9;
10RUN;

Étapes de réalisation

1
Initial deployment: Add a basic Value-at-Risk (VaR) function to the 'risk_library' table.
Copied!
1PROC CAS;
2 SESSION casauto;
3 fcmpact.addRoutines
4 routineCode={ 'function calculate_var(value, volatility, confidence_level);
5 /* Simplified VaR for testing */
6 z_score = 1.645; /* for 95% confidence */
7 if confidence_level = 99 then z_score = 2.326;
8 return (value * (volatility/100) * z_score);
9 endsub;' },
10 package='risk.models',
11 funcTable={name='risk_library', caslib='casuser', replace=true};
12RUN;
2
Second deployment: Append a new, more complex 'stress_test_loss' function to the existing 'risk_library' and persist the entire library to disk.
Copied!
1PROC CAS;
2 SESSION casauto;
3 fcmpact.addRoutines
4 routineCode={ 'function stress_test_loss(value, liquidity_score);
5 /* Simplified stress test based on liquidity */
6 if liquidity_score < 0.8 then return (value * 0.5);
7 else if liquidity_score < 0.95 then return (value * 0.3);
8 else return (value * 0.1);
9 endsub;' },
10 package='risk.models',
11 funcTable={name='risk_library', caslib='casuser'},
12 appendTable=true,
13 saveTable=true;
14RUN;
3
Verification: Use both functions from the now-comprehensive library in a single DATA step to confirm they are both available.
Copied!
1PROC CAS;
2 SESSION casauto;
3 DATA casuser.risk_analysis(promote=yes);
4 method RUN();
5 SET casuser.portfolio_assets;
6 var_95 = calculate_var(value, volatility_pct, 95);
7 stress_loss = stress_test_loss(value, liquidity_score);
8 END;
9 dcl package fcmpact('risk.models') p;
10 RUN;
11 
12 TABLE.fetch / TABLE={caslib='casuser', name='risk_analysis'};
13RUN;

Expected Result


The 'risk_library' table is created and then appended to. The final table is saved as a physical file in the 'casuser' caslib. The verification step runs without errors, producing a 'risk_analysis' table with 'var_95' and 'stress_loss' columns, proving both functions from separate 'addRoutines' calls are present and working in the final library.