|
改了一下,这次运算应该没啥问题了 V' D9 y+ S5 y
& H( a; p' d+ m4 H" h; c
4 K S! U3 ^% O3 ^
capture program drop hello
; E, W7 Y. S. E- {6 Q6 p2 y2 Z$ E3 H0 a: H
program hello
- d. A0 u( z$ o. }& k1 u9 z, H
; k' U, F! F2 A7 s2 w1 G+ ? quietly {5 O1 o4 s; {5 |/ v: _' P' b( m. x
: d. X4 {0 U; p1 `6 c/ Y- C: o! L: `
clear
4 D9 o8 k) }# S" _) c6 I. u; h9 s- u. Q! F0 w9 V# ]4 r- o
cd e:\finance\stock\20110101\source
( t, Q) \- U3 k+ H1 q
7 W Z# o$ E8 N. L4 {insheet using `1'.txt; N) G+ A4 u. B9 [. X* S X0 j) ~
2 R8 D! Y- R, P+ R
keep if v5>0
1 J1 {) i& A& y; H5 c( g# M- h ; W; H" n5 c7 r( G
gen vt=_n
* E; c- y$ R0 G# i k 2 ] e/ I/ v7 H- L- x
tsset vt, _1 }$ ?' E D8 E! g# `1 V) H
2 {: M! s3 A- g+ M/ w
gen zf=D1.v5
|1 A! X# B3 y3 z- _" y" G$ e4 U- p! |# q, [" z
gsort -v1
0 X1 m5 ~ W/ C
& Z# r! n8 x, J f gen avol=v7/v52 m9 J- }: h" E* r3 u1 @/ T$ Q
6 L9 n! A" A. D) T keep if avol>0
+ U: d2 K* T& `4 V
# y7 F, D* Q9 M$ e$ _9 f; t drop vt1 ]% d! }: F& s; P* A) r
3 o- a- R4 ~* [: l5 I gen vt=_n6 X- p5 P7 F0 }7 ^" U# q& p+ i" m; y
; C) w' J# y+ h/ `1 F8 J& D8 W
tsset vt7 O y8 t. s2 L/ M4 j
G1 f- p/ d5 C# S1 N3 Y2 o+ w! } sum v5 [aw =avol]
; b' K, |5 D& Y# D, W$ Q7 M/ u! I: p* S, k* E$ k7 l
gen amean=r(mean) in 1
9 P O: |2 x8 p9 P. P ' M* |! U# a _: d) g- p
* 总加权平均值 amean
9 Q! x% x9 v/ a$ E 3 M* w g9 d" H0 V0 Z0 L; w4 D( ?
6 c( B- w) s, M g- b
keep in 1/2407 |, h, H- U6 X: t; L5 Y1 p. w
" L9 D2 t5 D* S+ _# T: a6 [. z$ b
sum v5 [aw =avol]2 M1 t; b2 w) W$ }
, H' b" \ Y* n( s- N2 T+ G( y
gen mean240=r(mean) in 1# E" p& @* A, p( o; r
$ Y A( ~& |1 m3 ]3 M3 `
*240加权平均值 mean240# s6 G: g3 I" J/ [! L; E- M
# p1 I/ m3 U Q' R
set obs 500 % D" w1 u9 z( A6 [9 w
4 s& A1 Z Y( D% I- p( x6 O kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
: @ w/ R4 [1 I N. E
6 |7 A0 o# z- D4 ^3 p5 i6 ^- F *240 kdensity(dx240 dy240)* i7 P. p8 F7 ~1 L; U% j+ k, R0 c
4 n/ r$ x4 {2 u9 @ sum dy240' ^- y& [; F2 f9 L9 ]* D* d& ~; @
. Y- T5 I! u# x4 S9 ? gen yxis=r(max) in 1
2 i( G3 n% {" O* `
1 F0 f H6 N4 W3 h) {' y gen yxis2=yxis/2
! _& N8 N# l% v& ?. \$ b
0 b' K4 t- q* B8 f3 E0 k8 y *yxis" i: ?% k) q# n7 w0 d( V' W
* e) c1 _, q9 j* `: U0 }0 k
gen dy240max=r(max)1 `1 ?$ w6 L$ L& P& x
& p8 C7 a% j0 L
gen dy240minp=r(min)! W# Y7 T+ Z7 T# `& }9 a4 l, c5 y9 h, ]
0 `1 n# ?( ]6 t* X9 [ W3 d gen vtt=_n8 u9 T) y( G' L& |6 S8 C j, k
. b& x$ r( s( m tsset vtt
8 r0 x+ O! z7 A/ O4 _# S# E
6 \4 G0 I& N7 B6 s! Z$ W gen ddy240=D1.dy240/D1.dx2402 M8 j* K3 Q. m: P% x: F
2 d' D1 ^/ ^( _ ` sum ddy2405 M" Z( ~' M' Z/ _
5 ]5 G4 r* W: V1 y
gen ddy240max=r(max)
8 Z6 m5 S G5 |
) B7 ]4 I/ ^( R: E3 t; W7 P gen ddy240min=r(min)
8 _) r( _" F- g3 }+ p/ {
7 E& A0 r3 h. L/ A% t+ D! o" R gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)( ^ D) N u4 l& h3 F
$ V5 m0 J# f+ a! L sum ddy240g, o& P0 Z, B1 M; U
- u3 u* ?' B4 n5 Q. E( B gen yxis3=r(min) in 1' d/ r* Y5 A+ V* Y
( \" k4 K8 {8 A1 j5 k, V9 t gen yxis4=0 in 1
) s7 q" ^3 p% C4 h8 p+ J6 j5 A4 W " {# `9 D' j- X7 o! [' I
*ddy240g : C. ^5 s% h& Z7 |/ A; Y
* ]5 h0 B, @& Q 2 _/ c3 |1 S4 J: V& Z3 E. C
preserve
% S% W; Q$ S1 _9 y6 W; r 0 F& m$ C4 L. i! {$ H+ y4 |
sum v5 [aw =avol]- R7 I1 w% q, b* W% |8 a" L
; i, B- w" `8 Q9 s keep if dx240<r(mean)1 H1 B! |" `$ D! P
" v! V9 P3 w0 l; b$ P5 y) n& X sum ddy240- P e& I9 Q5 g3 W" c% y
" N$ q D4 b5 l
if r(min)<0 {( V# E0 Y) Y% g4 P
9 S, {8 Y; M# c
keep if ddy240<=0' v3 T9 s5 [: [0 I0 [
6 U- D9 Q7 s- {' }
count
+ w( X' s7 d! ] $ }" _) |9 X z8 e
if r(N)>2 {* U3 G+ o) n3 H3 E- ]6 z
1 \2 v/ ?# H, Q* j/ X. ~
pkexamine dx240 dy240) w; _! I$ c& p3 b6 K
8 E2 X: B# B- b& ^" o! j
local tempminp=r(tomc)" F$ ~2 x# E* f$ z5 R1 z7 E! u
restore * _# y! }0 ~1 [. a! X" J6 d
}" \; n+ V7 t( s5 o C' V, }
& o. ?. K; Q: w1 Y else {
- f5 h4 G# b- O: H, W2 B* B
* c; k7 V* z# x+ W( t di "cannot find minp"
7 R$ j0 B6 m/ j' {) V% {- K% q " o6 x8 m+ o1 n' u- @( e1 u
restore
8 U- c, h# B) f/ Q sum dx240
3 t B0 w, x' c, L local tempminp=r(mean)& P8 |! b1 R8 v
) ^$ @* E' q0 N# z
}/ u0 ^1 j8 F# _( u7 k( G" U
}9 l# r7 q1 R, |: [0 h I6 X' n
else {
1 j7 Q/ K s& P6 O+ h4 @( f+ W
( ^6 @! [* ~0 K- B. v2 N' w# C keep if ddy240<=r(min)) @& Z( z' C. Y1 Q
$ ]8 @2 B Z' W; p4 H
sum dx240. V4 |( h. K8 b+ y; g5 v# B/ o9 `
S+ f$ s- d$ D9 V* ?$ q local tempminp=r(min)
! H6 p- w9 M0 V# L- g0 g restore $ T6 s3 B- f5 V
}
* o# p: p8 f+ Z; E7 g
) p; d; Q3 u: A) s( t5 f' v
" g% v0 p" v0 n8 L, g l# F; N7 b6 S" e" {
gen minp=`tempminp' in 1; W8 n) l* d) |3 Q' p$ F* D
*240 minp
+ j* }+ J1 n; U2 n
0 s# n" p7 V6 C/ W/ \# M- u
% J# l( v' z/ ^$ v# r
2 ~( |7 e* J* D* o preserve # W9 Q0 V1 B# G$ ^
) S6 i: X2 k& ]/ D
sum v5 [aw =avol]
, v4 Z2 u9 ~* t: ]
) H- j* r* h h keep if dx240>r(mean)
* d; ]4 }7 g. O+ ]7 I1 m
" `0 V4 {, m0 ?$ L! L/ F a sum ddy240
; G0 z8 r% ~7 v% A + {% n/ V& w" \) a, i9 `
if r(max)>0 {
8 O0 _. f( Y& O% j0 r4 n , y+ T6 F/ o c- N
keep if ddy240>=0
8 C: w, n8 b5 H/ k/ F$ q2 J
" S% J# V$ d, N3 m9 j count
- _/ O. q- G/ W" B% k# ^: S
3 }4 }5 K9 h$ j3 o; V' g7 \ if r(N)>2 {% k0 f5 h) \+ k" l h
+ W9 H' s. p7 y2 X3 j' }! H
pkexamine dx240 dy240
, Q {. C) ~( j& f0 d0 q6 x% ]* }% B
* h4 t+ b. W; } local tempmaxp=r(tomc)
d7 }/ V( W; R) [. b restore
6 V) b3 i2 E, U; q* p- X8 x: Z8 S9 y }( `. G: C' K4 j. R4 Y' }: j: O
/ x& F6 b {" [' |4 l! d 8 {+ ~; b1 Y* q# D2 U" ]5 L2 ?
else {4 y' Q& J) B( n
restore ) ]+ h' J1 f: W% l
di "cannot find maxp"
0 S8 b* N$ I. n. r) s4 {( d ! i" o; ?0 u* `( n7 J5 i# i
2 q; q; A; ~' K8 Q( \$ T sum dx240
" b; i2 F) u$ |$ F& W2 T Q S local tempmaxp=r(mean)
1 q5 M: D! P4 d5 j8 v" S % W! o- ^% i8 X0 h- l
}: W- o; R6 m: y. _# j% _
/ i' \4 e6 e& h7 l. M0 G
}
0 `9 @7 o3 u. ?+ f; w
2 ?' {7 `( G) r3 k! l; m* g else {1 u: T& O3 j) H1 Z
- a7 Y" R9 j) L keep if ddy240>=r(max) o5 m- y; T% J ^. n* N% D+ }
; a* ?. v% l: i5 p$ U
sum dx2402 `. D% f1 X* ]
3 n I- p/ z" i$ P9 q( S local tempmaxp=r(max)
* \8 k2 I& P6 L9 G3 { restore ; i! W4 b, N2 Y9 ^1 M3 J# f
}4 S1 P8 U- R* [; ^/ c% f( L* z6 c
& U J7 m7 @9 d
& V6 z5 s# K2 `; z5 ]4 J; Y
0 F5 g6 @# s" F, Q3 _* ~% ]) D N0 L( t( A9 P, H! I `7 K
gen maxp=`tempmaxp' in 10 V k+ Y2 j5 L. w3 J8 [& p
% h) u( |" L6 l* J; G
*240maxp
, h3 U) ]$ H: b
0 u6 b4 O, R# b( U 5 C, u9 q4 B7 V' M$ s: G0 o
*-------------ddy240pminp左侧高峰值-----
9 \0 k! N8 m3 W) ~3 V8 ?
! T$ \2 O& k) |: y9 \2 P preserve
* M. ^+ ?; R9 i- P% D0 }2 X 1 {9 c3 l" l4 [( l; m; X/ M- ?4 d
keep if dx240<`tempminp'/ I3 d) P# J; ]+ ?' c
) h$ d+ I2 z, g1 N- K
keep if ddy240>0
+ ?' E S/ q& t0 T* q2 F
/ `% L) K9 z y; ]( R. }0 C: @ count" @. B/ o' O/ s0 V G+ Z- U
3 ~& |: a7 M6 z' ]$ M
if r(N)>2 {7 o1 x/ r4 y. x
( P/ H5 ]* l. U4 h" _
pkexamine dx240 ddy2400 T7 Z5 ]( w5 j
6 ] C+ V. C2 e& N- r% X- M$ j local tempminphddy240=r(tomc)
# {% _: ]6 p: Z8 A1 g restore
% g+ c- j z& V8 d$ o. K9 u }
* ` k! ~! c8 V" G( ?3 H4 J
G& w! Z* ]4 c+ t else {4 m: f( r& D# q! L' \
restore : n9 d0 s$ k- f2 E& e5 e4 F( c: Y T
di "cannot find pminphddy240"
8 B: Q5 v2 ]% ~+ c
: n# y! q7 V V+ D+ J 3 a* Q& H: a8 I4 C" M5 _" |+ ^
sum dx240( k: {0 u( {+ ]; P
local tempminphddy240=r(mean) + ?' s, x' G) j+ E. {+ O
. O8 L) b+ Z3 U9 j4 ?3 v6 R ' r; ~- _# u5 u M" e2 Q0 b
}
5 Q3 n7 R$ s0 l4 `. h0 k
% r& O; m9 B5 {' b % I) Q& Y. J8 N
: P6 m! X% R+ [+ u
: Z. @" ?! y! W4 I, b( C ; Q( X& L4 j5 t9 ~
L: v5 r7 d6 b0 w, S# W; {4 y
gen pminphddy240=`tempminphddy240' in 1% w& }! M2 c8 y! J: ~3 ~
# [+ @1 l0 U) B
# ?, h: y8 Q% E
*-------------ddy240pminp右侧低峰值 ------------------ G6 F3 m; n5 v
preserve
! n) p0 x, N5 r, w$ B: L0 F8 F ' K2 e* }2 z) ^0 l' e; J& x G
keep if dx240>`tempminp', [6 y* H9 U* m' S I
4 K; Z4 R+ \# y5 Y9 K keep if dx240<`tempmaxp'
# \2 `6 v7 q' C
0 M1 s9 x9 C, `" H* x& `8 ]1 U keep if ddy240<0
$ n+ M- Y$ b; u / @1 u" ]& q' j" f' L k
gen temddy240=-ddy240
6 M1 @* b! L9 I1 m, N i / {0 L/ B( n/ `$ `
count& V" O1 B1 A) k
* }0 r- D [2 T, r i if r(N)>2 {6 k9 J* R8 P3 x6 {+ Q
6 m5 G2 I! s: L" B% F3 w
pkexamine dx240 temddy240
9 S3 T" y( j2 l7 P3 f; R0 r( q; d % ~9 P, {0 F7 t$ l0 w' k/ I7 p, Y% s" ?
local tempminplddy240=r(tomc)8 _2 _# t# Q; R' ^. d
restore
# e7 t3 M) x) I1 L- x4 |0 Q }0 N. N' C6 K: o; [ A0 ^
7 W" v6 |- \! H2 Z1 t7 v
else {% d, e+ H8 S6 z9 |; f" x# D
- `1 d ^' K; g0 x di "cannot find pminplddy240"
q. k4 L" l+ C; S( m restore
. K- c! `$ g% h( H! b& S( U
& l& _$ d: W! n3 {' d" N M7 X sum dx240
; n" x2 K$ O# q# j- \1 i3 O( v local tempminplddy240=r(mean)
; {( {# W; W- o; h. K( Q, e / _; [. q- a- F( Y9 F" H, r9 m, c
( r4 T2 T; S* P( D/ l5 D }* p% w& ~2 g: Y, I' c( Y7 k
! \. D( w/ I4 x0 y: i : i$ @ y. Z6 l- R/ y
2 R, ?2 R+ c+ j2 f9 c7 C
4 v }* N; F# j: U/ ^ x6 L
& b ?4 ]! \% W0 [; p6 i4 r gen pminplddy240=`tempminplddy240' in 17 X! E, V, ~; p8 N- r
2 g6 q$ Y7 c! l' b e! k0 j; L *-------------ddy240pmaxp左侧高峰值 -------------------
3 N+ l! s/ h* l8 L4 d0 a& w. c( g
& D. D g$ d( w2 |: e5 F, t6 X preserve 4 M8 I1 w# Z, Z+ p( b9 K! V+ n
$ M( z% _0 G0 ^3 @
keep if dx240>`tempminp'
3 _6 y, K% D: {
7 F" A# Q* V2 W0 n9 m% Y keep if dx240<`tempmaxp'
( X% [4 d! _' a* h( v3 F, X $ g \& X# W, I1 G P/ D
keep if ddy240>0
/ C( f+ R2 t; ^2 r$ l1 i count& s/ T) K% y$ E
5 ]- }. g1 e7 K$ m if r(N)>2 {8 |3 h+ Z O2 ?2 v/ g, @
+ v5 |* q. Q, G; b j pkexamine dx240 ddy240
# Q1 o. I* Q/ O+ R) l
( y/ X0 }4 D7 ?: \ local tempmaxphddy240=r(tomc)
$ O, G, A3 F% c! d " |9 }, L% g( ^6 j7 V
restore
9 A3 z' J e2 B' T' O+ e6 W& Q }8 d$ p" e" S$ h9 S! q. a
+ y$ z9 v. k& e8 y% }- h
else {. n- F2 b& ~$ }- v0 g, w. H" j* s* J# F
- m% j% M+ d+ }, A- v' M9 l di "cannot find pmaxphddy240"" y& o$ V" |$ z5 X! V# F
restore$ r: _) w e9 L- z: B7 r8 @
: [% N! d0 p1 r, }* k
sum dx2401 v9 @* w% P. ?: k4 v
local tempmaxphddy240=r(mean)
7 ^5 ^6 v; A3 V
! m* R8 [7 y% K( D + d) u- O* _, D
}6 }/ o) \! N7 P9 T' k
) w7 u% L, ]! X- d. P 1 ~) W. P2 {( A8 J* x( q8 }, ~; _
|9 H, N0 F% Z$ v( m, @( v1 ~* m
) q, `: T1 [1 K& K, r$ P: D5 T : y1 {+ c4 U F; i2 e, N. w3 X
( s& k( q5 o$ w3 N) A, c gen pmaxphddy240=`tempmaxphddy240' in 1) d5 r/ r# e3 a9 ^+ I
: }9 p' e4 Q+ W! a3 q4 _
1 B: b6 m+ o" j' k8 H
*-------------ddy240pmaxp右侧低峰值 -------------------& u: @1 u5 X$ ]0 s5 L9 E x% P5 M) r
* e, E* e3 s. c! [6 n preserve 7 u% P% k% G0 a- w$ C$ }
2 {6 H# l: W7 E
keep if dx240>`tempmaxp'
: K7 y. _" G# G" ? $ G2 y7 i4 k: {& p$ D
gen temddy240=-ddy240
H" e. d; L4 U) r, E
6 J) o N" k, d' S" w+ K keep if temddy240>0
2 J4 A' }- h; D0 H, Z# G
2 m5 N. b3 [- @+ L count
E, p* o- @$ _$ ?7 `
- b0 i' H+ U: K8 D' `; z if r(N)>2 {7 o9 |+ x% C! q2 z" S+ d( y
* E0 B8 B) v; R' }
pkexamine dx240 temddy240% ^) p5 V3 P; i# I. z
( n+ j2 [' z1 {- A8 k0 T t1 k5 a7 G
local tempmaxplddy240=r(tomc) . w# O! D- ^* f" b& f
restore
0 K: D& A. |7 O1 F& } }
4 b x$ l5 h: ?$ Z" g0 t ; ~% ]! q, k2 g- O, Y$ F
else {& ~) V: o' K' s9 Y% o
restore. ?/ k5 n' P- P# J' ^8 i
di "cannot find pmaxlhddy240" {; M8 j; k" L+ y5 e
1 M" m) u6 s$ s) j
: x D' W, ]2 U' Y# q sum dx240
) C% A0 Y; y, C$ {6 \ local tempmaxplddy240=r(mean) in 1
. }8 f, y$ r. o+ N0 r0 r1 O6 ?
( E& K9 |' a4 I 3 @1 V, [/ a. b M) o0 _' p U
}! y" w6 U% Q: o% C) r+ ^
; M/ P W2 H' D( M
# Y. b/ g: g. F2 H ( t& A- z; q' O/ f; _% o" G
! e2 D6 w3 g3 ~4 j8 c / p0 k/ w: ~1 a: X5 t
# V. Q; g% Q; b$ |8 A! W: A gen pmaxplddy240=`tempmaxphddy240' in 1
# W2 Q, n$ s1 O' g* w . [, r( c: o) q( X
*-------------------------------------. p# j: u5 h% U! `
( P, Y& i: v6 ~* Y& Z gen price5d=v5 in 1/20
6 o, I( }: [9 H; H) G( P) n! N
1 H4 `" p' C& G/ b" l gen price5yy=_n in 1/20* O/ p# r4 U3 `( r5 _0 j
6 g" H1 D8 Y# w
gen price5y=price5yy*(dy240max-dy240min)/20
! H) [& `/ L) T% Z( p3 R T" q ! Y* a; c/ e" M9 S/ O" U e
*price5y &price5d
8 w* K& Z* \" Y0 b( F( H# I2 V
2 N- v1 J' a6 f. Z: R3 i gen priceny=price5y in 14 a+ X; _: R" V8 L
" C7 S) ]5 b* @, B" x
gen pricen=v5 in 1+ A! y8 r) G; e) c- \# \7 {, B) R
& }( F! d: O& _/ m ! ? u+ _% P4 e$ Y$ x, D
*priceny &pricen
; n0 |( }9 c: `" [ : I& b/ Y; P, F. {
2 l; B; t4 s# r3 m/ s5 k1 w *-------------------------graph------------------9 d* C: g V5 `3 @3 c8 t
0 X5 g4 t5 F8 ]7 D- X" E: \% E0 m) X, K
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)0 c+ n- C2 \( E( o# h a- d
5 T h6 f2 `- W) _; Q
* ---------可选项目----------------------
) C: U( J% z4 T9 U- m8 V7 ~% e1 U$ C5 z0 v/ b5 h
}
9 a1 J3 @1 w+ o; g) cend
) R" T# i" [ ^ a; x |
|