SlideShare a Scribd company logo
1 of 6
/*	
  
Submitted	
  by:	
  Akanksha	
  Jain	
  
*/	
  
/*	
  
Project	
  Requirements:	
  
1)	
  Read	
  the	
  ASCII	
  data	
  file	
  into	
  SAS.	
  The	
  variable	
  names	
  are	
  date	
  (mmddyy8.)	
  
usdlr3m	
  usdlr2y	
  usdlr3y	
  usdlr5y	
  usdlr10y	
  gbplr3m	
  gbplr2y	
  gbplr3y	
  gbplr5y	
  
gbplr10y	
  demlr3m	
  demlr2y	
  demlr3y	
  demlr5y	
  demlr10y	
  (in	
  this	
  order).	
  	
  
2)	
  The	
  definitions	
  of	
  above	
  variables	
  are	
  that	
  they	
  are	
  log	
  of	
  daily	
  quote	
  ratio	
  of	
  
some	
  currencies.	
  
3)	
  In	
  your	
  program,	
  build	
  a	
  filter	
  for	
  potentially	
  bad	
  data	
  of	
  variable	
  Date	
  and	
  flag	
  a	
  
warning	
  for	
  that	
  observation	
  in	
  the	
  log.	
  For	
  example,	
  if	
  the	
  date	
  has	
  a	
  value	
  of	
  
10/32/89,	
  then	
  this	
  record	
  should	
  be	
  identified,	
  and	
  a	
  waning	
  flag	
  should	
  be	
  issued.	
  
4)	
  Calculate	
  the	
  volatility	
  for	
  each	
  random	
  variable	
  and	
  correlation	
  matrix	
  for	
  all	
  the	
  
random	
  variables	
  for	
  a	
  length	
  of	
  time	
  period	
  (one	
  month,	
  for	
  example),	
  let's	
  call	
  it	
  a	
  
time	
  window.	
  The	
  volatility	
  and	
  correlation	
  coefficient	
  matrix	
  need	
  to	
  be	
  output	
  into	
  
a	
  flat	
  ASCII	
  file.	
  The	
  time	
  window	
  that	
  we	
  want	
  to	
  calculate	
  volatility	
  from	
  moves	
  
over	
  time	
  on	
  a	
  weekly	
  basis.	
  The	
  volatility	
  is	
  defined	
  as	
  standard	
  deviation	
  of	
  the	
  
above	
  variables	
  (except	
  date,	
  a	
  nonrandom	
  variable).	
  Note:	
  the	
  volatility	
  calculation	
  
here	
  is	
  based	
  on	
  daily	
  data;	
  the	
  volatility	
  you	
  need	
  to	
  get	
  is	
  annualized,	
  which	
  can	
  be	
  
done	
  by	
  multiplying	
  a	
  factor	
  of	
  square	
  root	
  of	
  250	
  to	
  the	
  daily	
  volatility.	
  
5)	
  Relax	
  the	
  above	
  specifications	
  to	
  allow	
  (1)	
  the	
  weekly	
  basis	
  to	
  vary	
  to	
  any	
  
number	
  of	
  days	
  (2)	
  the	
  length	
  of	
  a	
  time	
  period	
  to	
  vary	
  to	
  any	
  number	
  of	
  days.	
  
6)	
  Output	
  the	
  lower	
  triangle	
  of	
  correlation	
  coefficient	
  matrix	
  (including	
  the	
  diagonal	
  
elements)	
  for	
  each	
  time	
  window	
  of	
  all	
  the	
  above	
  random	
  variables	
  into	
  a	
  flat	
  file.	
  
*/	
  
	
  
options	
  mlogic	
  mprint	
  symbolgen	
  nonumber	
  nodate;	
  
	
  
filename	
  mylib	
  'Z:BerkeleyAdvanced_SAS_Project';	
  
	
  
data	
  currency;	
  
	
  
infile	
  mylib('output.txt');	
  
input	
  date	
  mmddyy8.	
  usdlr3m	
  usdlr2y	
  usdlr3y	
  usdlr5y	
  usdlr10y	
  gbplr3m	
  
gbplr2y	
  gbplr3y	
  gbplr5y	
  gbplr10y	
  demlr3m	
  demlr2y	
  demlr3y	
  demlr5y	
  
demlr10y;	
  
	
  
format	
  date	
  mmddyy8.;	
  
	
  
