Scénario de test & Cas d'usage
Execution of SAS FCMP functions within the CAS environment.
Discover all actions of fcmpactCreate a sample table of financial instruments with metrics needed for risk calculations.
| 1 | DATA casuser.portfolio_assets(promote=yes); |
| 2 | LENGTH assetId $ 8; |
| 3 | INFILE DATALINES dsd; |
| 4 | INPUT assetId $ value volatility_pct liquidity_score; |
| 5 | DATALINES; |
| 6 | EQT45,1200000,25,0.9 |
| 7 | BND01,5000000,8,0.98 |
| 8 | DER99,750000,60,0.7 |
| 9 | ; |
| 10 | RUN; |
| 1 | PROC 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}; |
| 12 | RUN; |
| 1 | PROC 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; |
| 14 | RUN; |
| 1 | PROC 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'}; |
| 13 | RUN; |
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.