|
改了一下,这次运算应该没啥问题了
3 C5 c0 w/ a; V$ H
# S, u5 Z6 i& n4 C u8 {9 `1 i- ]! U! G P( q
capture program drop hello1 p, k5 T7 p3 }8 u0 G1 I' C6 `
t' b; O V. Zprogram hello6 c+ R e5 j9 N* M# I# _
+ Z* o5 Q: Z7 C8 y* \
quietly {
9 _- B0 G/ _7 z- R* A
- R0 D, x- l3 M0 Vclear
! ]/ f- H- k8 C- G; v" Y) K
: N% ^' }7 ~3 N& {* m5 \9 [" Pcd e:\finance\stock\20110101\source% c7 d- ~" G. X) P X% h5 W
2 R# i8 \& C6 p3 H/ Ninsheet using `1'.txt
1 a. D" i5 l/ V8 ?
/ F* R3 H8 o: s# }) k keep if v5>0
4 ] D; c# p6 d; O) ]- n
. R) d( _9 j9 F. X' }8 F# T gen vt=_n
2 `- t5 a/ o+ r2 e' E4 L " S! h9 P, _9 `4 j
tsset vt
1 c, }9 {" x" o; b; ? f( U9 M& x8 c# k9 R9 Z
gen zf=D1.v5" q! [9 S& v( ]* `6 r; L
! v8 N, m0 U) ]* M' a9 d9 X
gsort -v19 I, ~3 J3 b8 Q% M( R/ }+ {& p
9 ~6 f9 K8 u- b9 v! m gen avol=v7/v5' `3 ~# N R6 R3 j' H
' A/ R. F5 M+ H( Y8 m w# r6 C keep if avol>04 c* R) j @0 x
3 p2 C R, O9 M3 H u drop vt
2 h Z1 }4 I6 Y* J D3 c* S) d# c/ A& G
gen vt=_n
+ i* ^2 [% |5 ?/ v# @ Q, Y5 R& Y" L 1 |7 N& }3 T# `5 U! _; i; {
tsset vt- R4 c. k$ @+ f' C
$ \( O- i. O' d) f
sum v5 [aw =avol]% g$ D4 O2 @7 O! Z5 g
; D2 K$ X1 G$ d gen amean=r(mean) in 1. \2 n" P6 x% v6 {2 V' u A
6 ?- U3 ~& P% ?1 W * 总加权平均值 amean
/ g8 z( k0 s- j3 O0 }* q 7 w7 S2 u+ F4 K3 J) ?0 `
3 n2 ?- ?! v& L! e
keep in 1/240 ^$ b# M! L2 K3 i! H
% `9 L' W$ M$ {4 ~; I: s# p sum v5 [aw =avol]; |5 k( @ x8 [4 F/ s) b
! N5 W* H) G% l! y0 c: @% K
gen mean240=r(mean) in 1
4 ^6 X) Y w! x2 b8 c5 g; y1 D - C4 i& A0 W" G$ ~$ ?
*240加权平均值 mean240
+ p' ^6 I5 i" R0 ]
8 d0 Y- `. C* w set obs 500 ! D' \, }% ?. P9 u
. H$ E- \ ~) G
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
- f( z& S; ~3 D( I" y* r$ F
) S; x- N( R, R5 K *240 kdensity(dx240 dy240)
S9 [7 o- G; t * i0 J7 j! B0 U/ O; q9 B$ p7 s
sum dy240
$ s' {3 w8 b7 }8 d' d8 s
4 ?6 o& K+ y% p* e. P9 K% z gen yxis=r(max) in 18 d9 h/ N, I/ M& x1 s1 _
1 ^8 O$ g5 l" c# Z gen yxis2=yxis/23 `4 g8 w4 R1 k' n1 X" Q9 Y# F
" g9 g; Q9 X3 L: o7 ]) w& a) o *yxis
3 \& }$ I: D4 k d - L8 W( L9 d# H* z9 o9 k
gen dy240max=r(max)
( Q, N4 y C# ~+ l! I0 V $ C/ `* K' j; ?/ O
gen dy240minp=r(min)
: z- m1 v0 b7 X# U! R6 S
* k @ x4 V) E& m1 h3 G* T gen vtt=_n
$ N# f- u3 A! }1 Y( D, l5 D, R4 d& A
tsset vtt7 }0 g" O5 |/ e* ]! W+ [
7 D8 i- h/ }% C# R0 ]2 z: j; o& ~# c
gen ddy240=D1.dy240/D1.dx240
g! S+ e+ W4 g
/ M R" |( U9 f' @ Y! t sum ddy240. v! }8 {( R) }1 E1 D' t, s
u% k% M8 p- Y" U
gen ddy240max=r(max)
0 y( F/ \, j4 u3 q9 I
6 X( _2 Q" O% h _$ d) K' v3 V/ @ gen ddy240min=r(min)- @' k3 D3 F' ^# V- x
8 u, I" q6 B' c+ ]4 Y6 T gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
/ z+ o% O0 I' b9 n8 R
5 b$ v/ v) j8 d5 K sum ddy240g
* q6 B1 u# x6 ` g! Z9 e' \/ Y . m: i: y( {% [) F/ r7 F
gen yxis3=r(min) in 1- q, c! t+ F; e3 g9 E
+ H- v7 c! V5 b) ^ gen yxis4=0 in 11 Z) e7 J. w$ Y6 V, U" _+ A% U
7 y4 b6 ~7 B$ f8 Y5 K$ e# o *ddy240g : Y: A% ]3 U3 r% S5 Q
( ?3 |) b0 w* b1 L
( u' U' F/ i9 J. J. }2 F preserve
+ R0 a6 r% |- {" i
) C, [& J# Z6 o6 i" O sum v5 [aw =avol]$ v# l+ g& H% v
" Y, ]3 A9 B' n4 A# Q/ W" L
keep if dx240<r(mean) v$ J+ j. V1 a, A, b, [# s9 ~% Q
0 c9 w2 Y" y! M2 _ sum ddy240
" D) n+ i |# ?3 Z8 H
' o6 i- O+ |9 Y. g3 c& K7 m) I2 X9 \5 e if r(min)<0 { F" D) ~. o) \4 S7 q" k/ o
. G3 D- v7 l$ {6 R( C3 j keep if ddy240<=0- C3 M. b ~/ |, ^- M7 @- ?
" N" u2 o- z9 U! K- f. m, ^0 a& C0 Z
count
8 P F- j. Z% c, ] & ^9 P& @% P+ o. m D
if r(N)>2 {8 T$ x# \+ p) i3 O: s8 x
* ?- R! k9 O3 d pkexamine dx240 dy240* O9 Q% w# M0 s
* v$ U" o9 I. q% m local tempminp=r(tomc)
& G5 G! _: h, H( i, Q2 N restore - }6 H0 g& L& I
}
@/ U( W& ~ {# p# v- p . \ f9 u& W2 y! R' x- r* J& |8 v
else {
' T' V! U: f& O$ z
7 L3 S5 v% @) H di "cannot find minp"* M" k! o# T: i+ e; G( F
( {- z- _. v* l5 R% a, y restore ! c* }7 R, E& C" o, |4 h
sum dx240
+ ^& U" ~; r3 A- { local tempminp=r(mean)
9 g7 b/ ~4 p2 {' B m
4 B$ a& U3 {4 S/ K7 h$ e) D! ` }
4 b0 B: j1 l" |* M! h }
8 |6 c. f- s6 Y2 ~ else {
7 X! ?& ]2 w' e( J. b" |3 c+ v : M1 i" ?/ s9 C9 s& U% I1 J0 K# I
keep if ddy240<=r(min)& [' e3 c$ ]& h6 q; d g
4 `- }( H6 n* D' D sum dx240
6 j; g5 G, D I! }0 m9 V
' X t2 v) X/ ^( r$ \ local tempminp=r(min)1 ^% p5 A8 \( ]3 h( [
restore
3 H4 X( w) u: }4 b' c, z/ P }
# V5 |( B w9 q" x1 z7 P1 c7 n: W3 g. M; Q6 \
' V1 Q7 l9 K. Y" a+ }
5 Y/ S6 N5 j, M: A" |8 `, n gen minp=`tempminp' in 1
9 d+ z1 e6 U) t4 t% O, p5 t, j& G4 _ *240 minp
$ H* d, _. k0 P1 {7 S$ i: {$ u! ~* ]
: w$ s: B; M3 x0 W2 V: U- {' v5 B0 _( Y3 b9 T1 [1 D: R0 m$ {
3 n1 E: d$ @) E& z
preserve
$ C% ?$ d5 | W) _/ ~+ D
8 ~+ h6 d P2 W+ s0 j sum v5 [aw =avol] D0 e5 n+ p1 o8 C6 p- m
5 e5 S* d+ c& {7 S) h* z
keep if dx240>r(mean) N" E4 B4 v9 C( H
% G# E' t9 [" `! c- ] sum ddy2400 h3 T- D7 a) b5 y
& v$ x0 K6 a' m' V' p* C9 T
if r(max)>0 {
- K9 }" X/ M. w; T1 ` , `/ @) j& k0 U& f- P
keep if ddy240>=0
4 [+ i) G$ T, ]# E
- y4 Q! p4 D" N6 k; { W count
6 j2 Z0 x5 T0 y) b0 s& a+ N 7 A, W/ x5 c: ~( m+ s
if r(N)>2 {
% v$ {( \6 O& H; b" O - B. b: @2 G) e
pkexamine dx240 dy240
: m1 X# o1 V0 L8 b) J$ c1 f" X$ C' _
# D; L, N1 W, a local tempmaxp=r(tomc) - V/ y* F+ ?, S2 r6 X' v3 I
restore f' g, Z7 ]9 g; |4 o
}5 M( J1 u+ p5 J2 v2 }% I. I
' R; E8 R9 ~) u( `( [
6 P6 i3 k9 I& a2 @0 J/ E else {: S+ y1 t+ G- }9 b# c1 s
restore ( b- v, E0 F4 A4 Q7 J
di "cannot find maxp"
( W. j; ?) N# |+ m9 H0 I & ?" u( o1 R- @- z: J
8 j- ?2 a& ]9 n& \; j% A6 b
sum dx240
4 t8 ^1 r9 c+ k I/ ^9 `% Z4 H8 ~ local tempmaxp=r(mean)
; O9 ]" H8 E4 d% Z" Y
' ?0 L9 _5 h2 o; O9 \ }, V \2 m4 Z% E9 s* E# O
1 A3 B! G! F4 E! { }) s n6 H, a) a. B; b
7 }/ B3 x& B8 x% y( i/ Z# s else {, Y+ |5 y+ g% a% G) u- R
: o C. s5 x. a3 t
keep if ddy240>=r(max)
2 y: p0 N( n' a& Y 6 s7 d% P9 Z4 t% j
sum dx2403 W) K6 e7 e% w1 k* a5 w3 z: |- C
/ c W5 H5 ]- x% \ local tempmaxp=r(max) ( n4 W) h- q$ |- Y* R0 {& r
restore ) z7 ^" F' m2 c; J6 i' v6 G, n- l# {2 j! R
}% Y! f x0 k ?. K4 F
, o7 Y3 F# q6 e" R7 ?7 p( M; h
# o: i1 s) Q5 D8 q9 P , W5 Q# X9 a# w: r
) I4 ]$ a0 X! E/ G& W) P" g2 k+ u
gen maxp=`tempmaxp' in 12 J* q* r' P3 o% @; C
9 o2 O5 ]- Y) D: M/ b( k; g
*240maxp
% {3 J( X# w, X: t6 p- S y
* d* ?3 b h' w7 d! L* J
+ F, o% S' y# `& \2 e# r *-------------ddy240pminp左侧高峰值-----
1 Y) i3 Y1 s- c: I 5 G* `/ T) x4 b1 y' n6 g/ W2 u
preserve
# g1 w7 z8 V: }4 D2 G& T * G1 r% i8 ~8 v# t7 Y$ l4 L
keep if dx240<`tempminp'& ?& O. L+ D9 k/ C
- B; _" c$ a, g0 i' Q keep if ddy240>0
" g$ d, R9 j( S C
0 u1 }; \" C3 C3 H, J8 @. o0 C count% I: V& e! O1 E/ B) g- t. h
4 |& b" W( W* a
if r(N)>2 {( |" `; T4 ]5 j$ d( ~' r$ v7 l
: D0 W5 y4 ^3 E5 _4 e$ z% P6 p4 |2 [1 v
pkexamine dx240 ddy240
' r, g3 G5 N2 W: `6 ?& ~ 2 ^# n+ A: i2 x5 \% {0 ~
local tempminphddy240=r(tomc) : h% @) G6 ~5 |
restore. z( l( u# Y; B: `4 l* c! ^
}
, z# H8 _ U! N0 i
' J: Q& p! j* q X* H) w2 f else {7 B5 [/ l- h% h6 `! R
restore
1 z4 S! m$ G5 j/ m di "cannot find pminphddy240"; r L( H/ b3 |* t! X5 D; C
+ Q1 @" Z) Y+ {2 ]# h 6 e2 }: z7 C0 j( B1 {
sum dx240
' o J! h2 U. L1 [( G local tempminphddy240=r(mean) # L2 E9 R" D+ _8 e
0 b1 p5 {/ J$ x7 x
% |/ v8 z2 M q4 V2 [ }9 i8 E8 M, e, K
& K5 r! Q/ _! S# O7 e: t 4 R+ \5 E; y) A) U
3 [, d. C* a$ A+ w9 `
+ a7 {7 Q# |* d! f
% P- K- g1 G# k( ^+ l
" n+ a( K' ]6 Z' Y gen pminphddy240=`tempminphddy240' in 1
8 B+ ^; ~, s$ I# l9 r3 ^5 d* s
) {# `# c3 O! [& @/ y4 X 3 G. @+ ^7 ~( L
*-------------ddy240pminp右侧低峰值 -----------------/ M f0 F& ~" O
preserve - q0 V1 U( q3 q# G
& b, B Q, x5 g/ f3 Y8 A, z keep if dx240>`tempminp'9 A( Y+ I" X4 w0 J/ A, ?
& [5 m% q; D3 ~2 G: u( W keep if dx240<`tempmaxp'
( J& y! \) E6 u" G
* b' I: R& |$ w( u) _ keep if ddy240<0' b% K& n8 \9 @2 x- X8 q9 \
R, L3 {- [! d* o( ]( {& i# V4 f9 D gen temddy240=-ddy240 M% p/ X8 r2 Z9 x0 o4 R
. T/ R# F: e/ T; T0 O4 h/ r4 _, O) f! q count
/ H' Q2 E" `- B$ p( u
: X# c" I9 ~7 l* C/ B) ]& l if r(N)>2 {& w* g# o. h }# t) v" g7 H" O
" t1 h& o% e/ b
pkexamine dx240 temddy240
% d& i) q" t& n7 |* ]9 k : N4 J m4 r4 [$ B5 w" o* @
local tempminplddy240=r(tomc)
0 d* w' p' f4 K% Y! m' G7 D3 y! A restore B4 K$ a, G# M! u! C, o* G
}
3 n3 `% U, W3 N8 l! @
( i: B, J3 l- n4 n6 ~* ? else {/ z3 m) c0 [- X& o- C# k& \
7 P- w* P% K" z; y3 _! f
di "cannot find pminplddy240"
# ^& i) i; S D restore
) Q% }$ S0 a* e6 ], u! Y$ b( s7 R
9 m0 p" s4 d+ p0 K$ E sum dx240
- C F4 t& B* X* U2 r local tempminplddy240=r(mean)1 V2 Q7 `9 {8 ]9 m0 }' }
1 ^( j3 o* I f' N0 l9 ^% Z7 [4 O0 j
- ^2 h6 k) ~, y4 ~
}0 Y( c* ]% h/ A0 X9 h0 n3 U b; u$ F
% d2 j+ [- q0 S" }5 z) @
4 x3 Y: B3 e! S0 y9 T% x 1 u* F: X! _, _& g3 S
3 b2 |. J1 F0 `9 S+ T ; D5 [& I0 S1 |+ l0 ^5 x& w
gen pminplddy240=`tempminplddy240' in 1
q) j0 v3 m" J ~0 a % t8 x: u8 J$ X/ b
*-------------ddy240pmaxp左侧高峰值 -------------------
7 |! p4 U5 I8 N+ h( x# @
+ x- D x" ~5 x0 U preserve
+ e6 k7 [4 u' O# T6 H/ }
" `* s) \3 e6 E& D9 ^ keep if dx240>`tempminp'
( b& J5 d8 h; O( `3 H+ j* g
% Q3 m; ^/ S8 q keep if dx240<`tempmaxp'
~3 h4 f$ `1 ]1 z5 @ ( R# G' `" ?, _" a& f+ o7 B
keep if ddy240>0# p! U' P: s$ q; M! d
count
% c0 N0 l2 {, V, I5 ?! [ 9 t1 t. i! A4 B
if r(N)>2 {
0 e3 L* E( f4 a! @" L3 K; K 1 A7 r4 o, J( ~
pkexamine dx240 ddy2408 M1 _5 \% G. {7 ]9 `1 u
+ }" c T# e! O2 n9 S local tempmaxphddy240=r(tomc)
) z& O( @- H e1 [0 U7 K8 ]: |1 z0 y 3 U8 L. q) C% p
restore
' g y6 a* |( a; P$ W" L6 e" } }
, A/ W- L- b0 ^7 @& \' G. a: i ( S$ p" w" [6 P) X; Q& [9 b
else {$ V" R9 L+ s" l' }4 f$ Y
6 D1 F4 g4 i: h% b+ C% d
di "cannot find pmaxphddy240"
) r) Q( v, ^* X. v restore1 W0 [3 Y2 Q+ y/ B- J+ ?
$ h4 y- b8 i }9 d6 z
sum dx240
1 B/ p0 \0 R! S5 F, v local tempmaxphddy240=r(mean)
7 a/ d1 {, _3 O Q% Y, u9 F5 a1 T4 i( y0 P. w2 C
9 R$ v( O2 M" K }
! Y4 @1 I- C; A n$ N% ~ 3 b$ w6 F# d- E( `- @8 j
4 K, N5 ~; O$ y: `+ _/ G) f8 L B% q
/ ^! W4 R# G! `
( N; G+ M: c, K6 ]: n. y% T' T s
& P: w: P9 w' Y' P$ O , F: L% J, n T0 S
gen pmaxphddy240=`tempmaxphddy240' in 1
0 K3 Y. i& M0 l( a5 a( q, S, g& A * `+ R& t; ^( b3 d4 C5 f0 {! k2 i
3 I' ]4 O- o% e *-------------ddy240pmaxp右侧低峰值 -------------------! @/ G' }/ J1 E0 A
* W% E/ [7 `! _7 }
preserve
4 b/ y$ i4 { [' I d
0 f6 b/ I. s' E/ z keep if dx240>`tempmaxp'( ^5 g4 J% Y, w- \1 ~! I8 k
: A( E# F; B D7 a7 g gen temddy240=-ddy2405 m; v3 ]: Q; h: ]4 L3 v5 k) s* z
. X2 P1 q. U; X( f& @
keep if temddy240>0( c& ?6 C) k' A2 `6 x
" a1 b' d( U0 q& _- y' U
count$ u; g# {0 k/ Q; v3 a
# K" f% R9 m+ v8 D
if r(N)>2 {
1 g1 w, Q, n( z) _# W* h1 Z' [
5 x4 O$ o" V( Y$ h/ A* f9 W pkexamine dx240 temddy240' q K$ o% O/ T# V1 B
3 M, g' Y) c0 W% R% \# x7 f: t9 C" {
local tempmaxplddy240=r(tomc) 1 f9 D0 c: F9 s% q
restore
2 U0 P0 @, O8 u: Q5 n/ t+ f# L }$ C. F9 {# O4 C; Y7 H
9 j: y/ [3 o+ K5 G( }* G
else {% P L6 b& r9 a# |' w& d
restore0 ?$ T. ]# O9 y6 |
di "cannot find pmaxlhddy240"6 b4 i7 a5 X z; r, f- c4 Y. i
. b) R$ n+ u% |4 t: a) {/ f3 f
( A" ~% [- H" N# q7 x3 W sum dx2402 }+ a( l, U$ u( b& N3 o2 k3 H, H
local tempmaxplddy240=r(mean) in 1
* L& g% j+ l, ^- m; J
) i0 u, K" N3 H) m% y. X
" q; Q& [; C2 {% h }+ w* O& p$ J% t5 j/ ~ ?5 ^
- X; n1 U9 K6 f
$ c7 {$ m! t1 p$ Q
" Y: |8 E" f% q" Z% L! u7 Y
' k0 t# t# W% y3 d0 D' h" J. t
( m# X, [, ~6 N8 K, ]
/ d8 k, Y5 |" S$ v gen pmaxplddy240=`tempmaxphddy240' in 1
% K* k! T4 I& q. Q: R* ^( h1 D- }: |
0 o% _/ v) \" T9 v *-------------------------------------: M) L( T- ]$ L1 U7 X: k5 v$ {. t' P
y0 o3 U; _! B" r; ~
gen price5d=v5 in 1/201 n6 `1 e1 }9 G+ T0 x
$ w. e' E2 Q& K1 g5 e: T! A
gen price5yy=_n in 1/20
$ r% ?/ _% i0 ^: w, G( b6 s. k+ @
( t9 @& A$ X( { gen price5y=price5yy*(dy240max-dy240min)/20
4 B5 |' V% E* B0 T7 n& E ( }7 [% `$ Y: t% J! g/ d& Y3 h( k
*price5y &price5d
# e0 ]0 x0 m$ d! y4 m7 G
: q$ d6 E/ N% N gen priceny=price5y in 1
' P4 l- Z' }6 X' ?( o
/ k) {) B8 F7 I7 s0 \' t" D gen pricen=v5 in 1
- T8 e9 r! J8 U$ k. P$ S. T" N; D% G7 H9 W
& \' ~. l1 q6 z! [
*priceny &pricen6 O& Y$ R. }5 C6 @2 F
4 M, }* g' `0 ` # {1 F5 \: C8 |
*-------------------------graph------------------( n+ E2 h/ \% N7 ^ h4 H' n- R
" }, g- P! g- Z$ y) s; w" @ 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)
: ?/ H. B9 ~0 h/ P! b
' F+ H& M+ S) B) M1 N* ---------可选项目----------------------' {% p8 b( I5 {; n7 @# [& O- F. [
7 T$ R" ^! N) g6 p3 T}2 [# w5 ^# k6 f- k
end( c# U3 D5 @0 q. C, U
|
|