year_	
  =	
  year(date);	
  
	
  
month_	
  =	
  month(date);	
  
	
  
day_	
  =	
  day(date);	
  
run;	
  
	
  
proc	
  print	
  data	
  =	
  currency;	
  
	
  
title	
  'data	
  set	
  Currency	
  -­‐	
  reading	
  an	
  ASCII	
  file	
  into	
  a	
  SAS	
  data	
  set';	
  
run;	
  
	
  
proc	
  contents	
  data	
  =	
  currency;	
  
run;	
  
	
  
proc	
  sort	
  data	
  =	
  currency;	
  
	
  
by	
  date;	
  
run;	
  
	
  
filename	
  ann_vol	
  'Z:BerkeleyAdvanced_SAS_Projectann_vol.txt';	
  	
  
	
  
/*	
  
Macro	
  VOL_CORR	
  does	
  the	
  following:	
  
1)	
  Uses	
  the	
  data	
  set	
  CURRENCY	
  (which	
  is	
  created	
  from	
  an	
  ASCII	
  file	
  and	
  has	
  
variables:	
  
Date	
  (mmddyy8.)	
  usdlr3m	
  usdlr2y	
  usdlr3y	
  usdlr5y	
  usdlr10y	
  gbplr3m	
  gbplr2y	
  
gbplr3y	
  gbplr5y	
  gbplr10y	
  demlr3m	
  demlr2y	
  demlr3y	
  demlr5y	
  demlr10y).	
  These	
  
variables	
  are	
  the	
  log	
  of	
  daily	
  quote	
  ratio	
  of	
  some	
  currencies.	
  
2)	
  Flags	
  a	
  warning	
  in	
  the	
  log	
  if	
  the	
  date	
  has	
  a	
  bad	
  value	
  such	
  as	
  10/32/89,	
  and	
  
creates	
  a	
  variable	
  flag_bad	
  which	
  will	
  have	
  a	
  value	
  'Y'	
  if	
  the	
  Date	
  value	
  is	
  bad	
  or	
  'N'	
  if	
  
not.	
  
3)	
  Calculates	
  the	
  annualized	
  volatility	
  for	
  the	
  given	
  variables	
  for	
  a	
  given	
  time	
  
window	
  and	
  leap-­‐	
  uses	
  macro	
  VOLATILITY.	
  
4)	
  Calculates	
  the	
  correlation	
  matrix	
  for	
  the	
  given	
  variables	
  for	
  a	
  given	
  time	
  window	
  
and	
  leap-­‐	
  uses	
  macro	
  CORRELATION.	
  
5)	
  Captures	
  the	
  lower	
  triangle	
  of	
  the	
  correlation	
  matrix	
  for	
  the	
  given	
  variables	
  for	
  a	
  
given	
  time	
  window	
  and	
  leap-­‐	
  uses	
  macro	
  CORR_LOWTRI.	
  
6)	
  Prints	
  appropriate	
  titles	
  -­‐	
  uses	
  macro	
  TITLE_VOL	
  TITLE_CORR	
  
TITLE_CORR_LOWTRI.	
  
	
  
*/	
  
%macro	
  vol_corr(win_len,leap);	
  
data	
  cfinal;	
  
	
  
set	
  currency	
  end=last;	
  
	
  
if	
  month_	
  gt	
  12	
  or	
  day_	
  gt	
  31	
  then	
  do;	
  
	
  
	
  
put	
  'Warning:	
  Observation	
  number:	
  '	
  _n_	
  'has	
  bad	
  data';	
  
	
  
	
  
flag_bad	
  =	
  'Y';	
  
	
  
	
  
end;	
  
	
  
else	
  do;	
  
	
  
	
  
flag_bad	
  =	
  'N';	
  
	
  
end;	
  
	
  
format	
  date_first	
  date_last	
  date9.;	
  
	
  
if	
  _n_	
  =	
  1	
  then	
  do;	
  
	
  
	
  
date_first	
  =	
  date;	
  
	
  
	
  
put	
  'First	
  date	
  of	
  data	
  set	
  is:'	
  date_first;	
  
	
  
end;	
  
	
  
retain	
  date_first;	
  
	
  
if	
  last	
  then	
  do;	
  
 
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  

	
  
	
  

date_last	
  =	
  date;	
  
put	
  'Last	
  date	
  of	
  data	
  set	
  is:'	
  date_last;	
  
