|
改了一下,这次运算应该没啥问题了
/ |6 f- I' G. t% B$ @3 v; g$ Z4 _# ?7 M! X- h: {
2 s* v, H/ s9 o6 N$ L2 G1 m
capture program drop hello9 v! c/ d& s' z# [8 S8 ?; o
: G1 @1 n/ A8 `' r' r5 t% O
program hello! w! I( t( b7 N4 S: `( R) o3 |
$ E* O* z1 T& h3 J9 o2 y
quietly {! r% j; C+ ~2 M0 Q( p" D
. S5 _/ R3 h5 Z! B& y. G) T5 o
clear
0 T- X+ u3 P0 c: D w
( H$ g1 e0 Y; Z1 |2 l6 w1 p# @( Kcd e:\finance\stock\20110101\source P# J3 Z# f) G" I8 Z
6 ?; v$ `4 r) ]1 L- H$ c
insheet using `1'.txt6 N( `' y/ J6 X
. H( K3 D* l }) S+ d keep if v5>03 `; f3 G: _, u L( m7 J
8 y/ `- ]0 ~! J, E4 q/ i
gen vt=_n6 u6 x1 B& [1 f1 {& h( |
) l8 x2 _) x& S; l tsset vt3 b' B+ i& K0 s" n, e7 r% t
3 v5 q: R. S; w0 G, Z
gen zf=D1.v5
6 y: a4 C9 t: y+ r7 R/ s) ]( k; M! a9 P
gsort -v17 w) c7 o# U2 ]9 P3 r+ ?
% f& y7 ?, I2 g, P5 d6 Y! y gen avol=v7/v5# b, M$ p" O8 z/ S8 S3 y' h
! `: Y. n- K; u# y$ ~1 n/ m keep if avol>0# a7 x0 L0 f+ i' Q6 ?! i
- ?9 N3 o% d% v0 t* `( v drop vt
: x. r! C3 R1 q8 L $ I. ?* Z5 l; R" H7 l
gen vt=_n7 t3 N$ j! m! M3 [
- R, s* y4 M" j. n
tsset vt
3 m4 C ^# f$ w0 J" ~& f6 q( Z 7 ^: M; r! I* Y9 F
sum v5 [aw =avol]
0 q. h2 P+ E9 v) X- `! `) R) `6 z! y
gen amean=r(mean) in 1# v8 H5 N3 ^1 o. K% O8 t: s: S
1 B+ {# G5 |+ }/ m * 总加权平均值 amean
0 K8 n, ^* Z8 m; N, l$ L
. i- f5 \9 a8 |& T* Q3 U- h z 8 }5 R( e7 d& K+ X" F
keep in 1/240' a) r. e; ?/ K; h- q- z
+ g& U" N9 o8 s: l$ A" k. I
sum v5 [aw =avol]
1 i( h* j$ f6 T1 q d* K: p; g
+ y+ `0 l: [2 S& x& }( x0 g gen mean240=r(mean) in 1
: V5 `7 m" i+ G% O
, ~7 p; L0 C& r) H9 L$ J0 U8 _0 X *240加权平均值 mean2405 c" s( E. @" i7 f. E) W1 f
3 L' ~" l& S+ o% X
set obs 500 : ^, b8 O, d# s9 y! z7 ` l1 V
2 Q! q2 E2 o7 g1 L/ ]$ T kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
( ~9 |, u$ m y& \1 g4 v4 y
) C6 a: A5 A6 n1 S- I' W; j *240 kdensity(dx240 dy240)5 d6 ^) o/ U& I8 w* {& w
7 s4 c$ [5 l. i& }
sum dy240+ A' S- q. S, q$ C
2 n2 G b( ?% }+ ]" r. m gen yxis=r(max) in 16 S. x0 d6 T/ b0 J
# t h) S* s" p( P gen yxis2=yxis/2
( ~0 R; T4 w2 V6 T! I 7 V3 q5 L. [, @* H; |1 V% {
*yxis
; s! C" A: Q: F3 `: Q
" G4 P6 i) `7 j' B" j# K1 `; U" l gen dy240max=r(max); I/ Z- v5 G* a
, E3 g8 Z. v# {* b* e W gen dy240minp=r(min)
& T: b% T" S4 s' {2 \1 u - }1 R" X; q9 ?: A* ~7 |
gen vtt=_n0 F* {8 a7 |5 b* a. t# P4 n* w* R
: S3 C& t& C# q0 x: m0 M
tsset vtt" K& @4 x) F/ |: \
* a, r. p5 J H3 I; c gen ddy240=D1.dy240/D1.dx240( k7 D S4 F/ T( [9 I
+ f7 X( h+ }$ d7 `9 X* q2 f& g sum ddy240
1 F$ J4 r- g) ~+ N/ Y% { 2 s$ A7 j- W J3 t. ~" z- ~- e2 ~
gen ddy240max=r(max)& F: Q l* V7 N
* T$ r; Y) s/ a$ B1 ]( ^
gen ddy240min=r(min)
; {9 b9 N- {5 B$ ]. f! s. e) G7 ^ ) t/ d/ y' H+ Q
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
0 \" ?! J6 T7 s8 g# Z2 L. a
4 M3 k4 t6 m2 |8 @& r" O sum ddy240g
, w$ F' ~- T6 h5 U- _: @
& @$ e2 g. V) E, s gen yxis3=r(min) in 1
6 @. V2 C6 v" p7 i 1 d1 I2 y q# z7 d
gen yxis4=0 in 1# }% l- ]7 ?' h! q+ e
3 o, t! }4 G# `) l' H5 K$ ~/ Y
*ddy240g
# I1 L: V, G0 I8 c0 B2 P , E+ D+ J- Y6 \/ T6 h4 o
# K3 P; p2 R M, f
preserve , i. A5 I! f/ D. ~7 o b) Q+ [
4 O4 {/ g& F/ q2 I) A
sum v5 [aw =avol]8 J1 s+ K4 W6 o# k9 x# \
# s! ~$ C! |2 R4 a/ p4 I6 ]- E- J
keep if dx240<r(mean)+ j& x. q1 K: N2 ^; C
% k: X. u: f$ R8 a. j. C sum ddy240
+ _! ^0 S3 ]! r5 ]/ }. F- x$ J
T; [3 A& p9 Y; y* Z if r(min)<0 {* @" E* C7 p7 [. E3 i
& M+ J5 @7 J8 G/ X: }$ F& U
keep if ddy240<=0
# T, f, ~4 x5 ^5 Y j, {2 g m; B) a* r' l8 c0 x
count
; k1 Y/ w7 k! f5 E" f) e8 V / G) L9 q4 Z! K$ p( f" N
if r(N)>2 {
9 [& F! l& h4 a/ a6 c 4 ~/ h3 w. V7 g. |! v5 x
pkexamine dx240 dy240" @+ V% B) v1 n( ]4 o0 O' V
+ H, ?7 p4 M) { local tempminp=r(tomc)
- n3 r: J, @8 V5 [( N restore
: E* }' P" ]2 Z" N3 I4 l! V" j }
$ G! l$ o, c+ |2 V9 w$ j
' B- L4 ]: B7 M" E else {5 d2 U0 F! F' [7 Q/ |
# Z: O1 B) |2 G: M8 D6 Z
di "cannot find minp"6 P: G7 j2 u) R6 ?3 Z0 p
( `+ P& n) ]! y6 v restore
+ {% j, s4 _# C# ` sum dx240
4 z4 \4 ^ e1 ~: @, D local tempminp=r(mean)
6 n7 s* f: e! z Z: Q+ t! K' C
; @3 F0 D" F+ l) q }- x/ F& S/ N1 |9 p, ?
}" a } x2 B8 A7 \) A
else {
o; y# X) j# }" f2 S% d ' M, b! G8 C$ R4 o+ F
keep if ddy240<=r(min) f* g% L. w& h$ | E
. V9 b! R6 U' w8 H0 ?1 n sum dx240* {, O0 q2 p* I! r* G: _
7 S( {' e- a+ h3 l9 }% z% ~ local tempminp=r(min)
8 k# c6 P0 T. B7 `! E9 @ restore . ~$ E* v: }- M# i# }
}5 z M! y& Y, F0 s
0 s4 e' s& J# {/ Y. G. X
" @ X0 s A0 P6 h! l2 L8 b) O6 c! E8 q0 {
gen minp=`tempminp' in 1+ x6 q# w9 r, b5 a2 B# i
*240 minp1 U7 @7 e. `5 w9 M$ r
) g) n. d( r' b k9 C) B9 y# V
5 l: B3 C' @+ }0 Q6 R8 u/ g, \
2 Q' ~5 n% E* X6 {- i6 A preserve
% W5 B0 f/ a' E: i3 v( s1 Z' Y
) ]0 x0 N$ i4 F' }1 V w9 | sum v5 [aw =avol]
- O* b' X& ?8 k! g
" r* l! K- I# \+ E" { keep if dx240>r(mean)1 b. {, _# i) n" \3 L( t
; T/ i5 q0 ?3 w: t8 ? sum ddy240
4 D: Z# C- n6 l) S L0 m- G# |3 m8 I1 q" j 4 r3 T) b, @& Q
if r(max)>0 {
3 H0 o- p/ L) z- e) t' U - F# V' u7 i/ Y8 t* g; y( j
keep if ddy240>=0
' ?/ B0 C f) h * F- G3 ] F' K5 l, m
count
5 `+ {' V4 B9 Q! ~4 N4 M3 ]3 J
. Z3 s- v& j% w V* u if r(N)>2 {
# `3 F1 |0 K# D5 T+ O8 g 4 u: J2 Z* I3 f+ E" V* B& p
pkexamine dx240 dy240$ y7 S0 y( N8 P5 ^9 R, O7 ], x
1 E& t5 x5 [# T7 n
local tempmaxp=r(tomc) $ E% `/ J6 @8 z$ z, N0 U
restore 3 [) I1 \4 l5 I& E) L
}
9 ?3 M, H+ v( P " X% b0 ^5 S! J0 a' u
5 S+ r1 r3 g' O+ |, {
else {
% j5 X9 v2 m% |' K; M restore $ F3 b8 z* {/ i: @) f. N4 o a
di "cannot find maxp"0 |! Q/ U+ `, G# G b
/ U! A- Y8 g0 B& }
1 l7 R3 F/ ?5 U! e; C( P
sum dx2407 b/ S; M0 a5 w
local tempmaxp=r(mean)
: j$ Z q) M0 i+ A$ p" [ P& T( Y7 Q* x: R9 C. J
}0 { z: k) k$ l) k
: l0 ]1 U' \ _ }# Q8 Y' W- h7 ^5 c6 p8 S% O4 P( o5 k
f c6 R8 x/ N, A4 K& ~! ^* V( T% J' `, W else {
7 ]8 t/ `2 ]" j' R! y; O, D/ o
8 }: ]& W5 i; }# a keep if ddy240>=r(max)
! O7 I5 \1 R6 `: H' T! L- u! j3 s $ h8 V4 m8 L5 l$ ~: R# ^7 a" w
sum dx240
( s, q* V" H6 ~* K
c1 s3 O' p& j- R local tempmaxp=r(max)
* r8 D$ q: {: e3 v4 K restore / {+ d+ y! j# z+ W
}
) \, {$ h) f* p- {% | 4 ]8 v1 S. [5 O4 e) V6 {# A4 f
5 P% g. W2 J; O. e1 O7 W 3 \5 C z% Q+ g
0 m: F: ~* c8 B0 I, q
gen maxp=`tempmaxp' in 1$ t6 M8 ^) ~5 O4 I/ w
/ _. o0 z9 q2 B0 {) P; T
*240maxp! M( Q6 W" J5 B/ C' w% A* H
9 {# _7 T& T' J4 p2 v' Y% x 4 ? Y3 {# [+ W, t& j
*-------------ddy240pminp左侧高峰值-----* t6 n) t- [9 c% e: _2 s
5 S/ m) [ Z/ \* O9 y preserve K& t- m( c9 E. w+ o( f. t
3 s0 W8 \$ Y5 d* y5 ] keep if dx240<`tempminp'
\9 Z0 V% T5 q5 v& t9 y 0 X0 Y. C, M& L4 d- S9 z
keep if ddy240>0- O7 y" L& c3 o" _; n( U3 u
c& k9 c& F: W0 Z3 X, ^7 ~
count
1 Y: \: F7 ~; r' e
7 E& `. G9 g# V: ^1 ^* h if r(N)>2 {% L) W, u0 y8 B0 [/ Q3 Y7 L) {/ t
9 {5 t% Q8 A% o3 N* i
pkexamine dx240 ddy240
t J2 M9 V+ M k# ^) C+ q9 Z 6 c0 V5 u7 c( G2 U' P1 O
local tempminphddy240=r(tomc)
1 n; B0 n6 d- M5 |$ K) x) ^ restore
: t8 Z" y: k" {* w8 q }
. }: I+ \6 u. D
# A$ j6 H# Z6 I9 X0 \ else {
; M3 [! [& a+ O1 Z+ x- _1 ~. @ restore " |+ k! a' \3 K6 w+ R& q; Q! g
di "cannot find pminphddy240"6 _% ~5 ~. g# s. ]$ W
' x% A1 L2 j; O3 a
* F$ Q! W' v! V; X) x: G sum dx2409 `6 Z0 m! [' w7 O
local tempminphddy240=r(mean) 2 H% u- C+ ?# e, t1 T) C* H
) Y, {2 b9 q. c
/ }" C7 p. t% f4 t" P7 [0 F& _ }9 H. V4 ^+ L) s4 G2 X0 E! S
! \0 ?% b2 B& X/ ]4 v: h: q2 r* }
$ o- c6 c1 O4 u6 W$ f' t
- D$ M/ A4 Z/ i, f. n9 e 7 X- I( @) o. n% q+ P9 i" ?
4 ? V0 S/ s7 k a , r: S1 v! f: w8 Y* B Y& n% r8 ^
gen pminphddy240=`tempminphddy240' in 1) m8 ]9 _ o J2 O% ]
1 s. y8 D$ I) X6 G; n
& _8 {- |9 m7 N. G3 e+ `
*-------------ddy240pminp右侧低峰值 -----------------
- G3 s* O& ^% N7 K preserve ' x: N- `8 E5 d4 U- v# L* S
1 {0 X3 M& l7 e& { keep if dx240>`tempminp'% V( d! O" m3 w$ v
' Q9 C* i# o) e keep if dx240<`tempmaxp'
) N5 H. F4 l2 e% y ! q1 J$ R8 D! `7 r }
keep if ddy240<0
& a; `* d4 ] h
, m- N( e' s' a# X6 {) T1 q3 i- v gen temddy240=-ddy240
5 R& D3 J! F8 y6 F4 [! i) Q 8 q' y Z& Z* B) a
count
; A- J& m4 t5 w: _: R$ q u , O* N. `4 ^1 ?( ]
if r(N)>2 {
$ D0 y& U! }- G 9 J; W; V* X( b1 S7 Z' @8 d
pkexamine dx240 temddy240
]$ H* U# V) Q0 C) H1 T * c9 m r1 l% ~- O. w
local tempminplddy240=r(tomc)
$ ?$ o. k' I! @( z restore, }2 k# ^. u3 S( ^: O% K2 u
}
& D. k. v- \" P6 ^0 [1 ]; M / H$ z7 @) ?7 O. \$ t- [# D v
else {$ A) D, b1 l. T ~' }0 F$ g/ S
8 r! h# w+ X& J8 {& k di "cannot find pminplddy240"9 `) B' U5 X, j% f) _
restore. ` @: @8 {' |5 s" ?
) C) e$ _: R. D8 j6 r6 g0 R' w4 e
sum dx240: W6 I; v* d5 | S" Y
local tempminplddy240=r(mean)
* k' t1 N- K' p; G. ?! q; `- I 5 J z4 { z, K. [+ @& e
; J9 S( l' E* H3 G1 g }9 V+ s/ O3 U" h
3 Z7 ?5 h: g- |& h2 x+ G
" ]5 a- E' L5 Z! A8 L " S. S3 {6 f/ G+ E! l0 S0 v% \
& w6 R# y+ D1 k( x
- J4 X4 _/ E( l; t
gen pminplddy240=`tempminplddy240' in 1! d' Q1 u0 w; e3 s2 b( k% R
; v; x. a" G" a% S' V( d *-------------ddy240pmaxp左侧高峰值 -------------------
( L% h$ E( x/ q# K7 U
+ ^/ w# G5 b9 Q9 h$ G' b preserve
1 I$ k6 K- b& @8 e! _7 ^ 6 J T& x7 A: A5 B+ T) o
keep if dx240>`tempminp'
) c: b: S2 W: J* @ * C" \3 N$ o4 |
keep if dx240<`tempmaxp', D9 b6 E+ ^& N
9 f3 T0 U/ j, o5 ?
keep if ddy240>0, m4 H, x: Q3 T
count
. [) T6 B! E. ?: x' B & j- j% w X9 r1 P* ?; F6 b
if r(N)>2 {- ~* h! K$ w. U G
9 b& v$ \' Z! u
pkexamine dx240 ddy240
4 I& y V: g! z% g! j
4 e. v. N2 P# O( \! d local tempmaxphddy240=r(tomc) 6 i; t' N' _, ?& t0 j
0 O# Y, ]' [, U restore
6 C% L! E" ?, B* J8 D' ? }8 c2 c+ V4 \1 C# i+ |( S
1 G/ `9 ~! n9 q% |# F, Z* K
else {7 t! @; c. s! c- b" W* D" U! U% o8 E
& H8 c) G& Z+ U1 Z1 Z# E% X
di "cannot find pmaxphddy240"; A% s! X% L% O8 M% M$ s$ ?3 Q4 e
restore' f4 h& F6 h5 v& c) \) i
' N u8 ^/ S& u9 o: X
sum dx240' c8 S7 t# b! I" k$ s
local tempmaxphddy240=r(mean)
0 F7 ~7 }/ L' J$ A0 r) p' M H
( j! L; `% J: ~6 Q2 E
* Z9 h+ t y8 A4 h& E6 G8 m }
4 {' @# Y8 t' w 4 k4 F3 r8 @6 @! [6 b0 U
5 H# A( I6 z3 D7 J% b2 z
9 ]! G! J; P. V9 }$ a+ ^- q
! `# Y) b5 a, }$ A0 Q# L
' o% ?# T( D; N 2 V1 [# B8 G$ S' D5 O/ h
gen pmaxphddy240=`tempmaxphddy240' in 1$ B3 W F& z% S1 U" ^
\3 g- d& e; E$ `+ l5 _$ A
4 O, N, y* A6 w( N) L, \$ a4 p5 n/ v
*-------------ddy240pmaxp右侧低峰值 -------------------" F: a! x1 r* p
, A; X2 J/ c& z; ^, p3 L
preserve
- O3 C# I) O4 o" Q& M. f( u ! x5 O5 [6 ]% X- A
keep if dx240>`tempmaxp'& G$ K6 q$ w" Z* n8 ~* I1 S
# e+ a0 E) V( D) V
gen temddy240=-ddy240. n3 o; |$ t, v
5 {9 }5 l/ K1 [: i* e" S keep if temddy240>0( ?4 J# u* |$ C% D0 B
# G3 M: P0 l# t
count
, H5 C0 n* m" j% R* v) t0 F & A" w# J& N! e( G+ o _' F1 l" b, V
if r(N)>2 {
, \" E( O- o8 |* o% ~" R
% d6 r2 s' H1 v |. r pkexamine dx240 temddy240
, q! P( Z+ v( j% R5 `3 J/ C : P6 o4 q: a4 ?+ K# H% R+ n) @
local tempmaxplddy240=r(tomc) 5 p: ?# Q B% d. S
restore8 E* J4 D: E- r) E* {
}4 a0 Z5 g1 k6 C* k4 E n
* M2 R( B8 ]9 `- C
else {% m* ^3 Z) |+ c, q2 {$ X0 ^0 z
restore5 k0 |/ m2 B: |! B1 z
di "cannot find pmaxlhddy240"& M2 F& W: t( f# H& M4 P
7 |4 [2 Z: |* `$ Y$ l2 E, Z 7 z! j& R% D' B- P
sum dx240
) f6 n; q* m5 u1 B% m local tempmaxplddy240=r(mean) in 1$ F b7 B: e/ Q! j1 Q. W$ l
: b( c. ~3 }- S$ V9 G ( S- U5 F) j" P4 f6 S+ ^. M, s* P
}
' E# @0 i8 |7 o# n
5 b1 S+ I0 g) ?: I4 ]+ E( x# O0 ^
3 _6 `/ y: u1 U: p
4 I/ a6 t* ^, e: d 5 n4 d0 u7 r% S
# c" S/ [% v4 O# N4 K8 j% R' P6 t, `
* F' }0 [" W% r gen pmaxplddy240=`tempmaxphddy240' in 1/ w/ X! X9 p3 m" |5 v
, M. T4 J4 l; d6 x" ^: j0 G
*-------------------------------------
6 H5 f U+ `/ v- _) r & Z, I( Q! C+ T8 O
gen price5d=v5 in 1/20% }; ]6 O( v: u/ ^. m6 ?) t
4 }0 O% F, W9 [7 q
gen price5yy=_n in 1/20
% T) M, g' k- D9 w4 B
4 a6 h# Y; g1 K5 h' I. F2 c gen price5y=price5yy*(dy240max-dy240min)/20. z+ t9 v6 S# Z, v+ o: P: \1 o. X
& d q, }7 l3 v% S! y, r *price5y &price5d5 u. ~$ Q5 @6 o* r! M- d5 @6 u
/ |4 x1 L& n! Z |
gen priceny=price5y in 1
- r1 V0 D9 f [& @3 [7 v 4 K$ s' B3 f4 h8 m6 G) S* I) ^
gen pricen=v5 in 1& o& \. u7 z1 j& J) {$ g
6 C `( l) F, p g, _
! a4 k7 |( J/ r$ R) n& \* _
*priceny &pricen
4 `1 b u1 B- n* m 6 S$ p, s. X/ @: @( r2 e
! s- B. d6 B# P1 P* J *-------------------------graph------------------% ^ J3 z r' m2 m1 c7 A) t7 W. o$ F
d6 l" j# b; h6 ] 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)+ d4 _# k0 H: u' \" `
1 ]# f( L5 K7 B# Y2 M* ---------可选项目----------------------
- Z8 S; @; K8 b7 Y% h3 n
{: a8 y4 s- T* h7 h}
9 r2 v% ]( M# L% S3 v- P& nend
8 ~, U2 J! w' x! P0 o! u; p% ? f |
|