|
改了一下,这次运算应该没啥问题了
0 z5 h' X9 _1 i9 g# J M T7 W1 `& \% r& q8 G! K6 k
5 z8 J( d. g: ~" u1 I- Qcapture program drop hello
) U8 Y1 K; U' i6 `* x& B0 O, |! c* s7 r+ h
program hello
5 N- J8 y) K3 C2 H, K* k0 _ u4 _6 M3 x$ t1 v
quietly {' G; G0 a0 f g7 S9 b4 d" p/ N8 a
5 \/ i) H7 i* b
clear
$ _3 j0 I% B7 @( ?5 h4 k9 u& |' w. q# S" O
cd e:\finance\stock\20110101\source
4 F, M) M0 ~) C+ V) G# P4 }; t6 i9 |) E' T4 A, e
insheet using `1'.txt' `7 }1 u# s5 z. e6 ?
0 b7 A) L3 j- C/ h7 s+ e* F. s2 W
keep if v5>05 Y% A {3 f7 b" v
8 E- c5 G) e. l, o% J" F4 P! m" m
gen vt=_n; h1 y& J K9 f. U9 D
/ g7 U: g9 Y! B6 l J9 C1 j2 N1 b tsset vt/ h- H$ Y* l, P5 m
" Z- `3 V) s' X; k* o9 }7 b gen zf=D1.v5
8 V. ?: s) w+ ?5 O, Z: ^' d, P1 l# L1 a, I; o# c
gsort -v1; d/ S1 l/ n# p) {
) K# J n1 i) m gen avol=v7/v51 W1 H# T0 K, w* Z. ^: \
$ U. Z* u# M1 i* t
keep if avol>0% a- B3 T" [! W+ \( d% s2 H& F# L8 U7 ]
3 u$ J0 ?4 U+ Q; t2 p- ^6 U& d
drop vt9 t" K4 J/ H5 q. c: N
C: D7 w5 Z) B9 ] gen vt=_n
' u$ C1 }) D5 b5 J/ k
) N! \9 w" m# c6 F, X tsset vt
4 f7 t8 c9 f1 Y, r6 h9 t6 J ' y5 L' N# O1 Y3 S# T: ^: B
sum v5 [aw =avol]
4 Y0 p& v! u: V$ x
6 m ?( X6 {! x2 P8 z+ l gen amean=r(mean) in 17 J& k* J Z! i& |
7 h, P7 w5 `+ f m/ m( w0 v" j! E& @
* 总加权平均值 amean
% N- |8 e* d2 L4 M u8 Y 8 h! @& W3 n0 t' c9 | T
: Q) Q% h6 r, A' P
keep in 1/240
! R3 M& h7 R! [
7 I4 X5 u" X7 _# w2 I sum v5 [aw =avol]) t2 P# T/ }0 _) R
|4 g! a4 }. d& e gen mean240=r(mean) in 1
/ l9 t2 ]7 v+ z( P6 D9 D4 Z, G, m 7 _! u/ r6 t! `$ u
*240加权平均值 mean240
7 w p$ D. O3 i1 m G2 k
# M! O/ ]* x3 H$ J9 x% b- S set obs 500
* R! U9 J$ a9 Q/ `& q / ^8 Z6 q4 H0 X3 \
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
& d0 v. a) q/ T# [0 _; s 9 ^1 T% J4 [ R. Z
*240 kdensity(dx240 dy240); v! V9 b) z' \& F4 c+ L
L' r: k% K* m8 D
sum dy2401 z" Y$ B+ @& d+ e
7 O" t) H9 l6 L6 g+ e
gen yxis=r(max) in 1
9 u2 E+ ]. o6 K8 x2 B
7 a2 P9 m) K* t1 \% G" W% w3 k! C gen yxis2=yxis/23 R |. ]. g6 E
: u- k! v6 F0 P
*yxis
$ \: v# P& N; i" z. W% {
. V3 ~, U( e. T0 k gen dy240max=r(max)
' I+ _- O2 l$ J% x$ l, p4 `( { # ^5 A& L8 D/ k- y- F* T2 w/ M
gen dy240minp=r(min)# O! m x; q+ {& n9 T) u- S9 d5 q
4 ]* a) U" n0 ^
gen vtt=_n5 S- p- N* [" I2 n7 F1 {
6 {' m" \0 j3 i tsset vtt# H2 A5 H2 ~- y0 _! A
6 ~8 Z2 D. L; L4 A& P( L
gen ddy240=D1.dy240/D1.dx240
" X$ {. u q2 R5 Z; f6 b& K: g 1 T$ X u( K- F/ a" Z2 s9 _
sum ddy2406 z& s8 ?- J/ T
2 d- N: ?& j4 J" f4 F7 |9 A3 k. k
gen ddy240max=r(max)
( q( {. m- S% H8 w' Q* `2 B/ W , ?9 B- o( e9 b8 Z8 W/ f$ A
gen ddy240min=r(min)
) ^) g6 i) B& x# l 7 v* z7 q2 R% q' \/ c% m, q5 [- l& ]
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
' t% j3 c' m$ A" w% k
5 ~1 B$ J, v6 K) A4 E; T$ u' i sum ddy240g# t; l, j+ R9 R! N+ c4 a
& E+ q5 Y3 r% C! \ gen yxis3=r(min) in 1
0 k: {* ?9 v! s+ O, _7 ~4 ~
" r1 i6 M" r' z0 [- A$ I gen yxis4=0 in 15 ?1 Z9 B* Y/ S
0 f# J6 Q# U9 M" W6 e$ i
*ddy240g
( D9 |! T: X' Z; H8 g( \
P" ?' `9 F) D. Y . S% f k; u n+ x% f, s+ I
preserve : b8 H: R, q* L4 b: g0 E5 L
6 G9 [9 R. O$ E; K( |, F7 s) Y0 ]
sum v5 [aw =avol]2 e9 C0 |1 l) C% j) {4 c1 J5 J
% {# ~! ]$ a/ v& z0 u; M
keep if dx240<r(mean)6 C: L: R* Y' ]2 h
& P) J) S* O5 R
sum ddy240
6 s5 a: Q7 B% E2 w w, ~ K; }8 S 8 R) j$ n% c+ l+ w" T o; A
if r(min)<0 {( X7 j Z: f/ P
- j9 S+ j0 t+ l keep if ddy240<=0
: c" Y! J3 n6 G8 C
+ L$ V" s. |- i0 d( _ count
$ z5 u- @+ A y& d9 f
- n& z1 d; W1 r. X6 \) y: K3 ?7 Z2 h if r(N)>2 {
/ \9 i* Y$ z1 ~8 A
$ B( C0 S7 T% o8 u( K pkexamine dx240 dy2407 z4 D9 S! `& m( g
( C2 `: G" a3 K5 ?% Y4 }
local tempminp=r(tomc)# b8 x$ h2 |! a# x9 a2 c" u( w% ~
restore 1 H2 t, F5 a: H
}
* P) {9 ?6 e3 ]3 w% v 0 m) ]5 V0 c9 t2 H2 t* J/ D7 L: `- d
else {
. b# C1 M) G9 @% X 5 {& S: V+ `/ |0 S n' _& ~
di "cannot find minp"3 K l3 g# a; V( w) Z" I
% T( d& }# e2 U6 C% B# G- Q
restore / t/ L) y# u7 N- V$ y1 g
sum dx2406 j7 k7 t4 O% O" d& E$ D
local tempminp=r(mean)
4 F% G, S8 v. P% Y: u+ x$ G. q & N$ r) R/ b: J/ [/ \+ t- e8 u
}
3 ?7 K Z: b/ g }
2 Z' Y2 q1 M6 [ else {
9 y" J( X0 x, {9 E& l x9 w# ^* x7 V8 ]
keep if ddy240<=r(min)3 E! K% ]' f" |! k4 O2 l( O
3 m% s; e) y1 b& k% b9 t" n
sum dx240( E8 F7 s% r; }- d, y. m& r
/ W% z7 ~ v3 t0 E& u local tempminp=r(min)! t. o- Y1 {' I
restore ) C; |3 i* \% W% l ~# ^$ Z
}$ { J$ E5 x g+ k4 A% x7 N
0 Q0 |$ d# \- T7 @1 c# x( d( P: D- |8 |' v9 l1 ?/ ^
9 M! s" v9 J- Y, R Y
gen minp=`tempminp' in 1
6 ]& z; n5 D% Q+ Z7 U! D *240 minp% B$ a) M2 s" Z! t; a9 _, Y
O% J/ i# ?0 x- S- _
: r$ @9 X( E2 z, ^9 w
- J* `) b7 t3 O+ o6 C preserve
; c2 \. d; _5 A% [2 C) M, H8 v' K ! J7 d0 U) L0 J9 |: m% l
sum v5 [aw =avol]' }1 x* M3 c& c
) S+ _4 P( N) |' s, h( A0 e3 A& L& ]' Q$ b keep if dx240>r(mean)
3 Y+ r- \) F f; u+ A1 n
( s$ P2 c6 e' O. W sum ddy2407 W% }5 `! c6 O/ G3 [7 K
1 L: C' w3 p& B( k
if r(max)>0 {: f E: O" n& X! R% o3 C
+ b% S K. u- |0 k5 n. H& |- }7 h! C
keep if ddy240>=0
# ^. o" R- ~3 j0 e& v2 L0 h6 U2 b 1 W% B1 `, k: s% T& }* p
count
5 t' V; W0 |. r ! x2 A! r- b% s
if r(N)>2 {$ w* s2 _) D8 c6 q! ?' x1 t! D
: k& |0 f( @/ z! G/ G pkexamine dx240 dy240
. |6 K/ U# M8 a# R& M+ q4 g 5 i6 r( z$ c! X3 S, X; B
local tempmaxp=r(tomc)
3 Q q2 J! O' a: @ restore
' H" @: I# i# m' u" H C3 ^ }+ ]$ z# G8 M/ t! C4 E
) ^+ g2 M2 ?! J
) j; `* b1 G3 i( i6 A4 T- z. j) ?. H1 | else {
# U& ~& a$ j; r( Y! I: i restore
$ Z( n& v6 v8 r& k7 q di "cannot find maxp"
( q3 F" d4 p. d( z8 `7 B2 P/ l" M) r . a; D! B$ Q) A( V1 m1 h7 I; r: R
, i2 S( r! f3 m7 z
sum dx2400 L4 N) Q7 r% [+ o* w2 L
local tempmaxp=r(mean)4 K- }! ]: b6 M Y3 A
. W- a: {8 S: p }
) N, o0 }+ z7 t' g0 |) f/ t4 Y " U7 \+ J3 a0 r- I
}
8 @: L4 G+ n) P5 X ; a P9 \& o, v' ?* W1 E* {
else {* }) f$ `# F, B0 y
# [, A7 [! y" b keep if ddy240>=r(max)
) A5 B: O8 u8 f9 V V ! w3 Z T) f! V0 N) h& r
sum dx2408 G8 d8 [( h# K
* W7 _) d* Z1 H+ _0 G+ M8 b+ \( i e
local tempmaxp=r(max)
. M1 O" T# e# r1 O, F+ Z restore
# |, D! t7 U' M9 [, ] }: R) W' f- n7 t4 \, d8 C
; C( A6 i, x+ Z: l) k+ N( U
) L- x0 I( A" U! w! L. h% T: y
- R0 q) J1 s; l) l" L4 m
8 j* W" J- e+ V) M( C gen maxp=`tempmaxp' in 1
# y, G0 n2 y1 x- k$ \1 X/ |
6 T& {- {( @2 J, K) P/ B* M% } *240maxp
! k/ S5 S' b) \4 W) s
: c& S' r+ Y- o " h/ Q* V! v4 L3 A3 v( o$ w. ~
*-------------ddy240pminp左侧高峰值-----
$ G7 g. [' c; N; N7 v* m/ u . ?1 [- I" f8 X0 A" C
preserve * a1 U- f+ P0 V. j7 \
6 R6 {+ [1 T: y$ o( O: q3 G! } keep if dx240<`tempminp'' X7 k7 [5 A+ G4 p) g% o5 Q6 i
1 r2 x* b5 R4 u5 j keep if ddy240>0
+ j4 y7 q& m/ b9 {2 {1 w 9 q5 E3 U V6 Z# ~8 F! h- v
count
) K& G% ]; N" k: b% U' K' m% n8 v % ^: L- m& i2 g
if r(N)>2 {& d$ G1 i7 p( j) b. Q2 r! Q
( d2 N$ [" s5 D3 B i! Y8 O3 w pkexamine dx240 ddy240
( |) K) j) H1 M4 a# m8 g+ ^
2 l8 j7 C, i+ q( l) A/ n local tempminphddy240=r(tomc) ! J4 m" }5 h+ T/ h
restore
3 e( i) R- Y) u9 }& D, E1 H }, R( a; G0 k) ?1 T
0 U0 m4 Z, x0 ]
else {
/ D' k' j2 a& ^0 A% ^% A/ X9 d3 T restore : y- e9 F2 b3 p. E7 s" v/ d G
di "cannot find pminphddy240"! Y7 t0 L( n7 p
+ j" z/ ]- R: c5 r) j! c
0 w' f$ g# t e) b8 f
sum dx240
# Q% y J* j) j h local tempminphddy240=r(mean)
/ E, O/ m- ]/ x( n; A I- r5 j0 v # B/ U1 C* J9 T9 U3 [- M
* h: U* u/ c! ~* |3 g3 N- t0 M4 I
}- K5 R, |4 m, B; u! F
: g. P) l, M7 v6 J 7 C; n# q2 I$ U( G6 v
0 T) C! s" {7 V$ b9 y! z( Y* a * w$ W' u" W' ^9 Z" B0 r4 ~
) p& s* c! a5 K
& w6 @( F! x6 x0 \/ Z, M2 d" g
gen pminphddy240=`tempminphddy240' in 1
: l+ e {9 R9 W L' Q0 @! ]! ]
) U$ h, y9 w& k6 |: _) V# N+ e 4 V( {7 W4 U& j4 d, P- o K
*-------------ddy240pminp右侧低峰值 -----------------/ e0 K" h5 {& a- o4 L
preserve
0 R0 R+ ~8 T4 v+ n# C! x2 ~3 K
( F) J6 ^2 q% h+ D keep if dx240>`tempminp'
- p+ ?! H2 m# b! e0 h6 k) k
4 E/ Y- b+ D1 P0 b keep if dx240<`tempmaxp'
1 f. B6 m2 G& F* g
. L% A; J5 \) [2 r keep if ddy240<0
6 J$ [. T9 g' O1 j: N6 G8 X% z
+ Q/ T0 C$ c1 `/ l+ i/ j0 h gen temddy240=-ddy240
8 y" Z4 M1 d( X% f; a ~ 1 `3 |5 E( l% X" a p4 z+ ]
count
, c' m/ e% v# G% p) l. K2 S $ ]- T# B4 d* q$ T- F
if r(N)>2 {
+ y U* n/ Q/ Q# G8 E- g
. G/ `; F8 S8 v" b3 p pkexamine dx240 temddy240% i7 {) ]7 J( B* O0 R; f K+ r
( M" n5 N# F" B- `& Z0 Q/ J+ b: z- L local tempminplddy240=r(tomc)% b- e6 d+ W) U' E0 d* Y
restore
0 k9 f# F+ J) a9 @: V7 j }
: \' _% \6 H5 m. m. V4 `: H
- F# Q1 @0 ^" w% R/ c% }" b else {
% @! t8 }. I" D! K; [4 X ! |9 x- ^, Z/ _1 D
di "cannot find pminplddy240", ]0 W2 [9 i( |2 J% p3 e' j; n
restore
6 l/ @5 M2 t& F" B- z9 t8 o" t: S # m/ E8 H! s& o8 M0 v
sum dx240
4 n1 m3 l* }9 E8 I local tempminplddy240=r(mean)
/ l$ l8 A d/ w" {+ n$ b
5 T5 n# V. t( D, _, j0 c
|6 b0 M2 q, C+ K" o! o$ r }
1 J) A0 N; @# E3 n8 q 4 t/ u' ^2 r7 [' J& n% G
6 Y0 @4 ]" |& b 1 d' J0 T! P; [& i C& G
/ K. a' Z) J8 ]- p6 N) o
7 S. J4 u" u$ H+ q7 w* U
gen pminplddy240=`tempminplddy240' in 1% ~. b" g h+ B0 w+ o: Y
3 c" j9 T6 D1 i/ O6 B, e *-------------ddy240pmaxp左侧高峰值 -------------------
$ R5 `# |/ l& A" I , ^7 y9 b, U3 n2 J- l
preserve
& K# h( {1 |3 m ' O& R' q2 Z l
keep if dx240>`tempminp'/ l, h, `) o. g6 P) P, {
& Q" h2 b* e/ Q keep if dx240<`tempmaxp'" ?% g4 c5 X1 l, n7 y! G
+ g5 ?2 T- U$ P, d6 {
keep if ddy240>0" `) o# \1 G6 C8 A7 B; I( d
count
: S }( I) @) e5 ?1 y ^' d, L
, N, T4 p4 l8 p' z8 J( h' H if r(N)>2 {" P8 j- n. t& @% k) M% X
" Y& `, t5 U- K- @% ^
pkexamine dx240 ddy240( j- \, h' |, ?: e* B7 a% w- g
3 W. s+ |$ ]' w4 N: \3 W/ p
local tempmaxphddy240=r(tomc) ( O. c; ^$ k3 i0 w0 Z" D5 W
8 X6 Z: z- }0 Z7 c restore
& L# r% \% `; { }: E/ y1 _3 T5 ?) t4 h6 z$ t1 P
* e, A* [6 |5 V1 q
else {
* `' R8 O0 G9 q. w) G( G
' R* V0 Z1 z3 g }% x% u6 C di "cannot find pmaxphddy240"7 m& ~( l+ q1 O% y" A5 ^
restore
, ], h; D0 O# `4 e& \4 C8 [
* u N* W8 J L& Z8 f sum dx2408 J3 t; [1 ], d8 T* i- p
local tempmaxphddy240=r(mean)
) A3 V* `9 j Z/ ? b% w5 O4 x9 g% O 9 g) ]: D2 q) T3 `
# [7 }7 u) c. f/ a! x }! q6 b& Q+ s' e
6 D9 X+ C j4 @% w R1 v
' R8 t/ p/ r1 M2 \9 I( w! j8 B 1 E$ r9 F+ ?+ A! `
* A1 ^: N: b* U7 E8 S) c' w# e; d/ f8 ~ : A P' y2 S7 A* d, n
" {1 g* k4 G8 j7 b: t! e' D gen pmaxphddy240=`tempmaxphddy240' in 1
8 e) X$ w/ g( |! a n: r0 r8 ] 2 K. V3 y* P/ r: g
' j' p, n$ k+ _0 _5 d; `0 J( K *-------------ddy240pmaxp右侧低峰值 -------------------
8 P: Y, l; e2 \; p0 `( @, d
; s5 Y1 Z! a( x6 S$ w7 \* ^( g- I preserve
/ @. y, {) y- M2 j3 n 3 F* h# u2 w* c9 q3 `
keep if dx240>`tempmaxp'
7 H, i% B1 j) L6 z3 I6 m
( t+ }( a3 q6 p% K: _ gen temddy240=-ddy240
9 ?3 ^8 p2 I* W% s$ Z4 u* L' ^ : O& j! m$ K0 \' ]! c
keep if temddy240>0
. a. z, g# e* r : c7 v) j' q! E/ G/ K( U3 q
count, P/ Z* g2 v) ?) K+ n
3 _) ?' [5 c7 ~( r$ W2 W if r(N)>2 {
. t& I ^+ m. P4 a2 Y
* t$ F0 @; x4 H5 \ pkexamine dx240 temddy240
* E) Q6 }5 d/ O, I u 3 B. Z1 [7 _& o% i
local tempmaxplddy240=r(tomc) 2 v" r* j b# m
restore) `" U: r/ z1 o! @: V
}8 u1 [+ X+ K7 r. x y
3 ?2 J) e7 k& ~
else {. Z' G- k; }% Q" [7 v' N; ?
restore4 z, K/ q# b2 W Y
di "cannot find pmaxlhddy240"
3 S; u3 c6 k4 L
, i2 v9 S% d: O8 L2 Q3 C: J: b' O5 f
5 T5 a# _. F# F7 G. D. c8 t sum dx2400 b9 `- ~7 s; n# u) {9 D; |/ }
local tempmaxplddy240=r(mean) in 1 J# a3 K. k* R/ N
0 f0 j9 h S. I6 k( n, c- W 4 d2 {" H9 J4 {8 L. ]
}
5 L* n6 A H' p% L
, s/ F1 \$ u$ B8 h ! g) n& M# ]9 v0 g$ z, h! y
2 C" W' I' H( d, I* Z
5 V+ i) z7 \7 y
: w! ]. {' `& i4 K , H! J7 o9 G. F+ H7 X3 x6 K
gen pmaxplddy240=`tempmaxphddy240' in 1
7 D2 n8 C# t3 M! N' n( a2 w ~
3 k4 A# Q( m$ z- u! L" k *-------------------------------------
/ X6 V2 E2 `& W" R r " f" @; f# ~: N
gen price5d=v5 in 1/20" Q9 U9 ]* F) \8 `% F0 w
' s. m" t2 ?& v7 V ^
gen price5yy=_n in 1/201 X% e) T+ @! {2 I2 m
) D1 I4 X% z2 W9 W3 t2 P
gen price5y=price5yy*(dy240max-dy240min)/205 x; q. c, U" Y
8 O1 o' E& x6 [- C *price5y &price5d# \6 ^4 ~& }3 s! `
2 S, O y" y7 N7 _; k
gen priceny=price5y in 1
, n9 o+ `+ z- J 3 V6 @" g/ W# _; u# r7 f) t; S3 E
gen pricen=v5 in 15 d. ~# [$ J( z5 O' [; i
4 q" r' W6 ~+ l5 `
# A5 M6 @7 s; }7 _& b *priceny &pricen
9 V; v5 {8 {& ^4 G) M2 J4 b# n6 ^ # Z3 D4 c% L: t$ {1 K! ?* c; m
2 d! e9 i p4 C6 { *-------------------------graph------------------4 B3 Z7 J" m' A8 P& D0 U( U1 u$ Y
4 V& i9 T' d2 ~, C+ c7 [. Y; d 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)
5 ~' ~! P& N% W: k0 W" d( e$ W
7 l% Z# `+ G, @5 @7 _* ---------可选项目----------------------
- k5 X( u8 g6 f9 w4 T5 z' O# l# \4 Y' ]- @$ B5 P1 ?
}4 Y2 o0 J* t2 Z* k
end/ U- |: E h# h( c! P# U% h1 k
|
|