date_diff	
  =	
  (date_last-­‐	
  date_first);	
  
put	
  'Date	
  difference	
  in	
  days	
  is:'	
  date_diff;	
  
if	
  &leap	
  eq	
  0	
  then	
  do;	
  
	
  
put	
  'The	
  Leap	
  cannot	
  be	
  zero';	
  
end;	
  
else	
  do;	
  
	
  
n_time_windows	
  =	
  CEIL(date_diff/&leap);	
  
	
  
put	
  'Number	
  of	
  Time	
  windows	
  are:'	
  n_time_windows;	
  
	
  
c_date_last	
  =	
  put(date_last,	
  date9.);	
  
	
  
i	
  =0;	
  
	
  
do	
  until(i	
  ge	
  n_time_windows);	
  
	
  
	
  
put	
  'value	
  of	
  I	
  is:'	
  i;	
  
	
  
	
  
next_date	
  =	
  intnx('day',date_first,	
  &win_len);	
  
	
  
	
  
c_date_first	
  =	
  put(date_first,	
  date9.);	
  
	
  
	
  
c_next_date	
  =	
  put(next_date,	
  date9.);	
  
	
  
	
  
put	
  'char	
  start	
  date	
  is	
  c_date_first:'	
  c_date_first;	
  
	
  
	
  
put	
  'char	
  end	
  date	
  is	
  c_next_date:'	
  c_next_date;	
  
call	
  execute('%title_vol('||	
  c_date_first	
  
||','||c_next_date||')');	
  
call	
  execute('%volatility('||	
  c_date_first	
  
||','||c_next_date||')');	
  
call	
  execute('%title_corr('||	
  c_date_first	
  
||','||c_next_date||')');	
  
call	
  execute('%correlation('||	
  c_date_first	
  
||','||c_next_date||')');	
  
call	
  execute('%title_corr_lowtri('||	
  c_date_first	
  
||','||c_next_date||')');	
  
call	
  execute('%corr_lowtri('||	
  c_date_first	
  
||','||c_next_date||')');	
  
	
  
	
  
i=i+1;	
  
	
  
	
  
date_first	
  =	
  intnx('day',date_first,	
  &leap);	
  
put	
  'start	
  date	
  at	
  the	
  end	
  of	
  loop	
  for	
  next	
  iteration	
  is	
  
date_first:'	
  date_first;	
  
	
  
end;	
  
end;	
  

	
  
	
  
	
  
	
  
	
  
end;	
  
run;	
  
%mend	
  vol_corr;	
  
	
  
/*	
  
MACRO	
  FOR	
  CREATING	
  THE	
  ANNUALIZED	
  VOLATILITY	
  FOR	
  A	
  GIVEN	
  RANGE	
  OF	
  
DATES	
  
*/	
  
%macro	
  volatility(start_dt,	
  end_dt);	
  
proc	
  sql;	
  
	
  
select	
  std(usdlr3m)*sqrt(250)	
  as	
  STD_usdlr3m,	
  	
  
	
  
	
  
	
  
std(usdlr2y)*sqrt(250)	
  as	
  STD_usdlr2y,	
  	
  
	
  
	
  
	
  
std(usdlr3y)*sqrt(250)	
  as	
  STD_usdlr3y,	
  	
  
	
  
	
  
	
  
std(usdlr5y)*sqrt(250)	
  as	
  STD_usdlr5y,	
  	
  
	
  
	
  
	
  
std(usdlr10y)*sqrt(250)	
  as	
  STD_usdlr10y,	
  
	
  
	
  
	
  
std(gbplr3m)*sqrt(250)	
  as	
  STD_gbplr3m,	
  	
  
	
  
	
  
	
  
std(gbplr2y)*sqrt(250)	
  as	
  STD_gbplr2y,	
  
	
  
	
  
	
  
std(gbplr3y)*sqrt(250)	
  as	
  STD_gbplr3y,	
  
	
  
	
  
	
  
std(gbplr5y)*sqrt(250)	
  as	
  STD_gbplr5y,	
  
	
  
	
  
	
  
std(gbplr10y)*sqrt(250)	
  as	
  STD_gbplr10y,	
  
	
  
	
  
	
  
std(demlr3m)*sqrt(250)	
  as	
  STD_demlr3m,	
  
	
  
	
  
	
  
std(demlr2y)*sqrt(250)	
  as	
  STD_demlr2y,	
  
	
  
	
  
	
  
