|
改了一下,这次运算应该没啥问题了
0 D1 f* c4 X$ h% u k) Q- ], x
- v8 M& w8 @# T6 X, ]# J" a. T- T8 ^( x& k# S8 O( N. M
capture program drop hello
; ?; w0 S9 F* u$ @4 T$ K
: p. g( J+ e: Xprogram hello4 j9 A0 Z. ?% Y" V$ G' ]9 d# A, L! X
5 ]" b5 o7 p; m" C( l( b5 L! X( I
quietly {
) u7 V5 W! j6 d j4 b" r6 Y+ c. B/ f8 U' k7 w/ E( I
clear
5 W' c/ v, ^" [% b b( a2 O2 R
: x6 l0 h+ {7 L' Zcd e:\finance\stock\20110101\source! r8 }8 a5 H. L
6 P3 P; T% u; finsheet using `1'.txt
0 l9 p7 U' a& z% Z9 L3 u* q* J: |
, M. G1 X# {6 ? A- n8 x% |, a9 c* Q keep if v5>0
& Q/ B5 q2 b0 U8 r
9 l8 e/ i: V( O gen vt=_n) L* r: c4 U0 o
7 I+ Y2 B' ?, \. Q* T tsset vt
: M" X( I5 _4 ^, I5 }- B
. n8 s1 B& c: t5 _! f gen zf=D1.v58 ^, `* ?7 {+ ]1 Y
0 N" u4 z* Q* Q gsort -v11 N# v4 E! V( [. M% o7 e
) d5 A; m+ }6 S4 Q gen avol=v7/v53 [, E4 G7 X" X3 [% I, Z8 D
5 u2 g# o- f( R! z1 p ^9 K keep if avol>0
. y. P. P$ ], C & k1 L2 Z. K) R7 `
drop vt+ C3 d3 H2 L( P) s! I) F( p: V$ \
. j2 ] c p" P2 p! H7 \: W
gen vt=_n5 H; y8 e: d% q) f- z
( A8 b: h- m, G# k: p tsset vt, z& R* r7 ?1 x* d7 }6 }, n. M7 r- n5 ]
$ t3 d) [! m# ^8 Q5 K" M8 O; r sum v5 [aw =avol]8 e5 q; H, P+ w' x
+ @! E6 ?* }9 p" _6 B gen amean=r(mean) in 11 f# ]- ^5 `. d7 ~
& y2 \' g) U6 b. [
* 总加权平均值 amean
( [! v1 H7 W- k1 s; q& { / g2 ?8 z! B. ]# N& Z! J6 d
, u$ o1 X4 m2 U: a keep in 1/2405 V( A3 c% }1 o; Q& T9 ]/ b, i
K6 |5 b+ G4 s sum v5 [aw =avol]8 i, p) _+ a" \3 r& G' B P" e7 Y5 `
8 e/ j. b& i1 W, F5 V8 k8 Y- ]0 V
gen mean240=r(mean) in 1( ?; u: d/ y' w0 Y. i6 H. r
# R# v% X; W4 ]0 A% k2 w! {: u; ?" A *240加权平均值 mean240
- }1 e$ ?! X j6 Y % F& q2 T# f/ m; k6 O/ ^
set obs 500
# Y" L8 ?" m/ @, @ 9 E X( d5 V: h; o! Z, l
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
: S4 C! [9 \: a7 A; v$ G6 l; m , _! d' r" }1 J( ?0 z; l
*240 kdensity(dx240 dy240)2 r# D r& j# Y, Q% A$ |! \
% e% `2 h6 ^) {; r4 ?9 t sum dy240
# n# s# M8 T" O- ] & q. C i" ]5 f1 w% }0 S9 f0 z
gen yxis=r(max) in 11 w7 X$ W0 d$ k) a% M
7 N* h. V2 x- y7 i n
gen yxis2=yxis/2% b5 s" R3 X. }8 Q9 c" x8 s
, O( z7 e, q# S1 ~
*yxis* p' |! {7 Y1 ]) m
' I! W3 T. b9 _- A+ D( M$ u1 G
gen dy240max=r(max)- u& ~1 K+ r3 S- u
, Z4 B* Z& C, R+ @0 R: g gen dy240minp=r(min)0 @7 ^2 ^. _6 _0 Q7 p
! z) s# f! C* f3 e' E: `, X2 ? gen vtt=_n
) v2 c2 U6 T+ O! A0 J7 E5 F
2 {) j0 ]! ^3 ]& d9 F8 a tsset vtt
( Q3 D% _" ~2 l% u# y* h0 _# j* u( k" \8 x: ?+ \
gen ddy240=D1.dy240/D1.dx240( W" `2 x% `6 P0 X+ [! G b
t- W0 K7 F: Y) }" q3 e- Y
sum ddy240
8 _! \. ^0 H3 ]7 R$ G) r: R
. A% ~0 Y/ s' Z2 O, s7 Q& l gen ddy240max=r(max)* r1 B9 |% r8 t
' J7 H! g* c' i; ~
gen ddy240min=r(min)0 Z F/ T! k. n. V u* u
9 E z" h3 _1 `7 p' N' { gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
6 O1 l g1 v8 U; V5 V
) Y+ c$ x' r5 g W. [ sum ddy240g
1 H( C) w' @5 g' I) p . f$ e) T. D9 H0 T/ A. C+ s
gen yxis3=r(min) in 1
. t! ^9 a- @1 d* m: K $ M% g/ F; N) f" o n
gen yxis4=0 in 1
& P& E0 k4 U( M9 b+ S
- Y0 y& g) S7 v( c2 N Z$ L *ddy240g
( E& W' ~: U, b8 v, o. g8 V
. V& y" ~3 i" T, r; ]& K
4 u3 Q6 ?. c2 `, z, T preserve % ?/ @0 }& e. I3 ]$ o. e B- q
8 Q( w. o/ u$ c- g
sum v5 [aw =avol]4 l& R* o' S/ J( c! n" Q
* F; ^, }& o4 \ keep if dx240<r(mean)" z: x( p9 `# m2 f5 R, g
1 {5 K" B5 V3 @; k
sum ddy240
n2 o: ?4 t+ D7 w9 E2 t9 M+ E 7 `% D6 ]0 M' C+ O8 `& f F2 {
if r(min)<0 {/ _" I) h6 v6 P8 w
- y1 J7 W( E! U3 j g' l* L keep if ddy240<=0+ Y# d' d% q5 Y& V( J+ X( c2 }6 W! L
5 U, t, r! z6 a5 ?: b/ y
count
& t1 T! J) k8 m, I/ p& y' j8 R; z f # S% P5 x. a; ?/ U
if r(N)>2 {3 I N: `3 o0 ~1 a
0 b9 a* w: F! s2 { pkexamine dx240 dy240
I( i6 C4 d' ] 2 w* F. D( R) F, R5 i% H2 V
local tempminp=r(tomc)
5 l; U" }; }' l; g restore
8 q2 ~( S7 Q2 B; } }
2 Y( T! ` F. r) J* o4 V9 k * v" w+ c8 \2 a2 f0 O+ D5 ^9 \
else {' o) c1 f+ y3 {3 H0 ~
4 L) f. {3 c; r, R" k* o di "cannot find minp"
( H, S! R3 O$ I; b& t
/ Y) J: z) {4 D0 O0 e0 B2 M restore 0 M8 B9 z% D4 M1 ^4 |- N& {/ j5 Z
sum dx240
- t' g, i8 Q$ }( k6 j0 ]2 p& K local tempminp=r(mean)7 k4 }2 `; _* A4 V7 F0 F8 ~
: E4 f# Z4 p5 ? }
4 [& o4 z, i+ p8 w; u8 A( F8 F }
7 G- G7 U$ G% y9 I else {/ n; t* v7 `4 K1 H5 Y* J, ?. \& b3 ]0 {
" F/ X9 w% @6 }4 c5 r: q: } keep if ddy240<=r(min)
- s' ~# u$ W& {+ q
- H- w! {) B" Q# U2 G- x! n5 q sum dx240
& {$ A0 y# k7 m 5 F% \" B% T$ Q
local tempminp=r(min)
' Y \6 W2 ?$ i. j( i restore 1 C3 O- Q: k2 ^ |6 F
}
1 h& D+ i4 D, n
8 B7 L# @) X: y4 \ V( |9 P* M1 V$ Q! H" ]$ A5 P9 L4 J# j: K
5 j q6 i& f" W2 L! J8 w+ U9 T gen minp=`tempminp' in 1
& ]5 I9 l: L- j8 A *240 minp
+ i: \/ S# t( n+ f. d/ m1 a( L) ?) I7 R7 y
: \& C8 b/ c. w8 x- s' ^ 6 t# H4 S3 y- ?+ C+ C* ]- g) c) l
preserve
1 u6 f4 H0 d& _" q; ^: q W) \9 ?7 ] 7 v6 B0 V. C* b8 q3 u7 e8 ^2 Z
sum v5 [aw =avol]
# D4 h& C1 x9 {* m . P8 `8 ~8 e8 e2 J/ Q
keep if dx240>r(mean)
. C: p: n+ Z7 M7 _7 k
`1 l2 v: Q; V6 R sum ddy240' m! T. {" T, i
7 |9 R' K$ R( G6 J M if r(max)>0 {
6 Q2 b8 i6 l7 r& G# J1 m
9 H* |3 ]9 O4 f- V# ?7 c keep if ddy240>=0/ `7 T+ X1 T5 B$ {8 }) c# ?( r
. }2 t( k4 ?. w6 Z& [9 Y: l \
count7 {$ m" x3 b1 v3 Q
3 k$ K9 |, c- e( W1 `; ^- z if r(N)>2 {
1 t% Z) |6 J( i2 H4 e! m , ?6 r: B. b; c, ]! \. P
pkexamine dx240 dy240# |9 T0 S. b5 P
& ~! c( _" a. B: j( P* ^: R
local tempmaxp=r(tomc)
, z" v. g( c5 q! j restore ! |4 r/ c$ c; q7 e
}
/ G2 ]6 T* r% g, ]: w ; t6 F1 d7 O+ F9 t! L
) L: a7 `# O$ x: Z( E6 @
else {
9 q0 r7 K: F: O1 z restore ) _% B5 E4 p4 s0 \3 h
di "cannot find maxp". H1 O& L& G& Y% U& S" E
" m# P0 L2 h5 w; J" p$ W
# o* R/ b5 ]2 _2 B sum dx240
# v, I% a/ T: a$ o local tempmaxp=r(mean)8 R; A k. d( X' @" Z. i2 D, w- K
. V. \3 m( A- h. K- m/ T/ a }5 t D# h% W9 B! P1 h
; K" K: E4 A) r5 I& L3 {3 @' G }
# {. f6 L" C+ _& \4 {; f- Z 3 j9 m |1 f( c ~, n. j
else {
8 S( n! N3 q' v, H% g ) Z! J( p" f, E( b: X1 K$ g9 }0 B
keep if ddy240>=r(max)7 j6 V' O& K# H% p; N
- Y# b6 `+ r% N5 ~4 ~9 s sum dx240( X; V% \1 Z" L' }
% E6 _3 \" J1 h4 M+ [" {8 w local tempmaxp=r(max)
/ X2 d$ k. [9 D; `0 T3 G9 P restore
+ Z, |8 Z, b$ _ }7 |& r4 ]5 w( y/ X! \
- q8 J( e( H* o5 {! I& [. B* D& E$ ]* u$ m3 M
2 B# F7 ]% K# {
5 }0 c8 u# b4 o; i9 h) m1 T- Z! s gen maxp=`tempmaxp' in 1
' I% f! }0 m6 C0 d
% s' D0 h' [, J% v: [* G5 f *240maxp
' D9 P& Y- N/ d3 @, q- R# M7 v" b* b( ~
' _0 \& e2 G6 [: i , J3 p3 t4 G1 {! W* C2 _
*-------------ddy240pminp左侧高峰值-----
% M/ p( N8 |2 I. a S: p* `, `( N2 ^( N
preserve
# `; U/ P8 {+ T8 H8 e- ~
9 g0 G' ]" n |! k" Q0 `7 X keep if dx240<`tempminp'. ]# _) b! z5 y+ |- `
6 Z5 G7 t8 f/ p& [5 | j3 T keep if ddy240>0
- f( A* ?- ] n" W; r
2 X% U2 d6 K9 A count1 u3 f1 _6 G- ]' m1 _3 J+ L
$ e/ |- l( c9 u% U# y( E
if r(N)>2 {
3 l% O2 X4 n0 l) t+ O3 o ' ], T0 | F6 M
pkexamine dx240 ddy240, R ?% r" ^; Q6 ^6 C1 A9 d
- J% i0 k( Q4 _# f$ ]: d; [ local tempminphddy240=r(tomc) . T0 C4 `4 M. a) a
restore/ _ h% J, ], m, P- z! m+ V
}
% n3 ]: w6 ]1 V- A6 p- D ! O N; h9 i7 a! F4 t9 `1 o& U, x
else {9 }) i0 L3 j# e, d3 @$ }
restore * f: c- r5 M, b* g0 _5 s
di "cannot find pminphddy240", ^+ t. Y- }5 l# H6 H! O; T% U
) w% s# \9 U3 R- y
; m8 E0 A4 `$ ^0 v) P sum dx2405 J' t, G/ H4 a: j( ~
local tempminphddy240=r(mean)
1 ?3 m$ A9 A' R; s! k& h 9 Y9 v4 m, V6 f
, e( f- H1 [) y
}
' u, x! l8 F1 J) ~/ @' k
) b; R& W( S) N( z% I
+ M$ s; n) ?0 y5 b ) @! Q4 \" [) e5 _/ P1 n4 b, e3 ~- {
( P& k/ p( b1 V! Q* R/ d$ ^5 t6 ?
) A* }% m0 u% G , i% W, z- C1 l$ ~6 M6 c6 b* i8 B
gen pminphddy240=`tempminphddy240' in 12 x" G$ r* o( b) J0 g K
1 [# |, u6 q2 @/ d7 `$ s0 z0 g( b
3 i! w! T- }3 Q- p9 X8 e- t
*-------------ddy240pminp右侧低峰值 -----------------5 J! r& }0 u7 X( H! S) Z
preserve , D& O7 G* o0 H) x: R
9 ~8 y5 U$ u5 h, ^) v X4 H
keep if dx240>`tempminp'
6 O) k8 g" x9 [% @0 P/ f 1 Q! Z, j. E! ~4 d
keep if dx240<`tempmaxp'
' M: W& g! b; I; n {2 s, S
& V' M: }( i: Q+ k* H/ m$ @: _ keep if ddy240<0/ b1 |& p2 Q- D7 Z0 y/ J& W
' i8 ^% R0 v. U! N' h6 L
gen temddy240=-ddy240* G* i. i( x9 m/ v' l
) X3 h( A5 ?9 U
count9 a; ?- c3 y1 M4 v1 c
) G( w0 }4 R) d" W; f, Z1 t2 q- U if r(N)>2 {# `1 }3 v& H- V' H
2 J3 x( {2 s- \4 `
pkexamine dx240 temddy240+ h t* Y- q( y
6 J+ }% S! p" F% `$ Q J local tempminplddy240=r(tomc)
d. n0 f" Z- q7 X% ` restore& c# g$ t$ j7 P+ N0 }2 W; ?/ O6 d
}
& I9 C! v% T7 ~ ; V6 G" ~7 ^1 g
else {" m$ e7 K3 b9 B9 l, I [9 s* `
5 T' H( H2 q3 Y/ s di "cannot find pminplddy240"' s7 c s" O9 H8 Z$ Y3 C
restore3 B: O9 b. ?5 l. q$ p2 `. w5 P5 b
2 b- e, M8 j1 q sum dx240
4 l" d1 W8 b* K" u! r, A1 \' j local tempminplddy240=r(mean)& C" y# I' G, y, p7 O
1 t: @" C, `9 U
; q8 ^* b/ i$ t: {+ `7 h' ^. v* ~; e }. F1 J$ I5 U M) }
! v8 o! E4 O& y. d1 p 5 ~8 P! J$ v. h4 _* a
4 T% V/ [" U4 ?) e0 T 6 P- I% Z" V0 E% z6 t
- y9 b; D5 Z6 q; l+ \ gen pminplddy240=`tempminplddy240' in 1
* S( u6 D+ _& J% V7 d% R' c3 q7 e; z
4 a' p) w, v" H! m: u* O9 {* \ *-------------ddy240pmaxp左侧高峰值 -------------------. n( Y/ N ] s; D' g7 J6 G8 E2 B5 {
& ^" @1 W# ?% ~2 e! t. m. R preserve
5 C: {' G, \+ I9 v4 j/ h 5 N- a7 w5 z% Z
keep if dx240>`tempminp' P' Q- J5 H* g( o$ f) X6 @' j& W9 ]
: C! s( p' X% S- g6 |0 s9 i keep if dx240<`tempmaxp'3 a# _: I+ s: b; H& u/ r4 k9 ]
1 L+ |' w9 Q) F$ A! U. P+ w
keep if ddy240>0
# Z/ q# x& }* @0 Q. d3 B9 Q+ \+ G count. D0 P: x F0 j" M+ M/ f. `5 k6 a
% ~# {0 c, t- r/ t6 X, x9 d
if r(N)>2 {
9 _7 m% R' Z# Q5 U0 y! p4 G
, ]1 ?3 V+ ^, i) B0 H pkexamine dx240 ddy240
4 |' G a- ? z. _& w ! q) s G, M, d D* f
local tempmaxphddy240=r(tomc) . k3 q m; Y( }( y: h1 V2 n
0 O: q# K6 y0 N# R& R restore. z7 i% W4 R; x" V" [* K8 X
}
0 S7 J% m, |/ A" T" L% Z" `4 z
* q- q9 P; x; g7 i else {
% u- z9 ^# u6 E; L" S: Z
$ O# g3 w, w4 v di "cannot find pmaxphddy240"
7 _8 l+ [) [6 V! z* ?5 d restore
7 u% w8 d) h. f6 S ; f, o7 G/ G" c8 [1 x
sum dx240
$ c- Q- ^2 e4 N* [6 V8 N local tempmaxphddy240=r(mean)
+ w b! V7 r5 u9 Z# G7 H" } 5 _' [$ D5 |; ?! k
# [) P$ y U% s9 n" p! p
}
- l) c, ?+ D \' w& U; N
) ]' v3 r/ Q% G4 Z% L K* f" s% f
$ ?4 D' V% S; u- D9 F% i
7 v$ c* g1 e9 m 5 \. |. D) X0 e8 z9 l8 S9 `0 a/ K
) D( q9 S2 d6 @% W* ^. a
7 y$ m4 L1 z" D5 N$ E gen pmaxphddy240=`tempmaxphddy240' in 1
2 l8 k: x8 R4 V+ N+ M 4 c6 f8 r5 _% h K4 t3 J7 u3 z
8 D7 k* @1 Z4 W0 Q3 ~ *-------------ddy240pmaxp右侧低峰值 -------------------
5 P9 z1 b2 }* V! q4 L7 c 2 z5 x1 j' _7 V0 i
preserve 3 z9 e6 Q6 V" d" D. y) c
+ f: D' P0 t" ]* D: J
keep if dx240>`tempmaxp'
, w9 a( d1 X9 Q" D : c, _5 T3 I4 `, Q
gen temddy240=-ddy240$ U( \3 X* S. ~& J5 f1 y) x4 N! \
7 d' ^" {9 w8 E( I2 W
keep if temddy240>0$ V5 j! O( I! X3 z
5 Q5 d; h5 ^- I count
5 b7 b0 g7 u y# w
2 I* j w7 f1 a3 E3 s% W if r(N)>2 {$ e1 D: C/ c; F" r9 O) `4 X
0 h3 s# x/ B! f; {9 p3 o% K/ G pkexamine dx240 temddy240
$ U j6 r8 y' R 7 _, Q2 E+ A4 x6 p2 I% w
local tempmaxplddy240=r(tomc) . z( e% I% F! G
restore0 u9 [ H1 f. M) K- z8 }3 R
}
2 z" i y) p3 |3 Z7 I# l , g0 D# K2 {( V1 u
else {
/ t* h2 @- U- M* a, L restore7 Z0 p5 L6 J- u h' E
di "cannot find pmaxlhddy240"
5 z4 Y; V2 V1 \+ P, e + Y' z, t- Q1 O
' n+ R( e2 B' J- q- c sum dx240
) j3 R1 Z6 _9 X0 l local tempmaxplddy240=r(mean) in 1
- @9 q/ T2 R1 J
5 T, ]; s- y: \) |' h- z+ F) \ ( K5 H, ^' Y8 c! T/ h% w7 J" C
}
, ?4 ?$ s) W7 f; R2 n/ H0 E6 T / x* M( L" ^( _
v0 M( {" t L$ S& p' T
7 y2 |0 G6 m# P3 d9 x; q ( P% d/ P1 T2 B# E# j! U+ V
4 q: L0 c* L5 {5 l, l" G' F $ F, `+ f% t3 P& o& y7 p% ?
gen pmaxplddy240=`tempmaxphddy240' in 1
" R# Z1 J( s) S# K : g- W, M9 i% n# i1 L. p
*-------------------------------------
/ }2 i7 m. n5 I0 ]1 k1 G
" n n) h; x; ^: m gen price5d=v5 in 1/20
4 V) U/ _0 q, j6 h* Q" U; d+ {
/ ]% b9 n# D# N0 G gen price5yy=_n in 1/20! ^* \, K) r) j
8 ^3 r, Q: t g2 Y& ] gen price5y=price5yy*(dy240max-dy240min)/20
+ _2 W. ^6 X" Y( u0 } " h5 m, z( z+ j X$ c& ~* H8 r
*price5y &price5d+ K0 L$ T5 Y: ~
. E4 I" g$ |: D: |* O# `
gen priceny=price5y in 1) c, T5 w% \* U- Q2 ~' t U+ v
) l9 O. R# b" b# Q4 |+ E gen pricen=v5 in 1
3 \) R9 M# J- X: G4 y- C. u& Q. A; m5 q: x: ?8 b
/ _, {1 U+ D- p0 G: b3 p% v$ } *priceny &pricen
9 l' J8 [* O. m' y 6 T0 i3 C" Y9 r( I3 ?8 _
$ v# G w+ X# c! I* i/ E
*-------------------------graph------------------
% b/ n* g5 | Z6 }( k
, J5 e, H) ]) V& r 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)9 H2 g/ o2 [' @: \5 T% ~
/ ?8 S9 ~4 b+ U7 ^1 d6 d' V
* ---------可选项目----------------------7 e* g2 v/ M; P2 ~+ I( u7 R# O
. ]" x) t& E4 ~: _6 h/ M$ Q' ^) t}
% C0 @1 m& e. R5 _( T J6 Eend
" A- O7 ], K$ t S; r1 ~8 j |
|