Introduction
SAS Risk Engine on Viya provides a modern, cloud-native toolkit for financial institutions to measure, manage, and mitigate risk, with simulations as one of its core strengths. Since financial markets are inherently uncertain and shaped by many interacting factors, simulations are essential for modeling this uncertainty and estimating potential losses or exposures under varied conditions. Leveraging high-performance computing, advanced analytics, and flexible deployment, SAS Risk Engine executes large-scale simulations with speed and efficiency. Beyond the capabilities of PROC RISK, it delivers greater flexibility, scalability, and seamless CAS integration, supporting sophisticated analyses on massive datasets and enabling faster responses to regulatory and market changes.
This article illustrates simulation examples using the syntax for riskSim action set, a core part of SAS Risk Engine. With riskSim, users can run sensitivity analyses, generate scenarios, perform historical and Monte Carlo simulations, model market factors stochastically and much more. Sensitivity tests show portfolio reactions to factor shifts, scenarios assess hypothetical shocks, and simulations capture outcome distributions under uncertainty. This article assumes readers have a basic understanding of SAS Risk Engine action sets, sequential workflows, and the use of environment tables, market data, historical data, and scenario states. Together, these components form a robust framework for assessing risk in both normal and stressed market conditions.
For detailed information on the SAS Risk Engine,
risk-related action sets,
and guidance on interpreting outputs,
please refer to the following:
Using the SAS Risk Engine Interface
Programming with SAS Risk Engine
A Brief on RiskSim Action Set
The Risk Factor Simulation (riskSim) action set provides a comprehensive framework for generating market states and calculating related artifacts that underpin simulations, sensitivity analyses, and scenario testing in SAS Risk Engine.
The riskSim action set enables you to simulate the behavior of market risk factors. Depending on the analysis type, risk factors can be shocked deterministically (for sensitivity and delta-normal analysis) or stochastically (for covariance and Monte Carlo simulations).
The following table provides an overview of available actions in riskSim action set. The table highlights what each action does and how it fits into practical risk analysis workflows — from preparing data (calcReturns, calcCorrelation), to building shocks (genScenarioStates), to running sensitivity and simulation analyses (genSensitivities, genSimulation), and finally transforming data for modeling (transformRiskFactors).
Action
Purpose
Example Use Case
calcCorrelation
Calculates the correlation or covariance matrix of selected risk factors using historical data.
Estimate the covariance matrix of USD interest rates and equity indices to use in VaR calculations.
calcReturns
Computes returns of market factors from historical price or level data.
Convert daily closing prices of SP500 into daily log returns for volatility analysis.
genScenarioStates
Generates market states under user-defined stress or hypothetical scenarios.
Create a “RateUp100bp” scenario where USD interest rates shift up by 1% and SP500 falls 10%.
genSensitivities
Calculates portfolio sensitivities (deltas, gammas) with respect to specified risk factors.
Compute how a bond portfolio’s value changes when 6M or 12M USD rates move slightly.
genSimulation
Produces simulated market states using historical simulation, Monte Carlo, or stochastic processes.
Simulate 1000 paths of future SP500 and USD rates using a Geometric Brownian Motion model.
transformRiskFactors
Applies mathematical transformations to market factors (e.g., scaling, shifting, or decorrelating) through methods.
Convert correlated equity and bond returns into uncorrelated principal components.
Specific Examples for Typical Market Risk Analysis
In risk management, analysts rely on a range of quantitative methods to evaluate how market movements, credit events, or external shocks could affect portfolio value. Each technique serves a unique purpose, from sensitivity testing to full-scale simulations. Below is a brief overview of key terms and methods along with sample syntax that form the foundation of market risk analysis. Note that the syntax is limited to riskSim related actions. For full analysis users must use other actions sets like riskMethods, riskRun and riskResults in a logical sequence to get the full picture. Refer to the training programs mentioned in the article or refer to the SAS official Help Documentation for more guidance.
Sensitivity Analysis
Sensitivity analysis measures how much a portfolio’s value changes when a particular risk factor shifts, while all other factors remain constant. This approach helps identify which variables exert the greatest influence on outcomes and provides a direct way to understand exposure to individual risks. For example, measuring how a bond portfolio’s value drops when interest rates rise by 1%, while credit spreads and FX rates are unchanged.
Typical Syntax:
This PROC CAS code is using the riskSim.genSensitivities action from the Risk Simulation (riskSim) action set in SAS Viya.
Illustration of Syntax for Generating Sensitivities.
The riskSim.genSensitivities action in PROC CAS is used to calculate first- and second-order sensitivities of a portfolio or instrument with respect to selected risk factors. In this example, the input environment (Portfolio_envTbl) and current market data (Portfolio_currMktData) are provided, and the analysis is restricted to specific factors—USD_RATES, USD_6M, USD_12M, and USD_36M—to focus only on relevant interest rate points. The options parameter sets the context and calculation controls: asOfDate specifies the valuation date, gammas=TRUE requests second-order sensitivities (convexity), while crossGammas=FALSE excludes cross-factor interactions. The epsilon value (0.002) determines the bump size for finite-difference perturbations, and hlowerbound (0.001) sets the minimum step size for the calculation. The results are stored in two output tables: Portfolio_sensEnv, which contains the updated environment with sensitivity definitions, and Portfolio_sensStates, which holds the generated shocked market states for the chosen factors.
Scenario Analysis
Often described as “what if” analysis, scenario analysis evaluates how a portfolio responds under predefined market conditions. For example, an analyst might model the effect of a sudden interest rate hike or a geopolitical event. By applying these scenarios, decision-makers gain insight into potential vulnerabilities and resilience under stress. Another simple example is estimating portfolio losses if oil prices spike by 20% due to a geopolitical shock.
Typical Syntax:
This code uses the riskSim.genScenarioStates action in SAS Viya is used to generate stressed or shifted market states (scenarios) based on specified factors and shock definitions. Note that risk factors and shock definitions are usually done using tools like SAS Risk Factor Manager. This is often used for scenario analysis such as “what happens if rates shift up 100bps” or “what if equity falls 10%. The riskSim.genScenarioStates action can simply read the tables and bring it to your analysis. Note that the action in itself is powerful and has the capability to compute variables based on a custom code as well. For more information and full syntax details click here.
The following code is a sample syntax for simply reading scenario input tables and bring them to your analysis.
Illustration of Generating Scenario States
This PROC CAS code uses the risksim.genScenarioStates action to generate scenario states for risk simulation. It takes a current market environment from the Portfolio_envTbl table and market data from the Portfolio_currMktData table as inputs. The scenarios block specifies a scenario input table (Portfolio_scenarios) containing predefined scenario perturbations, sets the analysis date (asOfDate) as January 01, 2025, and specifies an output table (Portfolio_scenStates) to store the generated scenario states, with replication=0 indicating only a single replication is written. The envOut parameter defines Portfolio_scenEnv as the output table to store any environment-related results from the action. In short, this code combines market data, environmental settings, and scenario and related perturbation definitions to produce a set of scenario states and related environment outputs for further risk analysis.
Historical Simulation
Historical simulation uses actual past market data to model possible future outcomes. It assumes that if similar conditions recur, portfolio values will change in ways consistent with historical patterns. This method is intuitive and data-driven, though it depends heavily on the relevance of past events to future market conditions. For example, recalculating a portfolio’s value using daily market moves from the 2008 financial crisis to see how it would perform under similar conditions.
Typical Syntax:
This PROC CAS code uses the riskSim.genSimulation action to generate simulated market states for risk analysis using historical simulation.
Illustration of Historical Simulation
This PROC CAS code uses the riskSim.genSimulation action to generate simulated market states for risk analysis. It takes current market data (Portfolio_currMktData) and historical data (Portfolio_histData) as inputs and produces simulated environments and states for further valuation or stress testing. The results are written to two outputs: an updated environment table (Portfolio_envSim), which stores simulation configuration details, and a scenario states table (Portfolio_scenStates), which contains the generated simulated paths and replaces any existing data. Simulation behavior is controlled by the options: nHorizons=4 specifies the number of forecast horizons, nDraws=101 sets the number of simulation paths, and seed=54321 ensures reproducibility by fixing the random number generator. The asOfDate marks the starting point of the simulation (January 1, 2025), interval='DAY' defines daily time steps, and analysisType='HISTSIM' indicates that historical simulation is used, meaning scenarios are generated by resampling historical market data instead of relying solely on statistical modeling.
Scenario Simulation
Scenario simulation combines the flexibility of scenario analysis with the statistical rigor of simulation. Instead of using historical data or purely random draws, it models portfolio outcomes based on a user-specified distribution of possible market movements. This approach allows analysts to design simulations that reflect forward-looking expectations or expert judgment. For example, modeling portfolio outcomes under a hypothetical distribution where equity markets have a 40% chance of a 10% drop and a 60% chance of a 5% rise.
Typical Syntax:
The riskSim.genSimulation action in PROC CAS is used to generate simulated market scenarios for risk analysis. In this example, the code creates multiple future market states based on current and historical data, with controlled randomness and variance reduction techniques.
Illustration of Scenario Simulation
This PROC CAS code runs the riskSim.genSimulation action to generate simulated market states using both current and historical market data. The action takes Portfolio_currMktData as the current market input and Portfolio_histData as the historical reference data, then produces two outputs: an updated environment table (Portfolio_envSim) that stores the simulation setup, and a states table (Portfolio_scenStates) that contains the simulated scenarios, replacing any existing data. The simulation settings are defined in the options block: nHorizons=4 specifies four forecast points into the future, nDraws=101 generates 101 random simulation paths, and seed=54321 ensures reproducibility of results. The asOfDate sets the simulation start date to January 01, 2025, and interval='DAY' defines daily simulation steps. Unlike the historical simulation example, this code uses the Mersenne Twister random number generator (generator='TWISTER') to create simulated draws and enables useAntithetic=TRUE, which applies variance reduction by pairing random draws with their opposites to stabilize simulation outcomes.
Monte Carlo Simulation
Monte Carlo simulation employs statistical models to generate a wide range of potential future market movements. By running thousands or even millions of randomized trials, analysts can estimate the probability distribution of portfolio value changes. For example, running 1000 randomized paths of equity price and volatility changes to estimate the distribution of portfolio returns. Unlike historical simulation, Monte Carlo simulation can incorporate complex correlations and non-linear risk factors, but it requires strong modeling assumptions.
Typical Syntax:
This PROC CAS code uses the riskSim.genSimulation action to generate simulated market states with enhanced flexibility by including a stochastic process specification table.
Illustration of Monte Carlo Simulation
The inputs are current market data (Portfolio_currMktData), historical data (Portfolio_histData), and process specifications (Portfolio_processSpecs), which define the stochastic models—such as Geometric Brownian Motion or Hull–White—that drive the evolution of risk factors. The outputs include an updated environment table (Portfolio_envSim), which stores the simulation configuration, and a scenario states table (Portfolio_scenStates), which contains the generated scenarios and replaces any existing table with the same name. Simulation options specify four forecast horizons (nHorizons=4), 1000 random draws (nDraws=1000), and reproducibility through a fixed random seed (seed=54321). The asOfDate is set to January 01, 2025, with a daily interval (interval='DAY'). The simulation uses the Mersenne Twister random number generator (generator='TWISTER'), and variance reduction is enabled through antithetic variates (useAntithetic=TRUE), which improve the stability and efficiency of simulation outcomes. The key highlight of the above method is usage of stochastic process specification table.
Example of Stochastic Process Specification Table
Consider the following code:
Illustration of Stochastic Specification Table
This DATA step creates the stochasticProcessSpecs table in the CASUSER caslib, which defines the stochastic processes and their parameters for different risk factors. Each row specifies a model (such as Geometric Brownian Motion, Brownian Motion, Cox–Ingersoll–Ross, or Vasicek), the associated risk factor (e.g., HPI, VIX, DOW, SP500), and parameter values like drift, volatility (sigma), mean, or mean reversion rate. These specifications tell the riskSim.genSimulation action how to evolve each risk factor over time when generating simulated market state.
The following table provides an overview of stochastic process or stochastic models supported in the riskSim action set.
Process
Description
Key Parameters
Simple Example
Brownian Motion (BM)
A random walk with continuous paths and normally distributed increments.
Drift (trend), σ (volatility).
Stock price moving randomly with no mean reversion: S(t) = S(0) + drift·t + σW(t)
Cox–Ingersoll–Ross (CIR)
Mean-reverting process with strictly non-negative values (used for interest rates).
Mean reversion rate, long-term mean, volatility.
Short-term interest rate pulled toward 5% but fluctuates randomly above/below it.
Geometric Brownian Motion (GBM)
Multiplicative Brownian motion, ensures positive values (commonly used for stocks).
Drift, σ (volatility).
Stock price evolving lognormally: S(t) = S(0)·exp((μ−σ²/2)t + σW(t))
Hull–White One Factor
An extension of Vasicek with time-dependent parameters; used for term structure.
Mean reversion, volatility, time-dependent drift.
Interest rate curve where short rate reverts to a moving mean over time.
Ornstein–Uhlenbeck (OU)
Mean-reverting Gaussian process, can take negative values.
Mean reversion rate, long-term mean, volatility.
Commodity price fluctuating around $50, sometimes dipping below zero in the model.
Rendleman–Bartter (RB)
Exponential Brownian motion with deterministic drift; no randomness in variance.
Drift, volatility.
Bond price modeled as exponential growth with volatility shocks.
Vasicek
Mean-reverting Gaussian process for interest rates; can allow negative rates.
Mean reversion rate, long-term mean, volatility.
Short rate fluctuating around 3%, sometimes going below zero due to normal shocks.
Note that similar capabilities also exist in a Python based environment for SAS Risk Engine. To learn more about how Python and SAS Risk Engine interact, click here.
Conclusion
The riskSim action set in SAS Risk Engine provides a powerful and flexible framework for conducting comprehensive risk simulations, ranging from simple sensitivity analyses to advanced stochastic and Monte Carlo modeling. By combining cloud-scale computation in SAS Viya with a wide suite of simulation and scenario-generation tools, financial institutions can efficiently support activities like assess portfolio exposures, stress test against extreme events, and model future uncertainty with greater accuracy. The examples in this article illustrate how riskSim actions—such as genSensitivities, genScenarioStates, and genSimulation—which fits into an end-to-end workflow for robust market risk management. Ultimately, SAS Risk Engine continues to empower analysts to move beyond static risk measurement toward dynamic, forward-looking insights that support more informed decision-making in today’s volatile financial landscape.
Find more articles from SAS Global Enablement and Learning here.
... View more