std(demlr3y)*sqrt(250)	
  as	
  STD_demlr3y,	
  
	
  
	
  
	
  
std(demlr5y)*sqrt(250)	
  as	
  STD_demlr5y,	
  
	
  
	
  
	
  
std(demlr10y)*sqrt(250)	
  as	
  STD_demlr10y	
  
	
  
	
  
from	
  cfinal	
  
	
  
	
  
where	
  date	
  between	
  "&start_dt"d	
  and	
  "&end_dt"d;	
  
	
  
	
  
	
  
quit;	
  
%mend	
  volatility;	
  
	
  
/*	
  
MACRO	
  FOR	
  CREATING	
  THE	
  CORRELATION	
  MATRIX	
  FOR	
  A	
  GIVEN	
  RANGE	
  OF	
  
DATES	
  
*/	
  
%macro	
  correlation(start_dt,	
  end_dt);	
  
proc	
  corr	
  data	
  =	
  cfinal	
  pearson	
  noprob	
  nosimple;	
  
var	
  usdlr3m	
  usdlr2y	
  usdlr3y	
  usdlr5y	
  usdlr10y	
  gbplr3m	
  gbplr2y	
  gbplr3y	
  
gbplr5y	
  gbplr10y	
  demlr3m	
  demlr2y	
  demlr3y	
  demlr5y	
  demlr10y;	
  
	
  
where	
  date	
  between	
  "&start_dt"d	
  and	
  "&end_dt"d;	
  
run;	
  
%mend	
  correlation;	
  
	
  
	
  
/*	
  
MACRO	
  FOR	
  PRINTING	
  THE	
  TITLE	
  "ANNUALIZED	
  VOLATILITY"	
  FOR	
  A	
  GIVEN	
  
RANGE	
  OF	
  DATES	
  
*/	
  
%macro	
  title_vol(start_dt,	
  end_dt);	
  
	
  
title	
  "Annualized	
  Volatility	
  for:	
  &start_dt	
  -­‐	
  	
  &end_dt"	
  ;	
  
%mend	
  title_vol;	
  
	
  
/*	
  
MACRO	
  FOR	
  PRINTING	
  THE	
  TITLE	
  "CORRELATION	
  MATRIX"	
  FOR	
  A	
  GIVEN	
  RANGE	
  
OF	
  DATES	
  
*/	
  
%macro	
  title_corr(start_dt,	
  end_dt);	
  
	
  
title	
  "Correlation	
  Matrix	
  for:	
  &start_dt	
  -­‐	
  	
  &end_dt"	
  ;	
  
%mend	
  title_corr;	
  
	
  
	
  
/*	
  
MACRO	
  FOR	
  PRINTING	
  THE	
  TITLE	
  "LOWER	
  TRIANGLE	
  OF	
  THE	
  CORRELATION	
  
MATRIX"	
  FOR	
  A	
  GIVEN	
  RANGE	
  OF	
  DATES	
  
*/	
  
%macro	
  title_corr_lowtri(start_dt,	
  end_dt);	
  
	
  
title	
  "Lower	
  Triangle	
  of	
  Correlation	
  Matrix	
  for:	
  &start_dt	
  -­‐	
  	
  &end_dt"	
  ;	
  
%mend	
  title_corr_lowtri;	
  
	
  
	
  
/*	
  
MACRO	
  FOR	
  CREATING	
  ONLY	
  THE	
  LOWER	
  TRIANGLE	
  OF	
  THE	
  CORRELATION	
  
MATRIX	
  FOR	
  A	
  GIVEN	
  RANGE	
  OF	
  DATES	
  
*/	
  
%macro	
  corr_lowtri(start_dt,	
  end_dt);	
  
proc	
  corr	
  data	
  =	
  cfinal	
  pearson	
  noprob	
  nosimple	
  noprint	
  outp	
  =	
  cfinal_corr;	
  
var	
  usdlr3m	
  usdlr2y	
  usdlr3y	
  usdlr5y	
  usdlr10y	
  gbplr3m	
  gbplr2y	
  gbplr3y	
  
gbplr5y	
  gbplr10y	
  demlr3m	
  demlr2y	
  demlr3y	
  demlr5y	
  demlr10y;	
  
	
  
where	
  date	
  between	
  "&start_dt"d	
  and	
  "&end_dt"d;	
  
