|
改了一下,这次运算应该没啥问题了
$ N S5 Q3 \8 S p# R6 [* h. d" B, Z7 n1 d% @5 L5 D' ~ s
: h; p5 B- D3 x9 `" C
capture program drop hello
( b4 W' U6 X s4 {( [/ x9 e. [; m {
program hello* ]- i) z5 Q- y& F3 b3 X
$ o1 F4 d( d9 m% H7 F2 a- n: D
quietly {! \3 O& C" r. P% h8 ]: ?9 U
# f0 m% l/ [5 q4 V9 N6 H! c. gclear
, }% N* t: o8 Z6 N8 r% B
: ^* Q) Y# c) {0 p7 ^/ [' Bcd e:\finance\stock\20110101\source
9 Z" E+ R3 U. ^9 w1 \, X
4 z" g& M1 U/ E! j& S$ v, I( |insheet using `1'.txt
. J, O* u4 E5 L/ V2 G4 Y* E# V( n+ [& J j
keep if v5>0
( Q! [, b+ O; l/ _. H U. O
* ]8 Z; [% I/ u* F% \* y/ l; J gen vt=_n6 N S) w$ R# H( A$ j* N* q, h
. R! s0 E& p: g; \& c tsset vt9 Z$ e" b% J. n$ E/ F% ?7 W
1 d6 z( h* U$ ?) E( t" U- \
gen zf=D1.v5 E3 D" \2 x3 Y3 g/ B
( t( V" ^0 _( x4 z gsort -v1
' u4 g6 c3 c- Q6 Q
1 `* ~. u# b& X7 P& ~/ B/ p8 x) l! N gen avol=v7/v5
# S I0 T. c, E# C . Q8 U# A/ ]9 c& e0 y' L1 A
keep if avol>02 S" E' F$ f) h
# Y1 V7 g# b' E+ o# n: E
drop vt
" P4 J) L# o4 O; j7 V$ k : v, l H2 S( y" L" A
gen vt=_n
; c K& u4 i/ ^, H Q, z% H6 |2 m
' P" c6 }# y2 G8 ` tsset vt# C% H) ?+ ^% |3 ?2 g% a: y) Y, U0 k
5 [7 W& U, }7 ^. z% m3 M4 u
sum v5 [aw =avol]2 @" Y- e, X, p. {" }6 @1 j ?
$ h) ^! V, A/ F& }4 P gen amean=r(mean) in 1
, l) Z2 ~ Y+ q- s9 T
( n8 D2 E& _% ]+ ~( Y. j P P * 总加权平均值 amean& O- X$ U5 P, `/ O
* a2 z* Q( O4 C! ]* u
) I5 @4 v) M7 K5 A- |# ^7 T
keep in 1/240
- v3 D& G: o: u* I( y
* x, r: ^; W3 d; s4 E sum v5 [aw =avol]/ q0 f% I: O1 k7 T0 L! a$ Q
/ T1 X; c x O. l# e) T4 t2 F gen mean240=r(mean) in 1
" V, `% b* _! k% l
. ^! e! `, s) O' S- p4 ^$ e2 | *240加权平均值 mean2405 K! B% T6 s |1 v' e4 w, V! Z/ B
G+ R. q; W: {% x2 ^
set obs 500
6 X' u- s3 P+ z1 F* p) \! b * l, y& L9 ?" {) o. T& r' ?+ t2 k8 v
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
3 r O% ~/ s# I) W " e2 m+ a' ^0 I
*240 kdensity(dx240 dy240)8 }8 e6 I3 R q9 R& | L
/ F' |( ]6 X. l) d% \ sum dy240, L: N& W- J' p6 ^. |
/ E ~1 K4 ~( D! h5 j- w: v gen yxis=r(max) in 1( B" V+ U6 q9 e
; z, M; s# w6 P7 ] gen yxis2=yxis/29 r4 b* Q( j3 G0 C+ }& _$ U5 T
+ ] {" P$ P7 E$ [$ \
*yxis! o; o. ^9 B! C% y! r' d
1 V4 A4 D1 |- B3 ~& T* k! B: w gen dy240max=r(max)
; w1 e/ u& m9 T) z* t v 0 |$ K& i& ]; g2 ^
gen dy240minp=r(min)
$ b( \ y ^6 S- @2 V
# ?& U- D* u1 @1 @" a gen vtt=_n; K! m& T4 C! e2 x3 C/ a
( {" q; k7 k6 n' F tsset vtt7 z7 [$ F! P0 ~* g
- d. U( T& q$ y, d: Q# c( V gen ddy240=D1.dy240/D1.dx240
5 d I- J+ j) k( Y7 l8 T) W
! }( l) B* R6 Z! |& x sum ddy2406 U; ~) F! G# h1 q8 S6 A2 Z
; r2 J$ w" C, M$ b; D, L* K gen ddy240max=r(max)8 a9 p f/ Y1 J/ P6 o
, M4 R& w7 i/ J ^5 V) ]$ q4 v
gen ddy240min=r(min)
% l6 n6 G- F2 k& H/ k+ a - C8 V+ B$ A; S0 r
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)! z+ o* f6 B3 h
( R* B6 b8 q5 K" A9 R0 m) E sum ddy240g. P( J/ s! }, D* D
! q7 G4 R5 J) \( j# c
gen yxis3=r(min) in 1
' x8 [& ~) p9 O' g- H$ u
+ m0 `8 Q6 B: z% v gen yxis4=0 in 1
" _+ f' d' l! t) a+ Z0 b 1 M- g. v8 f( L* G* X
*ddy240g , W/ v0 L$ R/ a% ]1 Y) }
2 J; c, i( P2 Z' J- W4 L& C # ?* n9 r0 g7 B1 x6 Z7 z- t7 |
preserve / T6 O! O' s |+ Y! P
0 u5 P& R, q! }) @" I. Y% W sum v5 [aw =avol]' B1 s+ K: q$ ]7 c+ Z! S- t
( Y8 J# Z; X; w keep if dx240<r(mean)
( Y! K& l. Y9 N# ]7 y
3 {! I3 o9 r- M8 B sum ddy240
! J* f8 Y. |1 z; W% u
, ^) L5 ^# \1 \- U2 ?8 X9 o4 ]8 A+ | if r(min)<0 {& g/ X$ \( u; m% n0 C
# L \! ?0 U: ~; n8 ?
keep if ddy240<=01 p& n& W8 y( O" K
( l2 _* H! N2 I- \3 E- y count
" B: `# b% k6 a3 M9 {0 u/ T 3 O. t- @7 [" H/ w) H1 @
if r(N)>2 { i7 b$ {& J# C, y1 ^6 [6 d
0 B# K, [- G. G' H+ w* m pkexamine dx240 dy240
0 G4 S5 ]$ ]/ g' W& r3 x2 ^+ E
l W0 \( _* I. a local tempminp=r(tomc)& R1 R$ M) B( ]& \. e
restore * a, q7 ^% p$ G' H1 r- j+ l
}* q: x d0 D( f. f& F% `+ h1 m
) v1 y2 ?7 W. Y `8 D
else {# ]' u2 u: I7 u3 {% k
2 l! T9 K) ~# o% z1 \5 { di "cannot find minp"& H+ n0 z6 U( P8 Q: W% h
1 _/ |" M$ O" f# `( o4 B* c2 j restore 8 w; S9 W& `8 O9 r
sum dx240( e1 G2 Q/ K" D; B$ c, O
local tempminp=r(mean); W- R& p% T$ Y9 c9 J+ j6 N+ A
* B' ^6 k* _3 B! Y' v
} M3 n& D3 _" o+ ?0 T
}
" l$ M2 Z; ^( m | f7 f. q1 y G else {
, T: F/ ?; s3 G$ w7 E( T/ Y
: i4 r1 ~7 O. `# ` keep if ddy240<=r(min)4 e& j g( G L1 V+ |+ t! t& U
( | w! Y' U4 J% Z, n sum dx240# ]' v! e, ~0 X9 x5 F+ s$ V
8 \4 b$ N% ?0 S: v
local tempminp=r(min)3 d- c1 K5 H2 u( R. V
restore # m0 _/ i i- u
}! \3 }' y, M: z, X8 V/ g8 b, j
3 p' Y. D; n _! D) x& {+ y$ x* D% @# m& H. ?( J8 f& [' L# `
# f* L4 D# g/ `! s7 H z gen minp=`tempminp' in 18 }" b1 w+ D/ O) e8 h3 Z1 `) F0 E# o5 s
*240 minp
7 [* ~. {7 {8 h& {) P
: r% u! f) q [! Q; k& j/ c' U$ i2 M. m1 Q4 L0 I; h& v
C' L( N# V' R% n+ X
preserve : W9 x8 G. [$ w$ Y+ r* @
" t- L4 L/ C5 O/ z' y sum v5 [aw =avol]
' X' o- Z/ F& J; i7 {8 `! R9 n
# O0 b4 G3 J, | keep if dx240>r(mean)( S4 w+ \ `# D( _7 Q& O
`. A7 B4 A1 u; Y5 a: Q
sum ddy240 R& w, ^, @/ s3 v r
& @, L1 |4 Z1 q* ]; y
if r(max)>0 {
7 J) ~) j! I; P4 I- F; a2 B- L
7 z% K1 C+ U9 F H- Q) `$ k" z keep if ddy240>=0
. J* n5 u' R% v- n% B7 W9 [: U( o# M 4 L) h- ?4 T' C8 ?
count* k4 ~$ m, w( _$ v* c
/ u/ V! O* R; M5 Q: L
if r(N)>2 {
1 n. ~+ n+ v: A. h 2 |: a) |2 F* f4 H- z$ N; y
pkexamine dx240 dy240! I+ ]1 r# i2 b) V, w
* W8 D- J7 `, S" x local tempmaxp=r(tomc) 4 @) j, b9 p$ u; b8 |) Z5 Y# }
restore & E- o2 o w9 J- I! Y
}7 }2 h! G$ Q1 i, s/ b1 ^ N) A' ]
7 c L0 x' S, i" e8 D) U. ]; h7 r8 O
8 {/ P4 v/ P1 U6 }9 \+ ` else {
+ K, F5 _6 I c restore
! g0 ~/ v( p/ z8 v# p4 p di "cannot find maxp" W( S" j7 q, Q9 Y. g
# o Z$ L1 K) z6 p h* [/ }& F+ R
* ~% Y' ?5 ~. g# w sum dx240" V6 r+ V* |$ n6 \
local tempmaxp=r(mean)
9 \2 Q+ g+ P1 Y6 b2 g$ Q3 s6 Q 9 g! ?2 B2 A9 z1 T$ D
}; R( l2 }, I7 i
$ c v8 n# Q( i# @ }
2 K+ y% m9 F5 K3 w. \; U
2 U; f% K- d6 x, l! t) ~' L& F else {
. X9 ?8 Y; ~! Z! R8 \
# I% z |7 h5 M, c/ D8 z( ` keep if ddy240>=r(max)9 I. u3 B) F: O) q `: [+ V
( i' t, r5 d0 |" e$ s3 [) ~4 `/ X
sum dx240
0 G6 Y7 q, L$ U) C6 F3 W8 m
4 k& |6 y# Z1 R local tempmaxp=r(max)
h+ S( S' ?1 g& B restore
4 G/ |4 c$ X% r; z }
% t" H6 o$ }, ]+ i4 z9 w & u z+ K, `3 a1 ~1 f/ ]4 e
8 _7 r0 l, r8 G0 t/ c- g
) |$ B" S1 Z. A
: N8 `0 H6 C' w( `, A7 L' H* s3 l( ` gen maxp=`tempmaxp' in 1, d' X& w0 j: J, e' W( ~% f0 u
" w( e G, q* e0 _, u
*240maxp; ?1 P+ I. y' Z8 X/ M
# v6 C% J) e# C 2 ]% Z9 F& `: L4 f2 V
*-------------ddy240pminp左侧高峰值-----0 _8 n% A8 i5 y/ c+ N+ \9 V
) `! l7 B5 N( n
preserve d2 t+ M9 R; ]5 ?' ~" }+ j2 J
# \7 F8 @- S/ n/ J9 x! K2 ~
keep if dx240<`tempminp'
/ H+ S. ?, f+ w
1 O6 K" f6 o- \9 h' q+ E% ^ keep if ddy240>0; H# v6 S1 _ f4 R
+ h/ G: D" V1 ?, m
count( o ]. i2 B8 G0 E$ f0 O6 v
0 f" a! |5 @5 S7 U if r(N)>2 {
+ K$ ?9 Z4 O1 s; }/ E% c
/ }# }/ t: I5 i/ ~* Q) J7 K pkexamine dx240 ddy240
! x5 H* P+ Z b $ Q/ o. r: S9 v1 n% m; @! l3 h1 I
local tempminphddy240=r(tomc) 5 T' W8 a* n- ~" ^2 B( a
restore3 [" ]6 ^0 V+ W: [. O, }- q
}6 Z, N' }( g) f% X+ w3 p
- h) [' b/ }: u0 Z7 {; a" C else {% V% Z. q; z5 F6 z3 H4 q% @4 ~ _
restore
) e0 T d' L! ? di "cannot find pminphddy240"
' _7 F+ o& e c L# v' K" T
$ P( M8 R3 s0 C7 B
6 X: V$ e) d* f3 @ sum dx240; g; g- m1 [6 @9 P1 m' |5 \
local tempminphddy240=r(mean) # `4 @4 T) L B7 W n1 i% I! L
' e; [1 [/ L; I7 v7 R9 A
4 t/ W: X0 U* B& h- u
}
# ~7 J2 {3 L9 T+ s / e+ Z( ?- e2 t6 x" C
" G/ m9 M' [4 I; E2 `% X
& d( f" x4 {/ u
/ k$ j/ U# i5 c! ]& k) X5 C
2 V1 J9 w0 V/ A4 F! f. F3 Z
$ U2 ^6 U% e/ `7 j) ^: b4 B0 I2 B+ k gen pminphddy240=`tempminphddy240' in 1
' x \+ d- |/ e- ~ 5 r- g. G s# O
+ H1 ~8 ]# c1 f7 u' l
*-------------ddy240pminp右侧低峰值 -----------------4 e: G1 l) P& G9 a( K
preserve : N) T2 Q, m: W1 T( \( e7 y {
* d2 n. B' Q8 g6 H% ?: e keep if dx240>`tempminp'2 Q! V- K9 s: {2 ^
7 X" @5 t+ X4 u* q" k
keep if dx240<`tempmaxp'
/ r( ?4 {4 X! J0 C3 q# k
~( O' t; r9 ]+ R* Z3 z- E/ I% Q keep if ddy240<0/ [3 y) `1 e. U9 Z" h
# P7 B7 [! t$ L M( R* [
gen temddy240=-ddy240
& L8 r* E7 ~, ]9 c2 t! W/ i 8 X4 W' R' \/ m. U
count( t2 l" U1 n- L$ R" m
9 U, g% N8 \, n; ~
if r(N)>2 {
' w4 E' v7 Z* E' D I. h
7 \- V% s( g. C" t pkexamine dx240 temddy2406 k$ v- J! e: ?4 q
4 P9 [3 g: I6 b* T% G
local tempminplddy240=r(tomc)
0 X7 J- x6 j; h; a5 b" H7 K restore; m0 U) P$ A: J
}0 p4 g& H" _1 P; X( \0 ~
' a# k e6 `7 s- a6 ^/ y else {
: Y5 E6 r: q5 b J7 y& O' _
0 t6 i4 p, y, ~/ ] di "cannot find pminplddy240"3 T& y1 N% S6 q8 |: l
restore
) ^* t; B6 T5 [; \/ \ Q* M8 h ( J3 \! y" s; K7 K
sum dx240' k$ t: h9 G0 ]# b2 p
local tempminplddy240=r(mean)5 d- b* h$ W& Y; z& I. X1 i" K
3 ~1 Y; L1 B0 ^7 h3 q
3 C0 v- i" o6 i
}
) @3 G- P' M: [* {2 B h: ?* w8 t7 V' p
$ R& ~# H Z, Z. ^5 b) {+ z
8 N" R. j" {* k( E$ m 1 s8 ^8 g2 } ]( |
, W# i& w" Q6 x0 Y$ R3 s
* x# Y2 `- ~, n' m6 P
gen pminplddy240=`tempminplddy240' in 1
8 A$ c0 P5 s: `7 ~* O . U" j0 O/ r( c% |: v) Y
*-------------ddy240pmaxp左侧高峰值 -------------------
" s: v: R4 P0 ?/ [% c( O / c G; F- b4 n& [6 \7 i( k
preserve
$ X5 K9 q- Y- C% G8 \ 0 c, `3 f6 j& C; M* k: c
keep if dx240>`tempminp' I6 S- t3 Q2 p" A F
4 X+ J+ h8 \, w1 y/ l# v6 L! K keep if dx240<`tempmaxp'
- U1 f3 n% v8 B& }7 b) [ * v4 x( ~2 v: m4 B
keep if ddy240>0
; X( C* v2 z* s; O: A4 V( ~ count/ T% K# u. E7 m; P
" P1 E2 g% O8 A
if r(N)>2 {; Y T8 t |2 ]) m! z
r, G8 F# X& C6 M$ W2 c pkexamine dx240 ddy240
0 H5 s! P5 G1 o; O9 N" d% y
* F5 v7 w7 a$ P6 c' U& U, `2 p# i local tempmaxphddy240=r(tomc) 7 M3 [( y6 I9 z, u% w" C* k
5 E: w" ^+ q1 e0 g$ f9 @/ I restore
" m3 P7 U: B4 J6 a, X }9 I/ p% b1 p: Q6 I3 Y
9 p6 e5 t) s) x Q9 q, [
else {
/ S7 u5 _7 _% A; i6 L % F" u& p4 z U7 A3 C) Q
di "cannot find pmaxphddy240"1 `1 c8 o7 H6 u% z* m3 q1 M. ^
restore8 C; g, _( G: g2 p
5 y* [/ l( k2 A+ y+ S1 z' m/ K$ ?* V
sum dx2403 |) o" `' j9 P8 N5 O& [
local tempmaxphddy240=r(mean)
, |3 U" _" a6 r/ c1 S& T ' a/ i. b; ?, M' |2 @
& B1 x4 j1 Q* j* d
}
) o. A+ j" R) V " Y1 w8 w6 c1 R) H. ?+ T+ }
0 b: y4 a' u0 |. `
& i1 [3 l9 F- j9 T) B" }9 q 8 L$ H6 W6 [5 P1 n
! W( Y" {2 g8 W" h' N2 l
0 K6 Q Y7 q9 K
gen pmaxphddy240=`tempmaxphddy240' in 1
& D' M" j0 t) e. s+ I y
7 L1 L. b6 p! E. y , o, ~$ l$ j4 L/ R& r0 B
*-------------ddy240pmaxp右侧低峰值 -------------------
- M( k* T( O/ C7 K & Q: I7 C4 a/ M, B/ o
preserve
! R1 c8 \4 f8 q- j4 V* k 1 N4 t1 a6 t0 X! j, x7 y9 H
keep if dx240>`tempmaxp'! |& w: h- O( y2 L3 ?7 |
8 e$ w5 v" K4 z" T
gen temddy240=-ddy240% `! u z6 N/ a# n. I+ t; [
4 F( B7 Y0 A8 A7 \: B keep if temddy240>0
# |& f5 x' X& D" {$ J
6 d' X; Z; k4 k8 _; f count
2 k& L$ V+ c4 t5 {/ H
8 A, U* t8 ~$ q/ N5 o if r(N)>2 {! i) }% }( X8 o) [4 r9 f1 `# J
7 Z# I% H4 L4 T+ W' N pkexamine dx240 temddy240
9 Y3 {: ?8 `9 k% ^" B$ ? 9 F% b k; h; k4 r: Z
local tempmaxplddy240=r(tomc)
) H! L. L$ v3 _; n2 t1 c0 j restore
: C( y3 L9 k* l$ y }* a1 M: Q& R; S, O) |2 `) e
7 \& n- I0 b. Y& A0 L7 `) m else {
7 d* O* \7 Q y2 D restore
' x5 v1 c9 Q, U' S: R3 x Y8 x3 j di "cannot find pmaxlhddy240"
" }2 [( \. i: _7 w
4 } i3 T: i/ ~" h1 r: m
2 j1 a7 t# g0 B sum dx240
- H5 h( t3 t& I8 l local tempmaxplddy240=r(mean) in 1
% k" b; M- e4 b 9 B$ i9 H; k6 h5 [. D1 h2 s8 s; \
3 p& d9 B0 w( C T4 ]5 ~
}" X) l& p' f+ s1 F/ f# q
/ f0 j% {2 o! s! X 9 D9 W; e7 F9 {: Z
: k' i3 h2 A, O3 B: [" l 3 a+ Z- y+ M8 W* d% F% {" R
) Y3 O* P( L7 Z7 O4 s* K* G
/ E6 o4 c$ g9 j& B( A" A gen pmaxplddy240=`tempmaxphddy240' in 1+ H% ]' e* {3 ^. u" @% ~$ Y7 z
2 m5 X6 J i( a; [ *-------------------------------------$ \6 X+ g& n/ r) q
: {& }. u$ C! P0 b! w3 l gen price5d=v5 in 1/20! q& i% V" m% T
+ X' w: j8 h5 m: V+ u" f& p* X gen price5yy=_n in 1/20
3 L) v' q; F0 X
; I6 {# o2 t4 c6 K# f+ J) C gen price5y=price5yy*(dy240max-dy240min)/20' I3 q) w* u" K! A
: M6 o m9 G) B3 t# H' J
*price5y &price5d
' _; X3 F `7 U. @) H u" G D. L, e1 q) E1 O5 x; K p8 a
gen priceny=price5y in 1
9 ]: |7 U( y3 d) Q: K 7 `- M* h! M: T$ _# _/ n
gen pricen=v5 in 1
. m8 s5 |. w1 k2 T
4 s9 T% |# L/ B- B 7 v8 a' Z' [0 p' M6 B# y
*priceny &pricen ~: b, z* m( i6 R4 }2 D* Z' M
$ ]6 t6 r0 A8 u6 `4 G! T5 F7 e) [; ]
|0 \6 f9 n. c+ d *-------------------------graph------------------: q) u/ _. N/ I+ g9 S
1 x- @% U% S" K- ~$ j# J+ u3 \6 o 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 u' k( ~9 {% Z2 D# X8 ]; z3 C
1 G4 t% H' [: @7 o$ q* ---------可选项目----------------------+ V% ]. p6 v) j7 d3 V( f9 U
9 d& c" i; B! f5 l5 g4 X( ]# A9 A! L}
2 n' l( t/ [) `8 S, xend1 ~- F$ l8 |3 a/ l8 u( J
|
|