Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Forecasting
- /
- Amihud (2002) Liquidity Measure

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-22-2017 04:56 PM
(6870 views)

Hello Folks

I am trying to implement the above-mentioned measure. It is very straightforward measure.

Liquidity od stock *i *__month __*t *day d is;

=(1/number of valid observations in month) * (sum[abs(return(i, t, d)/volume(i,t,d))]

further, no of valid observation in a month must be more than 10.

my date format is yyyymmdd and all my variables are daily based. I am having difficulty in calculating no of valid days in a month.

kindly give me some code which can calculate no of valid days in a month.

so far i tried these codes

data illiquid;

set crspd;

Liquidity=abs(returns)/abs(volume); run;

I have problem in calculating no of valid days in a month.

Need your help please .

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Because you have to count across multiple observations, you will need to take a few steps. This is only one approach ... SAS usually provides alternatives that also work.

(1) Add YEAR and MONTH to the data set.

This sample code assumes that your dates are SAS dates. If they are not, you will need to do this step differently.

data with_month;

set crspd;

year = year(date);

month =month(date);

run;

(2) Count "valid" dates per symbol, per month.

Since you haven't provided a definition of "valid", I will assume it means dates where volume > 0.

proc freq data=with_month;

tables symbol * year * month / noprint out=monthly_counts (drop=percent);

where volume > 0;

run;

(3) Sort your original data:

proc sort data=with_month;

by symbol year month;

run;

(4) Merge in the number of valid days:

data want;

merge with_month monthly_counts (rename=(count=n_valid_days) in=have_counts);

by symbol year month;

if have_counts=0 then n_valid_days=0;

run;

That at least gets you N_VALID_DAYS on each observation to work with. Presumably, you know where to go from there. (Or perhaps you need to post a new question at that point.)

15 REPLIES 15

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Good day

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello -

If you have access to SAS/ETS software you may want to use the TIMESERIES procedure - in particular the OUTSUM data set should be of interest.

Example:

proc timeseries data=sashelp.citiday outsum=work.outsum out=_null_;

id date interval=day accumulate=total;

var SNYDJCM;

run;

Thanks,

Udo

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

still thank you I think I was not able to communicate my issue properly. I will post the full codes as soon I arrange them with proper notes.

Have a good day

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Because you have to count across multiple observations, you will need to take a few steps. This is only one approach ... SAS usually provides alternatives that also work.

(1) Add YEAR and MONTH to the data set.

This sample code assumes that your dates are SAS dates. If they are not, you will need to do this step differently.

data with_month;

set crspd;

year = year(date);

month =month(date);

run;

(2) Count "valid" dates per symbol, per month.

Since you haven't provided a definition of "valid", I will assume it means dates where volume > 0.

proc freq data=with_month;

tables symbol * year * month / noprint out=monthly_counts (drop=percent);

where volume > 0;

run;

(3) Sort your original data:

proc sort data=with_month;

by symbol year month;

run;

(4) Merge in the number of valid days:

data want;

merge with_month monthly_counts (rename=(count=n_valid_days) in=have_counts);

by symbol year month;

if have_counts=0 then n_valid_days=0;

run;

That at least gets you N_VALID_DAYS on each observation to work with. Presumably, you know where to go from there. (Or perhaps you need to post a new question at that point.)

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

good Job and thank you again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello Raqthesolid,

Can you please share the code ? .. will be appreciated.

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello there,

the following codes worked for me. i hope they will help you too.

***Calculating liquidity from Daily data.;

*liquidity calculation following Amihud (2002) conditions;

2) At least 10 trading days in a month

3) Using daily data to calculate monthly Liquidity;

data Dailyp;

set daily;

Trans_month = MDY(MONTH (Date),1, YEAR(Date)); run;

proc sort; by trans_month; run;

data dailypa (Drop=Vol);

set dailyp;

prc=abs(prc);

if vol <= 0 then delete; *(-99 Volume is used when there are missing values);

if prc=. then delete;

if vol=. then delete;

Dvol=prc*vol; run;

**(2) Count "valid" dates per firm, per month. I assumed it means dates where volume > 0.;

proc freq data=dailypa;

tables symbol * year * month / noprint out=monthly_counts (drop=percent);run;

data Monthly_counts1;

set monthly_counts;*run; **(at least 10 trading days for each stock in a month;

if COUNT<10 then delete; run;

data illiquid;

set dailypa;

if ret=0 then delete;

ratio=abs(ret)/Dvol; run;

proc sort data=illiquid; by symbol year month; run;

proc summary data=illiquid nway;

class symbol year month;

var ratio;

output out=summary_data (keep=symbol year month total_ratio) sum=total_ratio; run;

proc sort data=summary_data;

by symbol year month; run;

proc sort data=monthly_counts1; by symbol year month; run;

data illiquidd;

merge summary_data monthly_counts1; by symbol year month; if count<5 then delete; run;

data mydata.Liquidity(drop=ratio2 total_ratio count symbol);

set illiquidd;

ratio2=10**6 *total_ratio; *(this is just to show in better form);

ILLIQUIDITY=ratio2/COUNT;

permno=symbol;

run;

proc sort;

by ILLIQUIDITY; run;

proc means;

var illiquidity ; run;

Good luck. let me know if you stuck anywhere and if my presentation is not very helpful.

Regards

ABdul

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks a bunch for your response Abdul.

I appreciate your help.

Best.

Trey

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Abdul

Thanks for sharing your codes. Trying to follow to obtain same measure but the section below is giving me errors.

**(2) Count "valid" dates per firm, per month. I assumed it means dates where volume > 0.;

proc freq data=dailypa;

tables symbol * year * month / noprint out=monthly_counts (drop=percent);run;

Did you create the year and month separately before running the codes as i have only date for each day.I did change the symbol =permno and was ok.

Thanks for the help in advance.regards.ejaa.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello dear,

you can easily create year, month and day variables from your date. if your date is in sas date formate.

year = year(Date);

month = month(Date);

day = day(Date);

i did this because i have to calculated illiquidity on monthly basis from days. additionally i also wanted to see how many days are being used in each month. i require atlease 10 days in a month.

sorry for confusion among permno and symbol.. i originally used permno (USA data) and changed it for you. but few were left out. please assume permno, firmid or symbol as firmID .

hope this might help.

feel free to ask.

good day

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I did not do for Amihud (2002) and never saw it on daily as well. You can do it daily if you know some papers who did it. Otherwise other measures like spread, turnover etc might be more suitable on daily basis.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.