run;	
  
	
  
data	
  corr_matrix_full;	
  
	
  
set	
  cfinal_corr;	
  
	
  
where	
  _TYPE_	
  =	
  "CORR";	
  
run;	
  
	
  
data	
  corr_array_lower	
  noobs;	
  
	
  
set	
  corr_matrix_full;	
  
array	
  full_tri	
  {*}	
  usdlr3m	
  usdlr2y	
  usdlr3y	
  usdlr5y	
  usdlr10y	
  gbplr3m	
  gbplr2y	
  
gbplr3y	
  gbplr5y	
  gbplr10y	
  demlr3m	
  demlr2y	
  demlr3y	
  demlr5y	
  demlr10y;	
  
	
  
do	
  i=1	
  to	
  dim(full_tri);	
  
	
  
	
  
if	
  i	
  gt	
  _n_	
  then	
  full_tri{i}=.;	
  
	
  
end;	
  
	
  
drop	
  i	
  _type_;	
  
run;	
  
	
  
proc	
  print	
  data	
  =	
  corr_array_lower	
  noobs;	
  
title	
  "Lower	
  Triangle	
  for	
  for:&start_dt	
  -­‐	
  	
  &end_dt";	
  
run;	
  
	
  
%mend	
  corr_lowtri;	
  
 
proc	
  printto	
  print=ann_vol	
  new;	
  	
  
run;	
  	
  
	
  
%vol_corr(60,60)	
  
	
  
	
  
	
  
	
  

More Related Content

