|
改了一下,这次运算应该没啥问题了
4 d1 Q/ r6 M; a% F! c) V3 A0 l
# d1 c' b( p/ f9 B. \5 _! _! ]- ~/ d7 N0 r
capture program drop hello0 b4 b* c# ?( B ^) {
( S+ U3 ~1 Z6 n i. U6 pprogram hello
# j7 _7 B9 E9 `, x; I" p! X6 G2 P {0 P
quietly {1 b1 K# q% B. S* J
$ d8 {' W7 I, |+ Cclear* b) C2 u4 y* }7 E4 z9 N5 {$ i$ H( |
* b) ^3 N x* ~: ~# ~; J( D1 v: rcd e:\finance\stock\20110101\source* q) ]+ z1 h/ F
/ \* g8 G0 r* [5 Y7 Z0 B8 S
insheet using `1'.txt
) _* i7 k5 p4 a$ p2 i# s' D
" g: W3 [+ i6 t: D) \9 p6 w" j/ D keep if v5>06 h0 m$ f3 h R2 A4 j" P8 t) Y7 \
6 v7 ^* R5 Y2 h/ K gen vt=_n/ I- `1 R7 z+ g, M7 A: P' ?
. M8 C8 \2 E8 h tsset vt
! c/ w5 Q1 w' Q5 P: a: S: Q0 F+ W Y2 a2 A
gen zf=D1.v5
( m' ~) }( @+ h; l' o/ T2 r' C7 \4 n6 V, ]
gsort -v1
P) J# I" n9 e) c
7 \* }( ~0 R6 E. G0 ~ gen avol=v7/v5& z' t" d& w2 J4 k! W
4 M% e5 n5 p. p. e$ D" U O* o# e keep if avol>0: X/ L+ N! `% M+ _. T C) E* G
) g0 H& }3 [7 M: ?/ G
drop vt. N. `0 L4 J6 i
: I$ s. U& m+ W6 W& `2 O gen vt=_n
0 \7 u2 |& }) N9 x2 C. D5 t + H6 R+ [8 \/ w, w8 H3 u3 G
tsset vt
% `. d# |: R. J8 j0 Z C9 C! x , i4 G1 H( O" [& y3 [4 m
sum v5 [aw =avol]
( A) q, s$ X; Z/ [. e
; o5 f! q1 |6 Z0 R9 K/ G; C gen amean=r(mean) in 1
w6 S0 s% M# K; y2 e2 B! Z 5 R& d2 _% E" A, L
* 总加权平均值 amean
3 P, M% _; {1 [; m1 @3 _
1 |# h& n4 M1 D: q ' K+ S) K9 @, T# k: @9 z2 ~7 ^- L
keep in 1/240
: h' Z1 k7 D( b* O3 X* O4 ?# Z ?
7 O- D! v2 N. x0 Y) ` sum v5 [aw =avol]8 @7 U, _6 g8 e1 C
@7 Z* [- E$ Q; ?" k& V! J2 W gen mean240=r(mean) in 1
9 y+ E2 _6 n v- k , x- O4 g N' [2 [* U
*240加权平均值 mean240
3 B7 e4 e6 I g' @2 w! {% B- I 6 U+ W+ V9 @# A2 G% @( N: Q9 P; t
set obs 500
& V `( `) C q9 Q7 i2 |
* k N! t. h9 j+ W- b kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
) z0 x) }1 |- c " n1 |2 N0 t/ u% l8 q
*240 kdensity(dx240 dy240)
8 S- e1 p. K% ]' x1 G$ M+ c- K
& {" S$ T8 g3 k. {$ i6 V sum dy240+ I2 O: u: O5 m. b- Y$ x
5 c: I& b: s/ @7 G! |
gen yxis=r(max) in 1; W' D8 O& ?! J! l
; x5 @' o$ O- \8 v( f gen yxis2=yxis/21 `7 `* O8 S$ f
5 c. v: A/ _; }7 G" T *yxis% \$ Q5 ~- D2 H
( \7 e+ u4 ` {- n gen dy240max=r(max) Q/ ^ _$ L4 i
# _9 d. s9 X, ?# c6 y) g5 B gen dy240minp=r(min)) P7 C* V" n! T' a+ l$ |/ e- }1 p o
( Y( h M# {1 \7 ]
gen vtt=_n4 T* g8 v0 t* |1 p2 Z
1 x+ r! `3 C0 C0 {8 {. Y. | tsset vtt2 v' C1 l2 V9 R: a! H
$ m/ ?, g! m9 F3 O
gen ddy240=D1.dy240/D1.dx2406 O% A) ]; u c1 i
0 D5 S8 K' x4 d sum ddy240
) Q: J" b4 |% p1 e# g 5 u% u6 O& i+ z. ]% N8 W
gen ddy240max=r(max)
H# `! n' X: t7 ^; \
1 _1 O! n( h& P gen ddy240min=r(min)
+ B* l! }. V8 v2 H, z
9 U: [( m1 [# J5 O7 C. M3 E4 ` gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)5 n1 |: J! Q) F, I+ Z
# X* g: g- L( e1 V
sum ddy240g
; t F( k' ^" G4 o+ X
5 i0 H5 `" O( y4 }2 m. ^7 a6 F gen yxis3=r(min) in 17 r& g# u+ q1 I# D U: b
! S, B: U1 U* J* t9 U' I2 ]+ E gen yxis4=0 in 1
' l% f5 J; q( }8 n4 w( X% V
V3 Y3 s6 F, Z *ddy240g
! ~4 f+ i) R0 G& w 5 I1 k: y) ]" b# _$ {. c6 w
2 v J8 T' z5 O: K preserve
% k1 C: T/ d9 }- ?& s! P5 ~/ y& M7 ] 9 {" X% F" D' J: J
sum v5 [aw =avol]+ f" {9 j, N/ T3 M) m1 g4 z
+ M) J0 E& b; R2 @ j* `
keep if dx240<r(mean)
6 V- Z. p4 b6 r0 \ 3 C N; s/ B8 z/ @0 @6 Y
sum ddy240
8 @# p, K- ~2 ^1 ?3 m1 r
# y* M4 ^7 U( _8 b- o2 K if r(min)<0 {
`2 u R) v3 Z) ^, n, d . i4 |8 x: w l8 q1 E" K+ t8 P
keep if ddy240<=07 E1 N* Y% L# I: d+ d+ ?
' v& U2 n. b5 q! r# i I0 j count
& L& b4 q: D8 _* x - d7 j' @& w# z" J1 _
if r(N)>2 {6 X7 T( W1 q; e9 P- Z7 ^1 T
; f/ D. O8 {* b1 O% z) v9 G pkexamine dx240 dy240& v7 ^: P- B7 C4 z* f/ d$ ?
& G+ H- V& ]8 ?0 U* v' o4 W local tempminp=r(tomc)
j+ Y9 A2 \; I% H" \2 @ restore % V" I2 W' m& ]1 v& y, j0 r! i
}
$ o% Y! B) \- d* C3 o0 D & V4 A( i- |. G7 k+ u
else {9 {: }' |& |+ t5 h8 ~
7 g. G0 l, k$ P) u+ d di "cannot find minp"
R) ^) ?, b& N0 s9 s! K6 | z ( Y- w3 Y: h% P1 ?
restore
( X3 g) M$ W' l& k sum dx240
9 w3 H e$ h9 a, d1 | local tempminp=r(mean)# q& }0 H7 y% S$ }# I
7 T, n, s, u4 L0 V4 Q0 _ }
* M! y# z. {* s4 B( t4 ^ }
5 D3 t/ Z: d! z, C( G( M! u else {
% t2 N* W4 G) [. l/ D 2 n" @6 H! k( w- j, E% y
keep if ddy240<=r(min)
[3 ?; M3 J2 i/ L4 D. A
4 M3 [: W- O3 _9 t& S sum dx240, V& ^$ G" m7 X0 c. h4 ?
/ s3 @; k( ^& S5 |( v: _ local tempminp=r(min)
4 _0 J% U6 W/ e7 X5 _% B# _4 X restore
& |9 N! W# U0 X5 V- e- [, A }
# b# |7 B0 G' W1 N/ Z" `
8 Y7 T6 k' A2 X
% P$ a+ g/ t$ I+ f2 r) H, M& K5 [6 M+ K$ M
gen minp=`tempminp' in 1
* U! f" {+ s, i/ B3 ^" O9 `9 q *240 minp
4 \& X1 H' y9 h+ y4 a. S5 \9 P" o* I0 N9 }! J1 W1 x
2 H& \5 t1 Y/ A" }! ~( m+ @* V; S/ q
8 j% k. l. ]* ?+ p; f5 U preserve
5 x& w( f! L: n: c
6 Y" @4 s% ?$ u6 |; p) U" A# o sum v5 [aw =avol]: z1 n; o7 \* v0 e) k8 ]) h- K( M o6 q
' ^" a) g7 O t. j keep if dx240>r(mean)9 I- }" I8 ]1 _& ^
" Y4 Y" |' j1 L5 @: d sum ddy240
& {3 a6 U+ H2 [) \! i8 E: s7 W , A' U& J% B/ H4 o3 U! g
if r(max)>0 {
4 }4 F4 _! x+ @ g8 N 9 T, s- E4 t& X; B+ i0 @, N% c
keep if ddy240>=0
3 G) K; a' A% o' @( W5 L. \! r5 U( v- X % K, [3 A4 V3 z: [4 D7 y: G
count
' h% _+ L! N0 U
- ?) K4 w" V8 A& U if r(N)>2 {
, `6 s9 W, B: J% ?
7 w! p$ U! m, q; k& N pkexamine dx240 dy2405 L( I& G$ x; n
7 q, H# k0 P" D z, R
local tempmaxp=r(tomc) 0 ~! v4 N. k4 S7 w1 D2 A$ n6 ~
restore 5 c! Y0 V7 c! v7 ^4 @) V: D
}9 h; N7 `) H4 m5 [' X0 p
, _+ F: ~. N; J8 X2 d+ l
: B1 I. O- k& r+ y# E
else {* t) ]& D S1 a, r8 Q$ \3 H
restore
! o- X; {8 j# l& V! w* P+ F di "cannot find maxp"
3 S* a+ \8 }; a 6 S" t, J( a: t# q
; D& v5 R& _& D9 g) @# y
sum dx240
- F0 l* x5 u0 B4 O local tempmaxp=r(mean)
- f, ]) X; _, l; {) t + R1 c' h, Z5 K, A7 h5 [4 L R H
}
5 m0 ^) }7 d, ]7 \- x6 _ E$ t$ A
: @5 g5 {5 K$ f# X1 r1 z4 d }
* N! S2 c& h4 m0 S1 H2 Z # i0 x- V1 |+ x2 A& m) k' U& Z1 C
else {7 z- T, M8 b Y6 i9 r$ l( u, Z! l
$ B2 h% r3 T8 F. n: C keep if ddy240>=r(max)3 r: `8 S. k, m% b
{4 \% T! i. O: q) \
sum dx2409 E8 z/ [ r* j4 }
7 S6 l0 E6 q |/ T local tempmaxp=r(max) & K. B& o' h: `3 _$ ?
restore
: t! p0 S- l. u9 ~# [- y$ i }
8 C/ Q- _* p# u0 E9 l# |0 [
) p4 a* g: y+ g1 [
, \. E, V, k$ K8 F" R
; ^) R2 V( H4 D$ {
* A- x- \& a0 `6 ?5 w0 ~5 q% K gen maxp=`tempmaxp' in 1
( r' O9 n4 t$ i+ j, _ 1 s5 c0 I6 {! p
*240maxp3 {6 C! O2 y6 e3 e
" s" o' D6 \, ~- }+ X5 x
3 N: h& S& ?, x/ b- O9 x, [ *-------------ddy240pminp左侧高峰值-----4 L( y/ R: g: S3 K7 {
* |2 d: M+ W- k" p
preserve
7 I# _ j8 x2 z% g/ G % w, |- ]2 O9 Q4 M$ N
keep if dx240<`tempminp', g' F+ u, l" l9 n
$ A& N# _; j L) d3 h) m1 [
keep if ddy240>0
. b# W: j- s! g) ]$ S/ G / C3 H; R" }" X
count
. ?3 n2 r5 n7 c6 x- e" a0 E
) @6 X4 A, R7 N8 o: o- S. i if r(N)>2 {; z# r. q" [# b5 `+ w R
. z4 Y6 R! a- y! m' q/ b- z
pkexamine dx240 ddy240& s( `: g9 o) J8 o ]
; ^! N0 L# Y3 H: _, ~) t5 C' e' g
local tempminphddy240=r(tomc) 1 w2 I8 @# w0 l# M1 u
restore
- B% s# k1 ~. Z/ m- G/ a }
2 W- F8 ~, D: O: L ; L) ^! ^" w# c: {
else {
9 h+ i6 n) A1 @1 |5 u \$ g: h5 a restore + W3 A% ?' ~7 b: L1 t! t! x
di "cannot find pminphddy240"# L6 [& J4 q8 S5 K9 x
9 i; `% |& s& m* V* r; ]
; ?7 \5 H% C1 n2 S) e
sum dx240# O' b$ [" r# a- j1 `! }7 R+ n
local tempminphddy240=r(mean) ) c8 c+ F/ b: f0 x0 {: P; f
. E: k% L _4 n' a3 x$ o4 p @. B
. r, a* n3 C" I& u& S/ R }
- H* w6 @& o \' l t0 K$ G: o# s6 @, I4 G( w4 q% R
- g9 d0 ~* b% | 9 o% q% _7 h# [+ P7 s2 v
4 Y3 a8 f8 N9 x# d
- r9 u( J3 _% f: h( x* I* ?1 s
3 _8 [9 X: ^: t6 d% t
gen pminphddy240=`tempminphddy240' in 19 ~- {, Y1 f6 ^- p. O0 ]$ r: W O
$ t4 D$ e6 ?" l6 P
! j% K) ]" e& J( o- s3 W9 U7 o *-------------ddy240pminp右侧低峰值 -----------------
, c4 J/ o) ]* |+ ^, C preserve
7 H% B" z( l$ h5 R* i
8 H3 K1 g! r; A% x% T- q3 [ keep if dx240>`tempminp'* H- K+ N" `- q- \$ V5 }
- h: R; j( Q7 w7 r6 n6 h6 C keep if dx240<`tempmaxp'
" C2 K7 f( D# P' G
2 m- q a6 R9 H) Y% ]! ? keep if ddy240<0$ X. U- T% z: ~. `2 G
% }1 j4 u4 Z5 ?* _' K) g7 o gen temddy240=-ddy240+ ]# a" R: k6 \* @" d% V! F! i3 h
1 Z) G4 W' d: m" L count0 O! W/ Y/ I: g% d
- c+ j& M3 H, J* R if r(N)>2 {
( _. z: e0 Z0 r+ f# W / _; ^4 [1 @3 B( g. z, ]3 |2 O/ C: A
pkexamine dx240 temddy2407 \' }/ u I! }
5 w5 S6 | W1 d0 W* k; f7 }
local tempminplddy240=r(tomc): }8 y2 `/ ^+ \7 q
restore7 X5 b8 y5 u' O* G4 M
}2 n3 l c5 \( i9 q2 W' L( a
& ?8 b8 u1 V: w+ |$ ~
else {9 D" e2 F3 b; ]2 y4 ]% P. E# N9 {8 N
0 I! E0 E4 V! a8 q5 T2 `
di "cannot find pminplddy240") W/ T+ Z5 e# k8 M( Y. X% p
restore, a% A& V3 k4 J, G6 K7 T! V
. t8 V7 z" x, F z" M
sum dx2408 q1 N& c& ~0 L8 }. V5 Y) D* b
local tempminplddy240=r(mean)
9 @5 u% } f4 o/ J* [9 C, p
' Y: e- q! z9 B! y3 T
- ^+ w: W4 k- d0 F }
9 ?; U" d2 A+ `! l/ B' Y Q. h ' `# h' `; Y" I+ U% |$ z, A! L
. T: M2 N! U0 i& l, i6 m. \
" z; A: D( e$ j ; r) v6 w7 Q4 m
3 ^7 P# _- G3 j# t; d$ { gen pminplddy240=`tempminplddy240' in 1
: S$ \: c' ^& N7 |" J3 _6 V6 G7 r$ B6 d
- I$ o& r0 G: K3 S7 k1 Q# f0 _ *-------------ddy240pmaxp左侧高峰值 -------------------( U0 }5 D( ?0 M5 h/ O q
% u) ]# J7 |/ |. {: ^0 }; c4 q preserve
! _$ }7 ~) m8 `$ c0 |0 O; B - B8 E, y# ~9 ]* \" U' [& K( ^$ B
keep if dx240>`tempminp'
1 w" \) t2 Z! c) Z1 L / Q% r; N4 U. h+ y7 r+ V# ]! C
keep if dx240<`tempmaxp'+ P: S( u. P3 x9 c) A& T
`7 T: g# F# Z+ M
keep if ddy240>0
4 h/ h ]* G* L3 e count
. {2 x q& S# m! [ + I$ ], q( b# l( @2 ^, B! V6 r
if r(N)>2 {; B6 w0 A' z' E2 H2 B
4 D E9 H% h; l& h6 r7 G4 a pkexamine dx240 ddy240& W1 p! o4 O. ~
) }1 D: h! _8 W: K local tempmaxphddy240=r(tomc) ; o9 m# a9 t+ Q) D/ l1 R/ _/ X q, \
) y( a2 q" e. Y) Y4 o) v, S2 p: a4 {
restore
7 t0 t2 o* d: r- ]% u2 r }3 ?$ i3 ~8 h8 G" B* |. u
" E' P# Q! M8 V( S0 L; [
else {% z! r8 @" ?- Z7 F9 |# u
Y$ d& W: O2 F7 W, \" S di "cannot find pmaxphddy240"1 B6 c: y& Y' m
restore- L! O8 s0 Q- {" u4 U6 q- p% R
& x6 y Z8 \ N; b" \ sum dx240( N& h% s; ~2 y: Z2 D
local tempmaxphddy240=r(mean)
' i+ g" S5 f- M8 B( X, S8 M 3 d. W& K- f, v6 [% y" |" O
+ ~5 ]9 F0 }& M6 n& R }- q3 `/ W) C6 S
3 y8 m% i; P" y$ X" H& [8 m0 [8 _ b' E; T7 D5 t7 m% ^
" Y" e. @; B6 H7 x
& ^ i- @' R! f- p7 u $ I! I9 [/ J* j, @& d- e; z9 i
8 I5 ?: N: X5 F. y2 X4 W
gen pmaxphddy240=`tempmaxphddy240' in 1$ X5 Q- g0 P! b" q5 ]" Q
7 I5 y5 y9 ?& J3 {0 w
3 }% N# `7 p/ v+ N$ [! ?
*-------------ddy240pmaxp右侧低峰值 -------------------
, i6 \! P2 m' K8 `; p7 z 5 M: l+ ?5 }7 v* p# D/ j! d
preserve
9 x+ a1 @3 y, F. _+ Z, P ; A3 _5 M- f$ G9 {
keep if dx240>`tempmaxp'
- l- F+ N! E7 M& v. i) K4 u$ S 6 }8 q% e( h' k: P6 s/ @" h2 U
gen temddy240=-ddy240# o0 @4 q9 G: j' Q$ b
* R( E5 _$ q5 h
keep if temddy240>09 c% a- H; N( R, o4 K
+ Y/ i7 x4 n+ S$ u) [+ R+ K count# {2 D' ~4 v- e% s! ~
3 s0 H0 @; d1 |. [# D
if r(N)>2 {
1 h) }: o; m* z/ h& \) C9 }! P
8 o) H- Z, o! H! B9 A pkexamine dx240 temddy240
9 u, c( Z6 n/ }' m. e( }
# l# R2 Z2 F4 } local tempmaxplddy240=r(tomc) ( u. |# a) A- `) S6 k
restore" I3 {: m4 v, P% U
}' ?' m! j9 t$ Z, c
, C& f/ J' ?, a+ r/ |1 ` else {$ J; n+ |$ G% c# N4 B
restore
# e# Z ^+ n4 x, g# o' Y, p- ^ di "cannot find pmaxlhddy240"
3 m9 Q/ B9 n/ q1 q( I. O2 J# S
' p: z' g& H% X" V3 Q
, T& @& `" D- E- e7 y9 \( P sum dx2406 Q2 w5 ]6 R' z% Z# Q2 Q" [6 ?1 h
local tempmaxplddy240=r(mean) in 1
+ U5 G3 C% K$ X" }2 z% r
: e( g3 e5 i5 E3 Z3 Z! f/ g
$ n- q6 i5 l, h( p% o }
! L( s' }% g% b ! E. I; d. s5 B
; h. p6 r* R/ Q, L: D! c
/ D# P+ [/ v# C( D
& ]2 z- [! t* T P- k
9 t/ R, i" e3 ?
# t* X1 O. U# |; }
gen pmaxplddy240=`tempmaxphddy240' in 1
7 v2 `$ b' o8 L2 x' |
/ V5 k+ ?- o- j, Q9 K6 A6 Y *-------------------------------------
8 r5 V9 ^) @8 D: n$ b9 T, e* I
+ ~9 I5 z0 t- I# k' M gen price5d=v5 in 1/20
( J% Z7 i+ U; \) ^& S2 z2 r $ V ]0 H1 M, _! ?+ Z% Y
gen price5yy=_n in 1/20
+ A' g& P6 p1 P # m, w' b" j7 t* S* B6 `
gen price5y=price5yy*(dy240max-dy240min)/20
& N, p5 e F" }# f* a7 J) | 4 N* u1 ?- c) [* E
*price5y &price5d
! a( |5 J4 O2 O) c; u2 r
3 T* {$ k: d' Z$ O: b$ d5 Q _+ k2 V gen priceny=price5y in 1
, D( r ]0 O- X& _5 _
9 K# d8 R+ E& k! t8 _ gen pricen=v5 in 1' x2 [" i7 V8 m& a% g5 }) ^5 e ~
3 Z2 I( R+ x* R- M9 N; ~8 G, i2 ?
; V& ]' B6 }8 S7 T' f: \# x0 y *priceny &pricen: Q4 |7 C9 {, f
" e I i- X3 Z$ X
% e8 @8 |& B) u( r: I2 K *-------------------------graph------------------
6 h' n+ \9 p/ Z* d5 t: @$ F + \3 r1 P! m; p
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)" {% g B# p/ }( S m
& d, `& t. \6 \2 q% [
* ---------可选项目----------------------0 }+ G2 L2 D' A" i, M! h
* L/ ^( O6 {; o}! S3 f+ Q& p5 }0 z8 A: a* |# ]
end
( ?/ O8 T5 ~* R& H |
|