|
改了一下,这次运算应该没啥问题了& v1 N6 f/ |' t/ T% P4 |
7 h9 v+ W$ k7 w$ ?
) ~+ j) V4 \4 M. X i) T; Y+ pcapture program drop hello
2 }- A6 j0 T* b, W0 o' @5 G. S V/ V# w* I/ \2 F$ L9 D5 c
program hello' e6 j% o6 Y; f# P) b0 c# {9 L
' l/ i3 @" X/ F( ^ quietly {1 ~) h* K `- p! p) W8 a
u) } |! R g5 l
clear
" d6 b9 X+ K( J5 \9 ?, b7 b9 `9 {2 P$ q, r" }4 q- S& U$ R/ {
cd e:\finance\stock\20110101\source
5 f6 U, l1 Q/ v& p0 ^) S
/ c8 F) u' D, u5 Y+ h! e4 n! g: ^insheet using `1'.txt
- K" J j/ I! \9 {
6 }+ Y# `# Q1 j6 Y% H' I9 |$ T# D keep if v5>0/ q. ]7 K4 K1 `, j) q
+ R$ c4 o! q+ @
gen vt=_n
) z' b3 l, P% m7 d) }, I
% s8 |1 ?3 O, p' l, f; |1 b tsset vt3 C @( k, [3 U, R
& L1 Q6 Y8 h* g! }6 Q. W6 ~7 d' t: {
gen zf=D1.v5/ y& S: x0 ]* g3 x
8 }. O- p' c- [! u! I( Z4 P
gsort -v1
@; @+ T% R9 b/ Y* U$ M4 `4 p8 T% X5 L! Q5 |# F
gen avol=v7/v5; c7 X& g P1 E: h5 n- J
9 z8 J; L% _4 _9 e; Z. C( N
keep if avol>05 o( Y& W% Q* a
! ~- |+ F7 @) y3 E5 g- C drop vt
' c- X2 n. Z0 t# e# y* r5 E6 ] # x ]7 \" o$ M# {' B6 ^8 ~
gen vt=_n
7 a$ F; A( L" T$ R" Q1 E% Q8 n
1 V6 W, }' E. O% d' [# L R tsset vt: X$ @7 N8 @3 q3 R
) K- i w- N* p: H3 g- ]& F
sum v5 [aw =avol]( z: k; _$ O$ y! H
; Q( T) V9 s" G" h3 E2 L% k
gen amean=r(mean) in 1
4 _, y, k0 A& x7 m1 r8 S
. }# C4 Z1 {) x4 k. b) U' j h. o * 总加权平均值 amean d% J; ^0 G+ S/ t, h5 R
+ r/ u. g6 x7 k. M: Z/ Q
/ t2 @$ [) H" c4 {" g5 b& O keep in 1/240
' ?" b# X2 v, Q5 F& y
- a M8 }. A) E# s$ X( C# t sum v5 [aw =avol]
: B& Y- |: |5 z c& J/ z
; k+ F+ t. x+ N+ k gen mean240=r(mean) in 18 B0 |* `5 P1 P; r9 g
9 s* a4 x$ d$ L7 |/ n
*240加权平均值 mean240; O$ [- _5 {1 P! Z& {
7 l$ L% `5 @9 ~4 u) g/ r set obs 500
8 O6 A2 s* L4 i1 r* Z5 F
" f( O8 R1 n5 C- j7 y& H' C kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
7 Y3 `4 o3 j/ ?) t $ y' P0 s9 l; U
*240 kdensity(dx240 dy240)1 O7 [ ]1 H B0 s
3 f2 ]0 T) A. e9 z$ o
sum dy2407 V$ G x# f% r8 O, [
: e8 Y! }8 F) D, P m gen yxis=r(max) in 1, X5 V2 U, q6 O/ s3 D( H; o' v7 j
- [! G9 x6 s) v6 W, y gen yxis2=yxis/2
. i0 I$ v" a+ o7 t, _: ~ ( D2 }4 l% i6 s
*yxis! Q, j. e% |9 U) _
$ W. Z p$ k' {6 o( I4 x1 m7 E
gen dy240max=r(max)
3 E) Y) |; U3 P* j# h1 q8 X/ } + X H7 h1 |3 f# k
gen dy240minp=r(min)
, l+ D* r. ^+ l" L" X% j
6 P- \' O' M4 @* K: j gen vtt=_n$ w4 ^/ s' c8 N
6 H. F# H6 A% C/ x- C9 ^& l" v! S2 |
tsset vtt
, P% Q+ \- u! I3 M! h% C, i* c7 R8 i3 `3 h! s" A: {# C
gen ddy240=D1.dy240/D1.dx240
4 ~+ Y# U8 D1 c7 o1 y$ U1 |; U& ] j & v q- Z; c# p x7 e2 z0 w
sum ddy240% z3 J+ |+ L( ~
% t0 m5 V6 x, u* _2 r. U$ o f( o gen ddy240max=r(max)
6 u, @ M/ I6 z! J0 L
& c! y* b5 D% Y0 W$ V# U gen ddy240min=r(min)
; M( q( B& J, r4 `0 i# P( s7 o0 a
4 @' T( b! e7 h: X( a% V gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min); b3 E1 O% P) h" t& l; x8 T
; h, w+ S& @" t$ q. J
sum ddy240g1 E+ _5 m6 [% |- }6 l/ W' o" W* T
7 a2 F( y" @+ E- W gen yxis3=r(min) in 1! {6 m3 T+ G2 n' E9 O) t, Z
3 K3 i5 R( R1 E ~: [" m
gen yxis4=0 in 1
8 n# p; C/ \4 U0 _& }3 P4 [
; L6 e% e, m- i% j *ddy240g ( C* x" D( v% q8 o i
* l5 R# y/ s6 ]- L* i, m7 o! P
) \ x ^: ^6 ~ preserve
" V$ b$ y. m1 _& s2 d 4 r# v5 _( D$ s) J7 u, E- j7 B, {
sum v5 [aw =avol]2 G0 C3 ?6 y$ C" {7 e
# Z1 a/ i$ U! @% {
keep if dx240<r(mean)8 e( G, S/ O& I8 _) o
% I3 w/ n4 n* n6 U# _: E
sum ddy240# \8 P; a! j( W7 W. y8 e, M$ u5 B
2 s ?. p: ]; N- I1 Y& I- n3 b if r(min)<0 {0 n6 e5 Q3 m3 n. J+ O8 R# ~2 B
, S m9 _' `! F) H& l- ]
keep if ddy240<=0
5 b" ~$ y9 t. T0 [5 Q& D
U" D+ Y, Q9 p! N: X count
/ G) v) @: \) J4 C" ]! X) f- ~
% K7 R' G% G! h) {5 A if r(N)>2 {$ ~) q% Q3 |& X
. B* U. w9 J- g! L$ G: {- v% Q7 k9 `
pkexamine dx240 dy240 T3 X8 j) a1 r7 l1 W/ G
7 p& ]- F2 [8 ~8 x
local tempminp=r(tomc)$ M' E& V* d) m- j6 u) f, {/ p* C# L
restore
+ X1 V" a+ O. N! |( R }) p& h8 E& `7 O
( \, M( R: j$ O( o* I8 E else {
) M: q; O/ a" r( l% D9 l
, t$ Z& {# t6 f/ }9 t di "cannot find minp"
% T5 Q/ `6 D( ] , h" K3 ~8 M- B. @# b) F2 D: w
restore
; _* b. O& k$ @6 b1 K sum dx240
/ E( N- C7 S, D) f/ \0 k& H local tempminp=r(mean)4 _( V3 T# _1 L+ l+ M) }
( W- L9 Z3 G9 q5 K } r6 r3 V3 @. b6 A+ ?. G
}5 K4 a- j; x$ b+ n* B+ g _5 R/ d% D
else {
" `: s. |5 v3 w5 p+ M
- C# }9 h; h$ K( n8 x- T keep if ddy240<=r(min)
! D; v. O! B4 _ # _" A N5 z R$ E5 C+ P
sum dx240+ U( X6 S: Z/ [ C4 D! X4 W; Q
9 y: }% p) W6 }% Q D9 }# P
local tempminp=r(min)9 o3 t( P# [- \+ v* Q8 ^
restore ' ]5 N5 M- H; `
}# r+ w% R- D5 y1 e5 z
6 C8 `; k8 L2 f& H5 _7 f$ k6 ?# B' `% F7 _1 {# |% j& Y* P$ \, s) e
: R6 R4 D. A R2 @" }
gen minp=`tempminp' in 1 X* [# h9 c9 U2 i/ C) Z n
*240 minp: f; K. \$ A2 C! B
5 f4 _' f* \% l: k; z1 Z2 e. t# _- X. Z
0 g: p w5 c2 k) j- K7 P3 ] preserve ; a6 k F! L/ k8 q8 H6 X' ^1 P5 K
2 ^; |9 h+ R7 m9 _
sum v5 [aw =avol]& K$ |" h7 f l8 X8 s! I
4 j$ y7 {! C+ J6 u. s( k+ y, T keep if dx240>r(mean)
/ n! S1 E8 t( l/ v ' r) Q! n8 u- N$ k! p$ K5 j& n( U( K
sum ddy240
0 `% I+ `" {8 d* M
, K: o3 |) n9 `8 ~$ P% L: r8 a if r(max)>0 {8 \7 k- b0 m. t6 |5 m: ?
' d: j- J0 A, w ?2 O; Z
keep if ddy240>=0+ S! }6 Q; Z- r9 l" z4 i
6 B4 a) z& V; w1 J5 o* a- q count
+ G( u1 |. _8 T3 n
! e. Y# @/ o% S8 E1 w; y& S) | if r(N)>2 {5 @( j% {! ]% s
; }. Q+ C" \( Q2 i8 r C& ?* f
pkexamine dx240 dy240$ [, ]) _& {3 ]1 g5 s
9 c) [0 q$ B3 M# u local tempmaxp=r(tomc) % e8 R1 s) g! A4 d
restore
% M$ ]0 G0 Z2 Q; U1 u5 T4 v }3 A3 h( m: i( w
7 u$ M8 A- S$ f0 ^* \3 h( ? + Q( r/ q+ O/ ~# t6 k
else {
8 E/ [) Z' o& ]- J7 w8 j, {4 h restore
" V) C% Z6 Y2 W/ _0 `6 } di "cannot find maxp"9 r6 N. d) B A# m8 L# G4 t
" A0 W$ J, N; m; _
& U) s% m/ b, b1 J, Q+ l' J: V sum dx240
- r' z( _2 E! {+ g local tempmaxp=r(mean)
9 @ t8 o5 a' {2 d4 w! W7 q' I \; D3 \ k+ P
}/ P# v1 {- p, \% _; h% H; I* \# I
3 W. `( X- G L2 c# Y }
! \% M3 g+ `; E q% B2 X & Y- c- U$ J4 ~: @! R I3 i
else {$ N% P+ ^4 A, D/ B1 j8 P( e
) E+ n2 S+ H3 P! x- k keep if ddy240>=r(max)1 A- s s4 t# C' V# Q
; h- a- ^. v1 `/ a* s sum dx2406 f& T2 n( I4 m: c9 N" A0 X3 l
" J( @3 X. |) k# o- i- p1 q& s local tempmaxp=r(max) 1 h1 T" `* p, _! _* a
restore
3 n9 Z- v' Q5 U! g }
" y& u$ f/ s+ x. a' b
5 u% S' q' {6 |- d1 T. E* R
# d# l+ B0 {0 U2 ?& q+ s 5 a" S) a) q$ F$ A" T W' y/ h8 f. a# p
7 i9 `( i* O% B# F/ O0 R gen maxp=`tempmaxp' in 1
; H: O2 \4 Q( V* O- V( Y) D , o }: P: F+ Y; }
*240maxp7 t6 |( f4 z- p, [
. o( K: ^/ d/ m* {, d
7 w6 I' p; N; R
*-------------ddy240pminp左侧高峰值-----
$ ], {7 d. A$ Z( F
/ P% A* \. @! `5 D preserve $ \ D4 p! l4 l; u1 E
( S: I0 c: U/ G' _
keep if dx240<`tempminp'
. e) J5 S9 B8 w ]
5 M V" L9 Q7 F" d& R keep if ddy240>0+ d% N* U4 h# T3 M$ j# }+ Z6 v U
+ e& c2 ?7 E A1 q7 A count" z" M5 v. ^* q0 S6 h
- R; ~& \3 q4 w if r(N)>2 {
V9 l$ S% z" e" L: F9 e % t& c! i7 I; c$ V/ ?. i
pkexamine dx240 ddy240
' e# Z* m4 j5 N" a3 Q( s
9 X7 @; R1 U* v) b1 E q T local tempminphddy240=r(tomc)
% E% k l3 I$ o9 e restore1 s5 F! H0 R' r! D; d3 P3 [
}
! a$ t0 r x; }+ T( } / v/ {% A6 Z. u! W* v! M' ^
else {
$ p: O' s/ U% Y7 d& g7 j restore
, p3 q7 X2 g6 Z( Q: j& G- G1 ~ di "cannot find pminphddy240"5 W' H( ]+ R# w c# ~1 E
4 h0 X/ v5 `2 s, `/ i! t# ~' U& u/ T8 u
9 @' \3 U1 T0 j/ `% \( o
sum dx240
g2 x: F2 I* C. p& p: { local tempminphddy240=r(mean) 5 S, ^4 M/ i4 Y. k( n
# M0 }, h- s( o. V
" g0 ^+ r' P9 a$ d p1 ~( a+ g }
2 u( X- e! c q/ p
( E) n# i# j$ |* \
& `5 m% t% W5 f" f+ X. L% a $ P- Z) L- V0 C% C: M
$ R+ T( x3 W' e& x
$ A1 I1 _/ i. ~7 I1 A; v. ?% e , u# |( `0 Z" P$ F, z5 c
gen pminphddy240=`tempminphddy240' in 15 G4 q" o% q9 j7 j
6 E# |. o8 A8 N' k: T8 e
9 C: C4 l$ U# a) {/ @ *-------------ddy240pminp右侧低峰值 -----------------
) e& \; ]0 G8 s3 f$ @& Z preserve
9 R+ \. Q% B$ H5 q+ O * C! O z; O8 v
keep if dx240>`tempminp'
& v! r9 O L3 D5 z
$ v. u) ]' {1 u( O. F keep if dx240<`tempmaxp'# B* x2 J$ W* g
' ?' O- K( U& r1 [3 V
keep if ddy240<0( I) f& L/ B( h
8 U( E) W4 L( l" W0 j
gen temddy240=-ddy240
! L& G" O6 ~9 }; F# g 1 ~9 k* m. g. j
count; H1 s: J$ y5 T% N5 {# |- _
. r% B, K* O1 g- @ V) \5 j if r(N)>2 {& u9 y8 y/ M5 g0 R# ?8 v2 F* ?
7 ]6 Y8 o3 j$ X: B
pkexamine dx240 temddy240
4 b, W' D( J; i9 A' w8 F0 y 5 U* L3 J: p) y) D6 \" b
local tempminplddy240=r(tomc)* y, N0 U0 ^" F- `( S% p0 o, {& X7 Z
restore
# j( \' |0 B/ B4 Z5 _7 r }
# @2 R! J: m9 I, ^, U' C6 X
9 z* z* M! z: _5 z. o else {8 Z# }, f9 T) X# p
* x9 t0 l1 v8 ?8 R' t$ q) L di "cannot find pminplddy240", x. C! H: f1 `- ~8 b
restore* H. ~" E( }. W' C
9 W6 f8 m' Z0 Q- b |( W sum dx2401 ?7 D4 B: m1 Z! ]! p3 D+ Q
local tempminplddy240=r(mean)
. Q. G/ h+ }% X0 M- P# ?, F
9 \. @* R) R9 P* w
; U/ K4 o4 p q& H }
# m, t4 |. H/ O# ?6 o+ J " W! v! l$ h0 @9 s0 w$ k
, w$ ~0 T; ^- I3 D- B9 U
' W) F8 g2 O- A) d" \ 3 {# a* g& F9 M8 b- f2 \
) B2 [8 q. K) r4 f x
gen pminplddy240=`tempminplddy240' in 10 l) _2 h& U0 D/ B! y! @! u- { S
, Y% F: @. O/ j$ j6 f, Y# T( F *-------------ddy240pmaxp左侧高峰值 -------------------3 P, v) t0 W8 _8 N9 ?0 d0 q
7 T1 @) Q: I8 k
preserve & e1 @! t$ [: J N4 d( p
6 N, Z! z& D" i5 P) k% C1 R
keep if dx240>`tempminp'* B8 |0 L4 s4 \% W; ~% i" v: P: [
: u+ y* J8 c2 j) i6 ?
keep if dx240<`tempmaxp', `& N' a7 [: X8 X" [, J
8 O N5 c2 |( P
keep if ddy240>0
2 O- O. g% d3 a) t" e& F count2 F+ ^) K. I9 }0 B$ Z( b% Q/ g- W: {1 [
' w s" }: K) W" @% s; ] if r(N)>2 {- u: [, @" @1 M. h1 [; l% T# C
# C$ R) m" X2 \) o pkexamine dx240 ddy2403 Z' V+ u$ F, G* m& M6 S
" r! e8 n' C. K- ~' c5 b% r local tempmaxphddy240=r(tomc) : B' k8 C. V* ^; L6 J- \
8 @' _8 l+ Y* L/ C; h& Q4 z: S: j restore' {1 k3 L0 `" R( B$ d5 ^
}
" ]2 k6 m; Q. f8 U, B; P- z! n* B
0 y2 G9 P0 K* W else {- k9 w, K) t% n1 |( x2 w% a( ~
- p' K/ u8 [9 U; P1 Z: n di "cannot find pmaxphddy240"
* G1 D5 |7 Y6 ~7 K0 N% F- ^ p restore
1 J4 @2 v6 [5 L0 D( v- \+ b # Z3 u% B: `% B' r( Y8 y
sum dx240
D, k+ @* _, \6 O; ]; \3 f local tempmaxphddy240=r(mean) ; R+ v4 X5 _- i( }- U5 B
e2 o- _9 Z7 X, g( t1 x: \
0 c: ^! U( H7 r p. k s9 L' ~
}
! O: c! K' X& u
; @, l* R- o) v' u0 K8 O/ g0 O! X 2 ^( W" N! y: Q, S# M/ r
$ e( z$ O5 l! h; K, L) G
, A! j5 s9 Y! [* D% ~. |; F4 `- K5 y6 m " Y6 q1 ?) ^0 V% Z) q
: n/ h+ y! ~6 |
gen pmaxphddy240=`tempmaxphddy240' in 1
+ V7 M0 N9 o0 V6 ?5 F
6 L% e' O' X0 U 8 g" _* z: S2 x |, F
*-------------ddy240pmaxp右侧低峰值 -------------------
% w: Y2 W7 e- l
6 v/ Q# [3 z: \: f preserve
+ X( r5 [- d$ s7 W: O / h" i8 ^4 i4 X ^% y8 }
keep if dx240>`tempmaxp'
( e. [7 e* e6 G
% z! Y' N* }: G Y gen temddy240=-ddy240
3 P- }8 r- _0 B$ v
. `. V5 H2 i% ~. g6 q, d/ J keep if temddy240>0/ b0 R2 M; N1 @9 X- y) r, o5 k5 E
0 |6 j4 G+ P/ Y9 U* I- T
count# r% Y4 O9 ?& e
) }0 o- i. {* Y! r9 E
if r(N)>2 {! [& {+ c0 S; q( p
+ ]! C$ N9 S( o1 T+ i+ O5 Y& c pkexamine dx240 temddy240
6 l* \/ v" _& g9 t6 [ " a1 [. `6 K" S% p. Z: B. M' }
local tempmaxplddy240=r(tomc)
6 f/ P9 w' V; E$ K6 e* [1 F. ^% p( ? restore
2 S* B n5 \" M. M1 ]. x# [ }! i7 _6 W; @! S0 v' e
0 m. @) f c% m* s/ `' b
else {) j- q' J: X" g/ S& e
restore' J6 `* G+ r& ]9 a6 g3 ^6 W3 \
di "cannot find pmaxlhddy240"7 E. `: C. }/ C( p. O! E8 r [2 |
# t$ G) r4 }! W4 o/ V: ?* \ 0 l9 e. p |# D( N
sum dx240; o: H) i2 V4 R6 l- y6 z
local tempmaxplddy240=r(mean) in 1
: Q' i6 x. B+ z$ P7 _; k + |( }' j: ?1 P! R
5 \/ l( a, v9 J2 ?
}0 E9 q+ T" m7 g, ]( p/ j
" n! [, y' Q6 w7 Z* Q' h
0 L) @. R( K3 I3 U/ m1 z
( f! ~8 b, m+ s# g: @4 ?" j/ [ 1 k/ n& V- d( q- z" `, g2 B
3 ^: e5 o- i* J5 J! z 8 S. M4 s( T: @0 @/ P) j. q
gen pmaxplddy240=`tempmaxphddy240' in 1$ j5 s# H2 o/ ~3 I% h
8 e$ M/ \' _9 H* q5 z
*-------------------------------------
. o' o9 g4 ~5 @* n& K
2 i: ~* d' F/ h4 p+ o2 D$ D t gen price5d=v5 in 1/20
# |# S5 R' T* M) v
+ i! i! Q6 s; B" E gen price5yy=_n in 1/20
| _" s0 \. B0 W 3 g- q# q: p! Z9 S) x; ]
gen price5y=price5yy*(dy240max-dy240min)/201 w# `' h* g0 m* D2 n
3 w, f0 h! a/ }( q3 q *price5y &price5d
! ^/ h& r) a# o0 N% A7 g3 B
; G8 o# H& O* j3 y, B3 N/ H gen priceny=price5y in 1
7 B- \2 h# p2 i, @- o: E9 m - V5 R4 _' ]4 g1 ?
gen pricen=v5 in 1: Y7 A4 n: @, J) \! f; A' w
) n K" b; P7 ?5 z2 r. T
8 o+ R* r' \% x5 j$ l2 {' h* q4 n *priceny &pricen
: V9 c, p3 ?+ y' a , e' V9 V* n9 D0 w& k, @7 v
. k7 z$ Q7 I* J *-------------------------graph------------------7 K/ K$ ]5 s9 E+ }+ I
% y$ D/ w e( B2 K. g tw(line dy240 ddy240g dx240)(spike yxis amean,lc(blue))(spike yxis mean240, lc(red))(spike yxis maxp, lp(-) lc(black))(spike yxis minp, lc(black))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean)) (scatter yxis2 mean240,lc(red) msymbol(+) mlabel(mean240) lc(red))(scatter yxis maxp,msymbol(+) mlabel(maxp) lc(black))(scatter yxis minp, msymbol(+) mlabel(minp) lc(black))(scatter yxis4 pminphddy240, msymbol(O) c(l[-]) mlabel(pminphddy240))(scatter yxis3 pminplddy240, msymbol(O) c(l[-]) mlabel(pminplddy240))(scatter yxis4 pmaxphddy240, msymbol(O) c(l[-]) mlabel(pmaxphddy240))(scatter yxis3 pmaxplddy240, msymbol(O) c(l[-]) mlabel(pmaxplddy240))(scatter price5y price5d, msymbol(O) mfc(black) mlc(black) c(l[-])) (scatter priceny pricen, msymbol(O) mfc(red) mlc(red)), title("`f'") xtitle("`1'") ytitle("density") legend(off)3 U7 E7 w# L: {0 x* [) w; h4 V
) B; Q) h- V8 a1 }* r* ---------可选项目----------------------
9 a$ g7 e9 P8 f" u0 _) l: ~' l+ y. S" l
}5 O3 C* M: x/ w8 c3 D
end
( W" l6 k/ i+ R |
|