FlyUFalcon 发表于 2014-3-30 18:29
这样的话也能做。 主要看每次价格变动。 如果价格上涨,即为B。 反之则是S。价格每边则是和上一次一样。
...
根据您的建议,我编制了一个程序小样,主要是用前面发的浦发银行的一年数据来计算PIN,我使用的是成交均价与相应的区间中开盘价和收盘价之中位数进行比较,若是均价高于中位数记为买盘,反之则记为卖盘。现在的问题是,有同学说应该用最高价和最低价之中位数进行比较,不知您如何建议。附上我的程序和论坛币。
%macro importtxt(table);
PROC IMPORT OUT= WORK.&table
DATAFILE= "C:\Users\mosuchen\Desktop\pin\&table..txt"
DBMS=TAB REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;
%mend importtxt;
%importtxt(gdata);
data gdata1;
set gdata;
medianp=median(open,close);
meanp=mp;
year=year(date);
run;
proc sort data=gdata1;by stkcd date;run;
data gdata2;set gdata1;
if meanp>medianp then buy=1;
else buy=0;
if meanp<medianp then sell=1;
else sell=0;
if meanp=medianp then bs=1;
else bs=0;
lagbuy=lag(buy);
lagsell=lag(sell);
run;
data gdata3;
set gdata2;
if stkcd^=lag(stkcd) or year^=lag(year) then delete; /*Lee & Ready 1991, tick-test rule*/
if buy=0 and bs=1 then delete;
if sell=0 and bs=1 then delete;
if buy=1 then buys=1;
else if bs=1 and lagbuy=1 then buys=1; /*Lee & Ready 1991, tick-test rule*/
else buys=0;
if sell=1 then sells=1;
else if bs=1 and lagsell=1 then sells=1; /*Lee & Ready 1991, tick-test rule*/
else sells=0;
run;
proc sort data=gdata3;by stkcd date;run;
proc means data=gdata3;
var buys sells;
output out=sumbs sum=buys sells;
by stkcd date;
run;
data sumbs;
set sumbs;
drop _TYPE_ _FREQ_;
year=year(date);
run;
/*-------------------------------------------------------------------*/
/* Create the dataset containing the observations... */
/* The observations for PERMCO 99999 are consistent with the */
/* Easley, Hvidjkaer, and O'Hara example on p. 2198 of the */
/* Journal of Finance. */
/*-------------------------------------------------------------------*/
data buysell;
set sumbs;
run;
/*-------------------------------------------------------------------*/
/* Get the data ready for the NLP procedure. */
/*-------------------------------------------------------------------*/
proc sort data=buysell;
by stkcd year;
run;
/*-------------------------------------------------------------------*/
/* This is the procedure used to maximize the log likelihood */
/* function specified below. */
/* */
/* This particular factorization of the log-likelihood function */
/* appears in the paper "Time-Varying Arrival Rates of Informed */
/* and Uninformed Trades" by David Easley, Robert F. Engle, */
/* Maureen O’ara, and Liuren Wu (paper presented at the 2002 */
/* AFA meetings). */
/* */
/* The parameters emerging from this estimation, for PERMCO 99999, */
/* are consistent with what's mentioned in the Easley, Hvidjkaer, */
/* O'Hara paper. */
/*-------------------------------------------------------------------*/
proc nlp data=buysell noprint out=pinest(keep=stkcd year alpha eta mu);
by stkcd year;
max loglik;
decvar alpha ,delta,eta,mu;
M = min(buys,sells) + max(buys,sells) / 2.0 ;
x = eta / (mu + eta);
bounds 0.0 < eta mu, 0.0 <= alpha delta <= 1.0 ;
loglik = -2.0 * eta + M * log(x) + (buys + sells) * log(mu + eta) +
log( alpha * (1.0 - delta) * exp(-1.0 * mu) * (x ** (sells - M )) +
alpha * delta * exp(-1.0 * mu) * (x ** (buys - M)) +
(1.0 - alpha) * (x ** (buys + sells - M)) ) ;
run;
/*-------------------------------------------------------------------*/
/* Clean the output and print it nicely. */
/*-------------------------------------------------------------------*/
proc sort data = pinest nodupkey;
by stkcd year;
run;
data pinest;
set pinest;
pin=alpha*mu/(alpha*mu+2.0*eta);
label pin='probability of informed trading';
format pin 5.3;
run;
proc print data=pinest;
var stkcd year pin alpha eta mu;
run;