|
改了一下,这次运算应该没啥问题了
2 o8 n9 y& X# P6 V3 o" y% d
5 x, w% s4 N b/ x, p: }& N
/ e& U0 B8 S" U8 L3 ^0 Rcapture program drop hello3 ~6 Y! G) X$ ^( j
1 V) w2 C; s/ j; }+ c
program hello: [( F7 f1 v1 W. A) C9 X& q5 B$ A1 H
9 \6 l* E$ g$ f9 Y# x5 Y
quietly {
6 K0 \" L5 \) J2 B- C8 s
) Q& N) v1 S4 x Kclear4 \9 A+ }0 }4 U9 p! E. X
' J' s9 w+ j& W8 Bcd e:\finance\stock\20110101\source
% R4 |$ ?/ U# a2 I8 R" y/ _
1 y' b/ N8 |& [$ n- s% W: ~' vinsheet using `1'.txt, H6 M( P% i" j+ ]5 E4 a# d
. u) Z7 W$ c" Y8 X5 Q keep if v5>0
3 A. L) S, f( o0 w3 H* K6 H
+ W% a( _: J+ d) g. n gen vt=_n
: h8 I! p. l% B/ e" ]. Q u
! m- M1 O' }) v' N/ B tsset vt& r# W: {) ?) e* O9 M
0 Q4 Z" _2 b- L
gen zf=D1.v5
8 A/ N: B- C5 s4 \/ Q& \/ f, B( s7 l. ]; j$ C9 J
gsort -v1
( J3 ~ B* M( P5 {! h9 K* e( }. S l4 d; D i
gen avol=v7/v5! _5 ?- _9 C( @' @+ B
7 Z1 o6 w/ b4 _6 [( B. I' T keep if avol>07 b6 u+ n( G9 B( {" @3 G6 Z1 v. @
0 C0 [5 T+ Z( D: ]0 z* X drop vt7 D0 P/ @% Z$ n! Y+ ^9 F
: Y; s$ Y- y' B. A: E$ c
gen vt=_n
8 [' Y" g' J3 m) |
4 P/ J6 [0 f Z) M& `5 E3 R tsset vt- ~4 d; E9 g9 n
7 c- F1 c( `7 Z+ J, T, F sum v5 [aw =avol]* ?7 g. @5 L+ |0 g/ W* e# z
& |, {& V" ?5 ~ gen amean=r(mean) in 1
- r1 ~. G8 b4 ^) c$ l8 C4 J 3 t/ S6 b0 Z2 Z+ w$ f) P5 x
* 总加权平均值 amean/ a9 I0 _* L. P2 g
" s( G7 i- d0 C+ I3 B
. c- k2 E3 F* s
keep in 1/240
) q) y9 l) G( l& V8 {$ A6 m; X3 L9 T/ Z
sum v5 [aw =avol]
! Q0 i* m0 X3 r2 q' F" }. m* _' _7 `+ I0 P
gen mean240=r(mean) in 1+ U Z* i" Z& O6 D5 V1 g# |
2 X# W: G0 g; R, C
*240加权平均值 mean240% S4 q( _0 E2 W2 g0 o1 h) s
% Y/ y* \4 t) L# P! ~+ U4 p7 ` set obs 500 , R8 ~2 A5 V7 X/ Z
+ |2 O6 c/ B9 i( }. @* q
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph6 T& t8 f9 K/ F: N$ T! L4 g
; H6 g+ x: w* a. `' r *240 kdensity(dx240 dy240)$ n& ^: O9 J8 S' L. ~
) ]! \) a O3 l- \) @9 U3 V
sum dy2400 `) \, |6 K6 U3 @- {& h2 n+ t1 V
+ N- |# p% g$ K7 R5 T, b gen yxis=r(max) in 1
" l1 p) w$ I* p9 M( {) G+ B' i7 F - M# G4 |- A( y1 m _
gen yxis2=yxis/2' c) p% S8 A" w
; _- a2 u7 V% Y6 ?- g% G, y# e
*yxis* K; R* D( r: [# H) S
" P6 m5 n; R8 P3 h# f, o* ]* L gen dy240max=r(max)& \( H/ j! ~6 i( f) h* R2 u: _/ _
8 g5 k! A" C, t gen dy240minp=r(min)
0 F G" w9 R! y F* O4 _% E
1 p. l& ]1 _' ^5 W gen vtt=_n
1 X+ U0 ~- C) Z. |( o) p- B
' b7 }3 C/ d: N" S; B tsset vtt
6 v1 k5 N- X/ l/ y* i3 T
9 z Q& @( z9 Q$ S+ j gen ddy240=D1.dy240/D1.dx240- g d) L7 m/ c* \
& o/ ^) s7 E) Z& e2 `( E2 t1 ] sum ddy240- l1 Y8 C. ? [
. l8 L: h2 ]7 i- \# y* c
gen ddy240max=r(max)' n9 {$ D9 P! h' r5 d7 S
2 u# A; _7 P" b" h2 w3 e3 z( J
gen ddy240min=r(min)% k% R1 r% }* a9 N
/ P, b* O5 @( E# E; r gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
& ~2 D; ]- V8 l. e
6 Y; \- j* U, B sum ddy240g
) [0 U5 `1 M5 a V
+ Q _- b" s0 ^ gen yxis3=r(min) in 1
$ `6 |" Y, t: l; ?* f7 q5 u4 x $ Z7 }8 l" T7 I
gen yxis4=0 in 13 y: B! b/ F9 F$ o* v K6 b
( C, X/ t. J) u& V
*ddy240g
5 q8 P; D/ \; U7 A% f) U 6 p9 h* Q' ^- s0 n, X v
6 U Y* j3 z& P0 o) ?) U* w
preserve 5 O3 ~. p4 l3 s" u
3 Z2 | v$ Y' U2 q5 x# f5 x sum v5 [aw =avol]
% H4 `: S; q# S3 h* r, r/ i. ~ v- g( _, ?% ?
keep if dx240<r(mean)
! X, r# S* N7 J& I- k7 L2 a
+ r' p+ ?5 Z, S# H5 }: A sum ddy240! q X; b) |: d" e, X' l
* l# g* {% F3 M) z5 V if r(min)<0 {
' j% n. H! H" j( M " k( q A7 Z; P
keep if ddy240<=07 Z" z6 R# _: F5 X
, l3 V0 h6 r2 i/ Q$ c7 T
count; r( q. n* ~1 ~; b8 F1 [" \
( H W$ z- [6 z- d( E" v if r(N)>2 {# d N, N. q% V- W$ h" L; h! h
* O( j% w. [* O* _; d
pkexamine dx240 dy240
) F: U0 ~( k) K3 ? O" [* r
1 _7 Z/ f) [. y5 o8 ^% H$ w local tempminp=r(tomc)) L1 j8 u+ i; ?7 x' t! T
restore
) b; [& O* A2 }( [# ]' M* J) f }
% S0 Y( z) H! K+ H% A * \5 W3 i; a: p# b) [* l+ g- d: b
else {
- m8 ~1 V- F7 _ : G* S% `0 O! G
di "cannot find minp"
$ j7 j9 w( u$ V1 k V" ? N g - D4 K4 I! {& M8 b: W; t
restore
2 `! D1 o* t+ p4 ~* i8 a* `; x sum dx240
7 J5 _9 u' F& m local tempminp=r(mean)7 q; M; h0 G. ^2 k5 g* w
- `' p$ s) l) o, h: M2 k }
. m) y( f) A" s0 z& ^ }
! l" \0 k4 n& f4 W else {
7 ^+ I& T7 D( L- l/ ] ( F. i& ?3 F+ W X% e5 R
keep if ddy240<=r(min)
5 e( j! t+ o" z( N0 ?* p( ]& U3 k 5 Q( p* x; U* u
sum dx240
2 {$ {+ w- C1 l% D9 N* J 3 {' x7 E( u7 n( G, `& Q
local tempminp=r(min)6 _2 m& h, j: G2 h0 F _- I- W
restore
! Z6 C r2 v+ |2 _: r% p- Q }& v. g/ U7 U6 B2 W. `. ?
" J/ z& N9 r4 \( l/ ] K
8 { r0 A4 W0 z
9 `% R, ? b( W1 @# C gen minp=`tempminp' in 1; O# h$ E* K0 E* u7 \8 l
*240 minp( c% p# Z- ]+ v4 ]
: [" C$ ]/ V# _
$ n9 y$ @# [( C0 E$ ]3 E
# j1 @; @: I j! W: k; m
preserve # z( v+ C) h0 [0 d' d( v Z
. M3 N: c' b; R- Q sum v5 [aw =avol]
% R7 ]$ q, a3 y. P, I8 ~
+ A [7 r) P! \" N% j keep if dx240>r(mean)8 V5 i, X# ^ K+ }: E
! y! X% H0 p" ]0 H7 l: n* q sum ddy240
2 }5 T6 v1 M- }! r# Z# |3 ^* C
8 h+ B P$ i" B0 N' Z if r(max)>0 {
7 {5 x. L; U1 b% Y- {
e1 T/ T. P" X9 q7 @8 C; o keep if ddy240>=0. j8 e! q; G9 q( m" M: C/ R, l
( f ]: ]4 K7 W' l2 g: J7 P( e, c p0 s count% K6 [1 j, b* t* r
6 T8 R# T% @- M1 W) z
if r(N)>2 {
q; G; Q! S' S/ r
* ]8 S) s U3 `! N5 e1 U/ B pkexamine dx240 dy240' X( j7 Q* z, K/ a0 ]
: N2 `- y- y% v7 f, u
local tempmaxp=r(tomc)
$ k( s1 o" j: V: u" B. e: L restore Q6 \" l% a, h% H% M
}" M/ Q+ a. F! U4 J7 k3 g" {8 f
3 T8 O1 T" r- D9 L+ K5 H! U
! P! o: P( J4 w. A6 D else {
- E: ~+ l0 j8 ?; U; v restore
+ r- ]% t* u; R0 Y; L di "cannot find maxp"
$ ^; m/ v. V7 z: q$ u4 M
6 ]4 s3 j2 X" o' A- `" e + f( r& ?' j. s4 F# K/ C
sum dx240
* n, Y$ q C* Y3 k local tempmaxp=r(mean)
0 J0 Y, \. I+ w& [+ X 2 W% M* ?3 f: Z
}9 c& t/ H/ H5 Z6 T
+ C X+ t' R( q% A5 ^& k2 E7 d }0 z3 D: d, S4 U7 ?
' }; H6 @2 D5 o( }+ L, W3 Z* A else {" r5 C( Z" m. Y" Y/ V) z% g) C& i
: c7 Y" [0 y6 n% G& h& ^
keep if ddy240>=r(max)
8 k8 V. a5 W, t$ U- O 9 s$ ^1 Q8 y/ F, w$ N( E0 S
sum dx240
* j( D& `( }; j3 \! W - T# Y6 |# v! b+ z) ]" M
local tempmaxp=r(max) * i$ M4 `' ?, Z, m/ h' D0 f$ q0 l
restore
( X3 ^* q9 k! R }
2 u; z T. ~5 R Z6 ]: D+ X' u
1 T" k4 A* `) y. ?$ n
% r' S" K1 J6 O5 ^/ \7 V; S ! V$ U7 e. m- o* f
' r; {, j, `6 {/ M: ^' A gen maxp=`tempmaxp' in 18 @8 @2 L, R1 r! `3 E2 P
% g! L* w- T) X$ l" j
*240maxp+ `4 E7 ~( K; ]; v/ ]
4 e2 N9 Y1 a* d1 M! q' `/ v 0 [; W R* [/ |3 R/ R8 L: @' o
*-------------ddy240pminp左侧高峰值-----
w/ n8 c8 |. u
9 u% I& C5 S# I- L; y3 x- G preserve # n& _) ?6 o* f& z
/ a2 }& o9 G0 A& [6 C% v1 `9 S0 [ keep if dx240<`tempminp'' P. \9 A! x+ o) _0 `! a
% l6 i2 ^+ M% K3 K, b/ b9 W
keep if ddy240>0
9 f' b y q' G7 y4 N( T 4 ]/ k; N& r0 W2 Y" [5 x
count8 _* i3 [* V; V7 ]( [, r6 r
+ r/ Z/ c x$ v& H3 F& D
if r(N)>2 {' k. ~+ R' ? `, Z! U* Y5 K
9 g7 k; ~0 D$ t. y8 g1 m! @ pkexamine dx240 ddy240
7 o5 C" R- H% d4 l6 U
1 @% D' U A' q) Q+ ]1 g. E. K local tempminphddy240=r(tomc) ) P& i8 S( k& E* e" k ?# A
restore
8 J* D1 N* H/ p! y$ ~/ V7 i }; Z4 k0 t- e3 l' Q8 Q% Q
! @7 w3 c' ?( Q/ F
else {
0 _& g7 @( U: C restore
5 p4 |% Y! l0 s, r& Q0 v) u! | di "cannot find pminphddy240") w( ^5 p0 \: R
. E; I; Y6 h* A
/ f9 Q }, ^0 L* T3 t( K4 B" F
sum dx2401 R1 g. B5 ]5 Z: O9 I
local tempminphddy240=r(mean)
5 O3 S6 h& q& v3 @
1 Q) i* ^2 X, u H " n9 Z7 l4 z2 |( {
}& q& `; r' c' t
. \9 [+ x( x3 _/ Q8 U 3 r# S( p) A% }
* N5 j0 d M# l$ |# t, b3 s( D- a, r - |/ F' x3 Q0 O# R; O
& F. w0 D2 o9 i u3 m6 A
/ n7 ~& O8 B+ Y gen pminphddy240=`tempminphddy240' in 1
# h0 p! R& R' x- A & C- q: |0 X+ q
, m! C" P H; I+ k& K2 A *-------------ddy240pminp右侧低峰值 -----------------
4 c. z4 r3 ` R6 b n/ y3 ] preserve / v9 R9 \/ Z6 D& ~3 f' h- \
1 u3 H8 |( {* | K5 F6 w2 {
keep if dx240>`tempminp'
" T, x1 g( c- C# R6 { 7 K$ K1 _- @) f& [ J
keep if dx240<`tempmaxp'
; T" t' O: F G9 W5 J6 S
4 ?- m% P& } ^ keep if ddy240<0
. H% Z6 A9 `$ o; B9 W3 I
9 S# p1 G" p0 ~% ^/ K; P) j! i( X7 P gen temddy240=-ddy240
' }9 C, O7 I9 [% z. c " \) B- s& U; e4 _: u
count
' t X' b# a/ J# ~ r _+ @
/ V) X L' f: F: b if r(N)>2 {
' g; I6 S8 g( s
* a) X5 e4 T5 h pkexamine dx240 temddy240% E! S' Z/ K5 y. u) ~# z
6 b+ f# A9 J" C9 J: z; t. x ]
local tempminplddy240=r(tomc)0 f+ r0 P4 a4 o5 I
restore
' }6 b8 u2 c' s& U }0 [2 `' M' K2 M# W) U/ k% F, J1 G/ J
* Y6 O' S5 T8 o w1 }
else {
4 f0 h2 K/ j( O3 \1 T6 Y 2 T# h# w! ^. j# h# M7 h
di "cannot find pminplddy240"; c g- I- U: w, P9 J7 o7 }. W
restore
9 s2 q- | @2 h
+ u: h: j' c5 O* W) Q( l- r% k sum dx240! D8 Z( j! G! e; q2 `: X" [
local tempminplddy240=r(mean)
7 g. ]( [8 i' v% C4 W
6 S: f# Y2 I# T+ a, F& Z * I* w. ^) Z. V$ ^
}( s& m$ j7 m1 Y
7 Q+ M v. w8 {, @ \% P 8 F) R3 }5 i4 u; ~/ d, [
) I% z [* |, _% Y& t! _; T
8 c+ i+ D2 v. C: `
2 J) x9 h- \. L; L gen pminplddy240=`tempminplddy240' in 14 i2 \: w* M0 g5 h- h# i
7 ?3 B/ |. w9 y
*-------------ddy240pmaxp左侧高峰值 -------------------7 |3 n G$ I z8 r
7 W' ~ Y: \. }5 }/ n
preserve
% h$ L- n+ ~3 g
$ {) C, d6 k5 q* ^4 D4 e; q1 d keep if dx240>`tempminp'6 I8 Y3 H, F+ [4 K& u0 ]
2 _- J3 t. e( b* o1 n
keep if dx240<`tempmaxp'3 L' X3 N% G; D3 `; j2 W8 J
2 B( y S( B9 ^) e: k
keep if ddy240>0 D( N' A9 M. p, z1 G* u2 w
count
) R7 g/ o& D; t ) X2 I' ~# _7 H: u( t% F
if r(N)>2 {
5 W# a$ M5 D$ d# j0 u% S3 R$ `$ g
+ H. Z. e. s: |( P pkexamine dx240 ddy240# s0 U, |! r' x
0 T2 ?& V( l7 n* w local tempmaxphddy240=r(tomc)
0 _: S. |1 N* |4 o2 H
\6 j0 V0 v7 X- D$ K restore
C# \* u2 E- y% i% J }
* _1 x! t q7 o3 ~/ V+ j: z 0 {0 y- {4 v' i% L
else {. P8 l6 g5 V0 |4 F, ^+ s4 r- V
* O: M3 \* k, S2 M3 C+ s" d+ t
di "cannot find pmaxphddy240"% h; r; c* v) G
restore, ^! x, ]7 r( x+ i) r
' [6 v0 Q2 A: S9 J, _8 z
sum dx240- v2 E7 k0 m1 ]; f3 t
local tempmaxphddy240=r(mean)
' K/ s0 M L3 _6 n
& \ { |; j- b) N5 n9 `
; E5 o6 e T Z1 f- w! ] }% _1 x) Q$ z+ Z4 u5 H) l
1 q+ V6 l/ C/ B' o" I, r
5 z* `/ I' C. @+ \
9 s. b: V* ], H) E; ]$ T: E' u0 Y
) m' k0 m3 N, d" C( X$ P
: D6 I* M2 R. w" K/ [ 3 E' S* m' @5 Y
gen pmaxphddy240=`tempmaxphddy240' in 1
5 Z% F$ \7 @% G 5 U. V9 w6 n+ {+ u
& `4 Z" D' n3 G, k. I2 i) }
*-------------ddy240pmaxp右侧低峰值 -------------------+ V7 O* Z' a1 O; P; v; M
. @. i: O( T/ w' g6 [ @: w$ ?
preserve ; Q( R' l7 a( p+ x/ H: x
. e0 ~7 d' a2 N) f+ x7 t keep if dx240>`tempmaxp'" e+ ]0 q4 V5 X1 ~
: E X1 k# q% K8 }
gen temddy240=-ddy240
4 `# D5 R) h8 ^: n6 X- ]" g. Y
* r w+ Y W9 s$ n; d keep if temddy240>0
7 L& J4 d* f4 Y" s, X
( C, a& U4 B, `* n* H count
2 h7 Q4 h( a- N# L " r9 c! U8 R- p( c9 ~9 p
if r(N)>2 {
$ K% ~' v' o* V, V& ~7 W: D % l/ Q7 U7 F7 `. y+ U. @4 W- z B
pkexamine dx240 temddy240
6 N! Z ?& M! ]3 s! { 0 m. a% S6 D O- V
local tempmaxplddy240=r(tomc) 7 d s" R5 y* }1 U
restore, x" M* e6 G8 V. ]2 d6 m6 r1 m
}! C+ O, ^; }+ N- @
7 K. M% G3 f) b2 V0 `; p else {# U8 H! a& _& D" j. o1 q* c3 M
restore
% C% l& e9 F& O3 a# { di "cannot find pmaxlhddy240"+ [9 y/ E& u% I+ C
' Q9 }6 a; B% H* g
% |- f. N: x' ^
sum dx240
+ c/ @- ^, ?' m local tempmaxplddy240=r(mean) in 1
3 M- b2 i+ h3 c) d" z& k " m1 Y7 C' J( K: G
- j' o: N9 b. M# [ }8 v# n, p& ?, f4 M$ @/ B
* D$ c+ O( g, M; U' [6 F
}9 n, R o( l& M: l
0 R( b% c- @/ `: `- v8 j' E
) N. ^$ g6 B: ?- L$ [' Z
\- |- O$ L6 } : w, F2 |7 y' v
gen pmaxplddy240=`tempmaxphddy240' in 1
# d7 ~* v# d- `6 q: V8 E
6 v; m( Y3 B; v2 v. E+ k *-------------------------------------
, F% o7 \& s$ E" C6 n( L
. }' g2 |( F, Q% H! x" b: U gen price5d=v5 in 1/20
4 n" a/ ~7 W0 u0 \+ f9 |* E# O9 t
) f' D2 V" q+ C0 F gen price5yy=_n in 1/20
: c" k' W5 y" x% m3 ~$ }
5 x) u. W8 D" x( y5 b$ f/ \ gen price5y=price5yy*(dy240max-dy240min)/20- T( f, T" X t
. U3 c+ \, L- [; B *price5y &price5d
$ c+ C& k% a, \0 ?+ d2 P5 V / x: i0 u2 F+ I9 ]( N- W$ S
gen priceny=price5y in 1
% n& I' m- \. N+ F( H5 | . t* I( B' Z$ [9 f$ S: F
gen pricen=v5 in 1& r1 f" w) O. m% y8 [7 Q) H1 t
; o( k6 B# _- w+ a" Q& Z
7 }& @6 G" @; B& }" @( ]& ? *priceny &pricen
s+ L8 I. L# |4 C4 v
3 t2 s: `* Q- v5 b" q% r
' z+ h/ \2 A- u2 K2 M( i *-------------------------graph------------------" U( x* _/ b( ]( F" I. S% o
4 B+ g* _8 c/ V 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)2 p: s2 F: R: K
4 p) K6 Y& x5 t6 y) _; q* Q% \* ---------可选项目----------------------
. E, f# c8 A7 M8 }7 R6 z6 g. ^5 k0 v4 O. g
}
: c0 k" \$ D3 L9 K% |9 u4 p) Fend) Y8 ~# M+ I- G" V
|
|