data have;
input obs close MA own buy sell;
datalines;
1 99.98 1000000 0 0 0
2 104.39 1000000 0 0 0
3 109.13 1000000 0 0 0
4 114.55 1000000 0 0 0
5 120.25 109.66 1 1 0
6 125.27 114.718 1 0 0
7 125.28 118.896 1 0 0
8 126.45 122.36 1 0 0
9 127.61 124.972 1 0 0
10 128.84 126.69 1 0 0
11 130.14 127.664 1 0 0
12 131.44 128.896 1 0 0
;
run;
data result;
set have;
if obs<5 then money=100;
retain last_money;
lag_money=lag(money);
lag_close=lag(close);
lag_own=lag(own);
if lag_money ne . then last_money=lag_money;
if obs>=5 and buy=1 then money=last_money;
if obs>=5 and sell=1 then money=last_money*close/lag_close;
if obs>=5 and buy=0 and sell=0 and lag_own=1 then money=last_money*close/lag_close;
if obs>=5 and buy=0 and sell=0 and lag_own=0 then money=last_money;
last_money=money;
drop lag: last:;
run;


雷达卡



京公网安备 11010802022788号







