Secret Macros to Use in WRDS Cloud

Jan 27, 2019

When a SAS program is submitted to WRDS Cloud for remote execution, a small script named autoexec.sas runs before everything. The content of this small script is as below: * The library name definitions below are used by SAS; * Assign default libref for WRDS (Wharton Research Data Services); %include '/wrds/lib/utility/wrdslib.sas' ; options sasautos=('/wrds/wrdsmacros/', SASAUTOS) MAUTOSOURCE; What it does is basically making the libnames available, so that when we want to, for example, access the Compustat funda dataset, we just need to write: ...

Winsorization in SAS

Jan 26, 2019

Version 1 (Unknown Author) /***************************************** Author unknown - that is a pity because this macro is the best since sliced bread! Trim or winsorize macro * byvar = none for no byvar; * type = delete/winsor (delete will trim, winsor will winsorize; *dsetin = dataset to winsorize/trim; *dsetout = dataset to output with winsorized/trimmed values; *byvar = subsetting variables to winsorize/trim on; Sample usage: %winsor(dsetin=work.myDsetIn, byvar=fyear, dsetout=work.myDsOut, vars=btm roa roe, type=winsor, pctl=1 99); ****************************************/ %macro winsor(dsetin=, dsetout=, byvar=none, vars=, type=winsor, pctl=1 99); %if &dsetout = %then %let dsetout = &dsetin; %let varL=; %let varH=; %let xn=1; %do %until ( %scan(&vars,&xn)= ); %let token = %scan(&vars,&xn); %let varL = &varL &token. ...

Access WordPress Database via SSH Tunnel on Mac

Jan 7, 2019

To access the MySQL database behind a WordPress site that is hosted on the cloud from a remote Mac, it’s relatively simple: establish a SSH tunnel and then use any browser to visit the phpMyAdmin. First, establish the SSH tunnel to the host machine: ssh -N -L SOURCE-PORT:127.0.0.1:DESTINATION-PORT -i KEYFILE USERNAME@SERVER-IP Because by default phpMyAdmin is running on port 8888, the above commband becomes: ssh -N -L 8888:127.0.0.1:80 -i KEYFILE USERNAME@SERVER-IP Second, open browser and visit 127. ...

Reconciliation of Black-Scholes Variants

Apr 17, 2018

This post is just to show that the different variants of Black-Scholes formula are in fact the same. $S$: Underlying share price $t$: Time to maturity $\sigma$: Standard deviation of underlying share price $K$: Exercise price $r_f$: Risk-free rate Variant 1 This is the one shown in our formula sheet, and is also the traditional presentation of Black-Scholes model. $$ \begin{equation} C=SN(d_1)-N(d_2)Ke^{-r_f t} \end{equation} $$ $$ \begin{equation} d_1=\frac{ln(\frac{S}{K})+(r_f+\frac{\sigma^2}{2})t}{\sigma \sqrt{t}} \end{equation} $$ ...

Bloomberg BQuant (BQNT)

Apr 6, 2018

Bloomberg is developing a new function in the Terminal, called BQuant, BQNT, under the Bloomberg Anywhere license. I happen to be able to test it thanks to a fund manager and find it could be a future way of using Bloomberg Terminal. Background Bloomberg recently made JupyterLab available inside the Terminal and invited partners to test it out. This function is named BQuant, or BQNT<GO>, which is still under heavy development, but the idea is just great. ...

Handy Stata Code to Generate Fama-French Industry Classification from SIC Code

Feb 26, 2018

For it to be handy next time, here’s the Fama-French 48 Industries classification. Here’s the Stata program to create Fama-French 48 Industries from SIC code. Basic usage is: ffind sic,generate(“FF48”)type(48) where sic is SIC code, FF48 is the generated industry variable name, and we are using 48-industry classification. Alternatively, one can choose 5, 10, 12, 17, 30, 38 or 49 industries. /**************************************** * ffind.ado * Creates variable containing Fama-French * industry classification. ...