percentile boxPlot

Comparative Analysis of Stock Volatility Across Market Sectors

Scénario de test & Cas d'usage

Business Context

A financial investment firm needs to assess and compare the risk profile of different market sectors. The goal is to analyze the daily return volatility of representative stocks within each sector to inform asset allocation strategies. A wider distribution and more outliers suggest higher risk.
About the Set : percentile

Precise calculation of percentiles and quantiles.

Discover all actions of percentile
Data Preparation

Creation of a simulated dataset representing daily stock returns for various stocks across three market sectors: Technology, Healthcare, and Financials.

Copied!
1DATA casuser.stock_returns;
2 call streaminit(123);
3 DO sector_id = 1 to 3;
4 IF sector_id = 1 THEN sector = 'Technology';
5 ELSE IF sector_id = 2 THEN sector = 'Healthcare';
6 ELSE sector = 'Financials';
7 DO stock_id = 1 to 50;
8 DO day = 1 to 252; /* Trading days in a year */
9 IF sector = 'Technology' THEN daily_return = (rand('NORMAL', 0.05, 0.8));
10 ELSE IF sector = 'Healthcare' THEN daily_return = (rand('NORMAL', 0.02, 0.4));
11 ELSE daily_return = (rand('NORMAL', 0.03, 0.6));
12 OUTPUT;
13 END;
14 END;
15 END;
16 keep sector stock_id day daily_return;
17RUN;

Étapes de réalisation

1
Load the simulated stock returns data into an in-memory CAS table.
Copied!
1 
2PROC CASUTIL;
3load
4DATA=casuser.stock_returns outcaslib='casuser' casout='stock_returns' replace;
5QUIT;
6 
2
Execute the boxPlot action, grouping by the 'sector' variable to calculate distribution statistics for the 'daily_return' of each sector.
Copied!
1PROC CAS;
2 percentile.boxPlot /
3 TABLE={name='stock_returns', groupBy={'sector'}},
4 inputs={{name='daily_return'}};
5RUN;

Expected Result


The action returns a result table containing distinct box plot statistics (Q1, median, Q3, min, max) for the 'daily_return' variable for each market sector. The 'Technology' sector is expected to show a wider interquartile range and higher whisker values, confirming higher volatility compared to 'Healthcare'.