Recently uploaded

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Tool to calculate Annualized Volatility over a period of time: SAS Macros, SQL Procedures and Arrays

  • 1. /*   Submitted  by:  Akanksha  Jain   */   /*   Project  Requirements:   1)  Read  the  ASCII  data  file  into  SAS.  The  variable  names  are  date  (mmddyy8.)   usdlr3m  usdlr2y  usdlr3y  usdlr5y  usdlr10y  gbplr3m  gbplr2y  gbplr3y  gbplr5y   gbplr10y  demlr3m  demlr2y  demlr3y  demlr5y  demlr10y  (in  this  order).     2)  The  definitions  of  above  variables  are  that  they  are  log  of  daily  quote  ratio  of   some  currencies.   3)  In  your  program,  build  a  filter  for  potentially  bad  data  of  variable  Date  and  flag  a   warning  for  that  observation  in  the  log.  For  example,  if  the  date  has  a  value  of   10/32/89,  then  this  record  should  be  identified,  and  a  waning  flag  should  be  issued.   4)  Calculate  the  volatility  for  each  random  variable  and  correlation  matrix  for  all  the   random  variables  for  a  length  of  time  period  (one  month,  for  example),  let's  call  it  a   time  window.  The  volatility  and  correlation  coefficient  matrix  need  to  be  output  into   a  flat  ASCII  file.  The  time  window  that  we  want  to  calculate  volatility  from  moves   over  time  on  a  weekly  basis.  The  volatility  is  defined  as  standard  deviation  of  the   above  variables  (except  date,  a  nonrandom  variable).  Note:  the  volatility  calculation   here  is  based  on  daily  data;  the  volatility  you  need  to  get  is  annualized,  which  can  be   done  by  multiplying  a  factor  of  square  root  of  250  to  the  daily  volatility.   5)  Relax  the  above  specifications  to  allow  (1)  the  weekly  basis  to  vary  to  any   number  of  days  (2)  the  length  of  a  time  period  to  vary  to  any  number  of  days.   6)  Output  the  lower  triangle  of  correlation  coefficient  matrix  (including  the  diagonal   elements)  for  each  time  window  of  all  the  above  random  variables  into  a  flat  file.   */     options  mlogic  mprint  symbolgen  nonumber  nodate;     filename  mylib  'Z:BerkeleyAdvanced_SAS_Project';     data  currency;     infile  mylib('output.txt');   input  date  mmddyy8.  usdlr3m  usdlr2y  usdlr3y  usdlr5y  usdlr10y  gbplr3m   gbplr2y  gbplr3y  gbplr5y  gbplr10y  demlr3m  demlr2y  demlr3y  demlr5y   demlr10y;     format  date  mmddyy8.;     year_  =  year(date);     month_  =  month(date);     day_  =  day(date);   run;     proc  print  data  =  currency;     title  'data  set  Currency  -­‐  reading  an  ASCII  file  into  a  SAS  data  set';   run;    
  • 2. proc  contents  data  =  currency;   run;     proc  sort  data  =  currency;     by  date;   run;     filename  ann_vol  'Z:BerkeleyAdvanced_SAS_Projectann_vol.txt';       /*   Macro  VOL_CORR  does  the  following:   1)  Uses  the  data  set  CURRENCY  (which  is  created  from  an  ASCII  file  and  has   variables:   Date  (mmddyy8.)  usdlr3m  usdlr2y  usdlr3y  usdlr5y  usdlr10y  gbplr3m  gbplr2y   gbplr3y  gbplr5y  gbplr10y  demlr3m  demlr2y  demlr3y  demlr5y  demlr10y).  These   variables  are  the  log  of  daily  quote  ratio  of  some  currencies.   2)  Flags  a  warning  in  the  log  if  the  date  has  a  bad  value  such  as  10/32/89,  and   creates  a  variable  flag_bad  which  will  have  a  value  'Y'  if  the  Date  value  is  bad  or  'N'  if   not.   3)  Calculates  the  annualized  volatility  for  the  given  variables  for  a  given  time   window  and  leap-­‐  uses  macro  VOLATILITY.   4)  Calculates  the  correlation  matrix  for  the  given  variables  for  a  given  time  window   and  leap-­‐  uses  macro  CORRELATION.   5)  Captures  the  lower  triangle  of  the  correlation  matrix  for  the  given  variables  for  a   given  time  window  and  leap-­‐  uses  macro  CORR_LOWTRI.   6)  Prints  appropriate  titles  -­‐  uses  macro  TITLE_VOL  TITLE_CORR   TITLE_CORR_LOWTRI.     */   %macro  vol_corr(win_len,leap);   data  cfinal;     set  currency  end=last;     if  month_  gt  12  or  day_  gt  31  then  do;       put  'Warning:  Observation  number:  '  _n_  'has  bad  data';       flag_bad  =  'Y';       end;     else  do;       flag_bad  =  'N';     end;     format  date_first  date_last  date9.;     if  _n_  =  1  then  do;       date_first  =  date;       put  'First  date  of  data  set  is:'  date_first;     end;     retain  date_first;     if  last  then  do;  
  • 3.                                                                                     date_last  =  date;   put  'Last  date  of  data  set  is:'  date_last;   date_diff  =  (date_last-­‐  date_first);   put  'Date  difference  in  days  is:'  date_diff;   if  &leap  eq  0  then  do;     put  'The  Leap  cannot  be  zero';   end;   else  do;     n_time_windows  =  CEIL(date_diff/&leap);     put  'Number  of  Time  windows  are:'  n_time_windows;     c_date_last  =  put(date_last,  date9.);     i  =0;     do  until(i  ge  n_time_windows);       put  'value  of  I  is:'  i;       next_date  =  intnx('day',date_first,  &win_len);       c_date_first  =  put(date_first,  date9.);       c_next_date  =  put(next_date,  date9.);       put  'char  start  date  is  c_date_first:'  c_date_first;       put  'char  end  date  is  c_next_date:'  c_next_date;   call  execute('%title_vol('||  c_date_first   ||','||c_next_date||')');   call  execute('%volatility('||  c_date_first   ||','||c_next_date||')');   call  execute('%title_corr('||  c_date_first   ||','||c_next_date||')');   call  execute('%correlation('||  c_date_first   ||','||c_next_date||')');   call  execute('%title_corr_lowtri('||  c_date_first   ||','||c_next_date||')');   call  execute('%corr_lowtri('||  c_date_first   ||','||c_next_date||')');       i=i+1;       date_first  =  intnx('day',date_first,  &leap);   put  'start  date  at  the  end  of  loop  for  next  iteration  is   date_first:'  date_first;     end;   end;             end;   run;   %mend  vol_corr;     /*   MACRO  FOR  CREATING  THE  ANNUALIZED  VOLATILITY  FOR  A  GIVEN  RANGE  OF   DATES   */   %macro  volatility(start_dt,  end_dt);  
  • 4. proc  sql;     select  std(usdlr3m)*sqrt(250)  as  STD_usdlr3m,           std(usdlr2y)*sqrt(250)  as  STD_usdlr2y,           std(usdlr3y)*sqrt(250)  as  STD_usdlr3y,           std(usdlr5y)*sqrt(250)  as  STD_usdlr5y,           std(usdlr10y)*sqrt(250)  as  STD_usdlr10y,         std(gbplr3m)*sqrt(250)  as  STD_gbplr3m,           std(gbplr2y)*sqrt(250)  as  STD_gbplr2y,         std(gbplr3y)*sqrt(250)  as  STD_gbplr3y,         std(gbplr5y)*sqrt(250)  as  STD_gbplr5y,         std(gbplr10y)*sqrt(250)  as  STD_gbplr10y,         std(demlr3m)*sqrt(250)  as  STD_demlr3m,         std(demlr2y)*sqrt(250)  as  STD_demlr2y,         std(demlr3y)*sqrt(250)  as  STD_demlr3y,         std(demlr5y)*sqrt(250)  as  STD_demlr5y,         std(demlr10y)*sqrt(250)  as  STD_demlr10y       from  cfinal       where  date  between  "&start_dt"d  and  "&end_dt"d;         quit;   %mend  volatility;     /*   MACRO  FOR  CREATING  THE  CORRELATION  MATRIX  FOR  A  GIVEN  RANGE  OF   DATES   */   %macro  correlation(start_dt,  end_dt);   proc  corr  data  =  cfinal  pearson  noprob  nosimple;   var  usdlr3m  usdlr2y  usdlr3y  usdlr5y  usdlr10y  gbplr3m  gbplr2y  gbplr3y   gbplr5y  gbplr10y  demlr3m  demlr2y  demlr3y  demlr5y  demlr10y;     where  date  between  "&start_dt"d  and  "&end_dt"d;   run;   %mend  correlation;       /*   MACRO  FOR  PRINTING  THE  TITLE  "ANNUALIZED  VOLATILITY"  FOR  A  GIVEN   RANGE  OF  DATES   */   %macro  title_vol(start_dt,  end_dt);     title  "Annualized  Volatility  for:  &start_dt  -­‐    &end_dt"  ;   %mend  title_vol;     /*   MACRO  FOR  PRINTING  THE  TITLE  "CORRELATION  MATRIX"  FOR  A  GIVEN  RANGE   OF  DATES  
  • 5. */   %macro  title_corr(start_dt,  end_dt);     title  "Correlation  Matrix  for:  &start_dt  -­‐    &end_dt"  ;   %mend  title_corr;       /*   MACRO  FOR  PRINTING  THE  TITLE  "LOWER  TRIANGLE  OF  THE  CORRELATION   MATRIX"  FOR  A  GIVEN  RANGE  OF  DATES   */   %macro  title_corr_lowtri(start_dt,  end_dt);     title  "Lower  Triangle  of  Correlation  Matrix  for:  &start_dt  -­‐    &end_dt"  ;   %mend  title_corr_lowtri;       /*   MACRO  FOR  CREATING  ONLY  THE  LOWER  TRIANGLE  OF  THE  CORRELATION   MATRIX  FOR  A  GIVEN  RANGE  OF  DATES   */   %macro  corr_lowtri(start_dt,  end_dt);   proc  corr  data  =  cfinal  pearson  noprob  nosimple  noprint  outp  =  cfinal_corr;   var  usdlr3m  usdlr2y  usdlr3y  usdlr5y  usdlr10y  gbplr3m  gbplr2y  gbplr3y   gbplr5y  gbplr10y  demlr3m  demlr2y  demlr3y  demlr5y  demlr10y;     where  date  between  "&start_dt"d  and  "&end_dt"d;   run;     data  corr_matrix_full;     set  cfinal_corr;     where  _TYPE_  =  "CORR";   run;     data  corr_array_lower  noobs;     set  corr_matrix_full;   array  full_tri  {*}  usdlr3m  usdlr2y  usdlr3y  usdlr5y  usdlr10y  gbplr3m  gbplr2y   gbplr3y  gbplr5y  gbplr10y  demlr3m  demlr2y  demlr3y  demlr5y  demlr10y;     do  i=1  to  dim(full_tri);       if  i  gt  _n_  then  full_tri{i}=.;     end;     drop  i  _type_;   run;     proc  print  data  =  corr_array_lower  noobs;   title  "Lower  Triangle  for  for:&start_dt  -­‐    &end_dt";   run;     %mend  corr_lowtri;  
  • 6.   proc  printto  print=ann_vol  new;     run;       %vol_corr(60,60)