|
Here is one problem troubling me for long time....
What I want to do is this: Suppose following is the data:
obs P MaxP b_signal
1 10 11 0
2 12 12 1
3 11 12 0
4 11 12 0
5 9 12 0
6 8 12 0
You see at the obs 2 P >= MaxP, which triggers the b_signal, indicating
a buy action, now my rule is keep holding what I have bought at obs 2
until price has dropped 20%: P < 0.8 MaxP, this will happen at obs 5.
So I want to create a dummy 'Holding' indicating the period I hold what
I have bought, it should look like this:
obs P MaxP b_signal Hold
1 10 11 0 0
2 12 12 1 1
3 11 12 0 1
4 11 12 0 1
5 9 12 0 0
6 8 12 0 0
You see the value of Hold depends on three values: the previous value
of itself, the previous value of b_signal, and the comparison between P
and MaxP. How to do it in a Data step? or SQL? Seems quite
chanllenging.
Thank you very much
Yiyu
|