|
改了一下,这次运算应该没啥问题了
' ?/ R- y$ V) f" O- Y( H1 u( R- s5 q3 K/ \& k5 _
9 J0 p+ X# z5 p/ r- }1 gcapture program drop hello5 E& ~$ Y' U/ [- D: w, G5 R
- C! z7 z `4 u$ C% xprogram hello
& m2 \9 d1 `1 m" b2 I. s9 L
. _# }( f4 }" w0 z quietly {" U! H: a# Q1 m0 ?* S
: l5 L+ n6 j7 F; K, V( |
clear
1 q; s$ w, `9 ^2 h6 Q/ a+ @$ _( a$ S0 b6 A: U
cd e:\finance\stock\20110101\source
! o7 y7 _2 _/ F" v- v% e
C, k- Q3 {$ d0 _0 ?3 j' s5 dinsheet using `1'.txt' K% ]9 l& h5 O) {, w5 D( P
4 t- W. e, F( F9 [
keep if v5>06 M9 m0 G; m: v/ B
% v; ^/ J$ q7 ~( K3 g. \' d9 ` gen vt=_n
2 K) d5 V" {8 y( O
2 ~9 l [# @$ L @ tsset vt6 T3 ^( t, e Y
8 A( Y* E3 g0 f/ h5 S gen zf=D1.v56 U+ P8 k2 m- @+ u0 l- |
; F. m& M& R; i3 ] l" B gsort -v1
! L5 B. B/ U9 E Z4 T. B3 K8 T# ?* Z+ p) e* p
gen avol=v7/v59 e0 F2 G/ e' K7 U. Y
5 G- v* [1 x5 r+ F7 B
keep if avol>0
4 O5 s7 d/ Q9 m* {/ q) x; |8 p
& v8 n2 W, P; D6 [3 u1 W drop vt
, a& B( s8 g% i& k" k( G& _
0 m% Z3 @! E- v) Y& W gen vt=_n- a5 U5 c6 I% z8 p: D1 m" y
) j5 q0 K$ y0 f/ s* x
tsset vt
7 t& M7 M# i% ^2 W, t . n6 A& C9 m/ a0 C3 z( t8 H
sum v5 [aw =avol] {! S2 y" a. @0 n9 d; U% y
) e. d, D9 X/ P$ R. r gen amean=r(mean) in 1
2 q5 r2 A9 L# x! Q( X 2 F( a9 `; G2 V- i9 e* @9 ? w
* 总加权平均值 amean2 b# V2 P0 p0 H) y
: j+ V; |0 h& E) D& K3 A* w+ |& l1 g. k
+ ?+ p( [" y7 D keep in 1/240. e. }1 z6 T8 Q( i
% E. E) N7 a" i& K0 m: z: I; l- c9 P3 W
sum v5 [aw =avol]
% D2 W: M, Z; a$ v0 u* T3 C! A, F2 n/ W2 |
gen mean240=r(mean) in 1
( ^1 w( M$ i+ x* c- ?6 o$ H$ S9 d" Q
$ d+ a8 Z( a, x! K! E/ k% f9 T* C *240加权平均值 mean240! \( @: g; j( {
* q0 H+ L' T7 h5 u8 z7 R& u set obs 500 + ]# A# ]! A, v5 d2 h" h
}6 w6 f- B, i! v kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph' x! C' [8 R9 s \
/ j7 a' {% U/ w( u& x# ]4 a
*240 kdensity(dx240 dy240)
9 x) t$ W% \! V
- G: Y- E) S( A& P8 @' ^ sum dy240 w( {" i# W9 X% J3 T
+ m2 @0 n. ~# E8 c5 v! K2 M& p/ v
gen yxis=r(max) in 1* S: ?9 ]! Y8 j4 g8 J0 Z
% w7 R) l6 u) p/ M2 }- J! d gen yxis2=yxis/2
; `' z0 w* g5 d% F
6 S/ x0 V' H7 Z& Z, e. Z! M *yxis
% r# C: s' [$ r) x n9 S$ @5 [& G8 X
gen dy240max=r(max)5 P2 c" k, A9 ]% ~6 a* q
- ]$ @3 E% P# u9 x
gen dy240minp=r(min)
$ a) J. N2 v5 B 5 h3 f+ j+ A# Z* R0 Y, k' d
gen vtt=_n6 A9 Z9 c1 ?2 x+ I2 j: X" E) J
% |% j# G% F* C/ j( f; o
tsset vtt# H% q2 G% z3 ^ b# z% i
2 y7 D+ \( R; Z$ A/ X7 {
gen ddy240=D1.dy240/D1.dx240) Z4 F( ]/ q- X( |: H
d1 s, a, m: g9 ~- l$ l/ t6 I sum ddy240( z6 T" }/ u4 O# A# t) C/ O
! N0 ^2 D8 y* F9 `
gen ddy240max=r(max)
5 c% v- B: Q4 d, ?/ }
5 e- v. U E2 T/ D gen ddy240min=r(min)6 c, j! q/ k/ c* y
5 c: _7 }: W$ J/ E9 | gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
, E9 ?- A' V- ^' y
# O( V8 J5 A- R: H* u2 q sum ddy240g! f3 S- x* S/ H
* n+ @8 U4 N' O) z' O7 X gen yxis3=r(min) in 1/ i' D; N" b1 F& h) n/ E+ z
2 p1 ^4 k6 w$ o5 J; M gen yxis4=0 in 1) _5 w) p9 A' K9 y8 S* ] t; H
7 J# J& G6 {. Y3 n! U; G. `- T
*ddy240g 2 X$ R! o5 v1 p
6 s9 z2 V) S6 _) j% _ : ~1 g! U5 |6 @
preserve 8 S9 V- e0 }! W' c5 e" g, Q
/ B) x/ T! |% w; q. {7 M sum v5 [aw =avol]; V4 V2 x; y7 ^8 u4 j1 S; H* Z4 o
D* l; Y: u' ~; v" \/ _4 T! b
keep if dx240<r(mean)$ B* U6 b7 t2 @/ h
. s" W" @" K F1 X5 g
sum ddy240
" T8 C3 P |$ S/ k" h ! H6 I. U7 ?4 d
if r(min)<0 {4 T7 V. q D, M( v- F: u3 N/ T
% R0 _5 g" K" {* a: H: X9 c7 J
keep if ddy240<=0( g8 J+ L4 k8 h0 ^
% i+ M: X: s* Y' @. } count
4 F1 N4 O! b4 q/ K" S" h
: x2 }( I) r# d0 p8 S$ ? if r(N)>2 {& K- s( X; m2 w! t C
6 V ?' E, ~+ x8 [& y
pkexamine dx240 dy240% |/ U! I+ @1 \# @
) k* {* u1 L3 M, m; R$ s
local tempminp=r(tomc)
' z8 u5 s% L* v0 K9 P7 ], M restore $ w! ]2 `( p2 p+ Q
}
- r, x a/ R5 p) X. _& D 1 x( Y0 J7 G2 @6 S& }2 _' P" G7 J4 B
else {
& T; x) S* v* Z, N( N* b
1 x8 E+ R+ v% x4 I di "cannot find minp"& U' B; d' l$ H6 ~# y4 c
$ E, Y9 ?" v4 s y! b8 R
restore 8 j- n8 _3 [- c" u L. U' D
sum dx240! J$ d. H; B* Y. h. j; T" E
local tempminp=r(mean)* P3 L' b$ G7 e6 v
% Q6 z8 A5 q; C; y; A+ x
}3 }( `! j' ~5 V/ t% h3 m' n3 D
}
6 s! O4 r( Q2 D$ s) m# ^1 p! \ [ else {
/ P/ Q+ M Q" ~( V
1 i) |' a, {0 A3 B+ t; G7 ~ keep if ddy240<=r(min)
6 _' f" |/ @5 H 2 V- s, f% }+ [+ R" M. H- i
sum dx240
$ B" V }( a, S+ Q' h0 B3 n5 `! d% g
' b7 J7 ^2 j! k/ B* _2 g1 M local tempminp=r(min)
8 t2 J' R8 Q- V restore
; t/ P/ N8 {; I7 p9 ~2 ` }
1 K; t- R! M R+ w% `4 G8 C' i6 |) g+ ~- q$ b) I
8 Q+ k# r. h' R" [
" P Q0 I, h) s0 V1 _ gen minp=`tempminp' in 14 O; Q5 H% J2 E% V. P4 D& w2 a9 u
*240 minp; I# G' _* z6 ^5 a% b. }
" U# k. E+ x: K( v# M) ~5 W6 B- T+ A; g( \
/ @" h! \& M6 [& }- i6 V# H3 a preserve 4 r$ c2 j( }# ~' {. G
. K V$ _5 w1 M sum v5 [aw =avol]5 [, m+ O/ f W8 q
! L- @) F( \3 N) n
keep if dx240>r(mean)
3 u1 C6 ]/ D, C4 }- Z( Y9 ? + u* r# u5 P/ |3 u2 J( S& j
sum ddy240) J" Z3 W: L B1 T- [+ z; k
9 l7 l1 c D' n8 r6 m, W
if r(max)>0 {; V+ F. c j7 J; }) z
- Z* ~1 q) M7 T! H keep if ddy240>=0
: v7 y9 N6 p: m3 { / D6 v! z+ }; b) J! ]
count1 `+ c' u" `6 j9 T0 Y( |$ |
8 x; H! I/ f3 \2 q4 v6 }0 F7 k
if r(N)>2 {
! ~( g) k2 h% x3 u6 m5 v3 A ; L8 X* X; k9 t* x4 Y
pkexamine dx240 dy240
0 Q* s# x* n5 Q1 R" ] : X! k N3 k) ]5 |7 O& I
local tempmaxp=r(tomc)
! r1 a) E" b4 r restore
4 ?. W3 v& B6 {- t' _/ T1 N }+ |# x8 w8 A$ s+ j1 N9 R
6 k) u& v7 r" m
j/ N4 h7 C2 U( f# ~ v, u else {
; w- V0 B9 F5 q1 I1 Y. ? restore
/ c1 q) |1 e5 a7 F( J% U4 P0 o& H di "cannot find maxp"6 h: H" A, s. {1 R* L- t# T+ @2 b
7 ~4 u+ p" r" P$ H7 W$ T! Y 9 T& y: L5 r4 d1 v' j* F
sum dx240
1 t3 S6 Y; H6 `8 j local tempmaxp=r(mean)
* w0 p; C; v7 p }) p6 d6 u ; E: s- g: R: C X
}/ o, o& y7 I0 |. l4 P
( m; Y, Z6 u: h# c }
: O0 m$ X0 b5 ^* _* H + {( e1 x+ `! W' t, g* I! d8 b
else {* M8 x; w$ _, m3 `8 H: m% p1 z r
' x! E F7 B6 d: h
keep if ddy240>=r(max)
; Y$ Z. ~5 w) u# C1 ?/ {
: f% ^" ]6 d' v. h- | sum dx240
/ m& ?- ~2 ~: ~- \' e# c0 _: Y 4 f S; U! G; ~; ~* k$ F7 N
local tempmaxp=r(max)
: Z* u: q/ d3 W x7 F7 v restore
, ~. Z5 _6 Y5 {2 C0 \) z- y5 [ }2 e- {/ O5 P ?
7 r; b' |& F8 c5 c+ `0 Y) N0 J0 H% ~; c" U6 W
1 p) ] y, }! Q
& U3 L' b) f# U4 X4 }1 ~4 a gen maxp=`tempmaxp' in 1- n+ @9 }" U! t8 W
& k: E& v) Q+ ~/ k7 ^9 j/ G *240maxp- t/ Z- k- B# E2 e' S/ t
/ |- {2 X" k- y% e/ I U) V
- q7 I. Z9 s0 s% N4 g+ p2 J3 ~ *-------------ddy240pminp左侧高峰值-----
# t% x7 B' q0 V % _- C2 @7 A1 c, |8 U# k
preserve 3 r" B O' `, r) S% m
* ?: u. l, q. _% @" x" W T& M( H
keep if dx240<`tempminp' {+ ]6 l8 U6 P3 q- t% b2 w, z
6 |# N3 g, {" O- x; W
keep if ddy240>07 c# ?2 L9 |$ J6 H$ t
1 V8 O% V4 b% {# Y- a count) {5 a, S G, T- Q1 ^6 n T
8 i3 G2 U3 e0 k2 Q
if r(N)>2 {( P6 g+ j( L4 h( L2 }4 J; l
) b/ S' A( D& C" z- r# X1 M
pkexamine dx240 ddy240
; s& }' d/ F2 N$ F4 U$ p& N3 ^1 e. ]
. z/ W3 \( k, ^& f$ u4 l; w local tempminphddy240=r(tomc)
) e9 ?7 ^) e9 w J1 f restore4 |5 Y/ m) i0 Y3 k0 a2 a8 }$ ~2 j
}* i& m- i+ A N' f g
: c) l- o1 Y& |2 j8 y. l# `& O" L3 z else {2 {% h7 D. `) i% H& K
restore * K" G# ~0 F" p6 I0 ]8 q1 b
di "cannot find pminphddy240"
/ u( ^4 [6 [) E4 N( M* T. R: j* A
4 b( b( a% o( W. k8 [+ g" C + V- Z; {# z1 [" \# P% c& o7 X
sum dx240& O$ s5 { p% c# x$ J Y
local tempminphddy240=r(mean)
8 H9 c/ e5 _. }5 H3 p2 y) E
& L, U' A& S" n- R% Z . b! u0 E3 B/ y+ B, @
}/ T" Q8 S' t$ f
& `( h0 `; }! ~( C3 O: x
! M% S5 o) g: p* Z& B
$ J' j2 X4 W0 v5 s: l* X% I * }" n6 {- d+ H% V& o
( }6 K: r& J1 K. D/ M$ z
/ k5 S: W7 m3 L4 k3 X& |4 K5 W5 M gen pminphddy240=`tempminphddy240' in 1: {* _, V/ h- G* E
2 b7 ~" @! J1 X, n
; z' N3 G+ F8 {2 W) ^, x *-------------ddy240pminp右侧低峰值 -----------------( O8 x0 G Z G0 C3 k
preserve / d4 y- w `0 [5 P5 q3 a% b
# a/ D2 v( P" p1 e* S5 l8 E
keep if dx240>`tempminp'' V1 Q0 b$ r6 K+ A3 L
. }2 @3 g3 E; d: h R3 i+ b& t
keep if dx240<`tempmaxp'. J# H, L* Z% J* R
1 B9 \. P% h0 @0 M; J3 p
keep if ddy240<0
5 e0 ~0 Y0 \6 Q( D! c- Q & `' S1 e n% q$ H; l N
gen temddy240=-ddy240
& i8 H j4 t; p% }% y( z5 M4 A& Z
7 L# ^4 z8 C' t count% c$ v5 \2 a6 p0 j3 }
3 t: u$ p7 Q, a d- I0 M; H9 u
if r(N)>2 {/ z0 U: r1 w* B
- ^0 `" ?1 {, O. D& n pkexamine dx240 temddy2400 Q0 `; Y6 m, j' Q0 F( x% x. T
- l' ? b3 ]" r* f local tempminplddy240=r(tomc)
* r% Z7 V* V/ \: }2 T$ X2 m/ ` restore
6 @7 {$ X$ g' ^4 ?" A1 ? }
( v5 v, j& _( S5 i6 O4 d3 T' `8 W% P ' u9 s. ?, o7 H4 s. |' U- l
else {. _ L6 u0 S7 u$ C$ N7 A4 g; J1 x
0 n# A' G. t: j; \ i
di "cannot find pminplddy240"
5 D0 a: c, l1 i" O* @2 f% J$ q restore
+ l6 |6 p, t# D# I. o4 \ , S' u; \8 X. ~0 [ M! C3 f
sum dx240) f" x8 M) s: _; ~; L
local tempminplddy240=r(mean)
e5 ?6 M- X0 k7 V# o5 Q5 a9 s 6 i l7 Y) F$ V0 t& N
* |+ A( S) j2 d8 N; [* d% J1 |
}& k+ |7 R7 f2 I$ s
5 ~( w/ h. D% n- r 8 Z# q( g4 a8 A: _' s
1 u2 `5 J0 t6 O" Y L
4 }$ A" h' X4 ^2 a8 s6 C; ?
6 z( t8 d4 v7 C3 R3 j gen pminplddy240=`tempminplddy240' in 1# q: H/ B6 N/ |! G1 x% N
/ Q4 l) F" d) a/ g *-------------ddy240pmaxp左侧高峰值 -------------------3 {* \0 k. K- F3 Q
3 @6 L) X; _3 `4 ]/ T preserve
4 F) k# L7 y3 f# c2 L h
. C# h! r+ q- `, Q1 ] keep if dx240>`tempminp'; C2 Y# N/ p) T- i
* r$ O* d$ H. }( ]2 F
keep if dx240<`tempmaxp'7 K( k4 \1 D' Q4 U! b
- j+ H7 l" n$ k" {2 H keep if ddy240>09 c x+ V/ |6 h# b7 H+ X7 d3 d, Y
count6 I% e: m2 [6 f
6 b7 m1 \ ?1 e7 V
if r(N)>2 {
% S I" s6 Z7 v- f7 ^! B; k : W6 B* U2 v8 ~7 t$ r$ S
pkexamine dx240 ddy240' \0 ^% | l y! Y4 E8 ~
5 }4 S; }- j2 d( j. A9 j* U1 E local tempmaxphddy240=r(tomc) - u- b0 P5 r0 k$ L J, `; R
) w! y' Y+ O) _2 G' k1 L% A
restore0 E$ p5 B4 _9 E
}
: ~5 M6 Z h7 ~: D # f5 A: A- u& m! O, S8 l3 b/ f% G
else {! c' J) p9 i4 ?
5 L6 A3 v/ `* O: `: w# e5 a di "cannot find pmaxphddy240"
, O5 X- K( v& n; Y restore
& I& J8 t! g9 S3 }9 v9 o3 _
2 J k0 b' x! G sum dx240
1 a6 l1 g" k$ R/ a) L! E* G# ? local tempmaxphddy240=r(mean)
) t/ k# f$ H; @. o8 w+ k( Z ) y, ^* S5 b4 z- O# f6 y
' a* Z1 ]) k) f$ B& U- A. Q }/ Q& j3 m* V9 l& [! L" X
2 G: l/ H$ k9 a1 }6 m& V
/ L$ j M, J# k4 y
% b/ u9 ~" G( ~' \' V7 h$ k K ; l( _- A4 q+ f- J( V
2 m( q& u1 l; `+ } % y/ E9 ^! e6 m1 V4 Y
gen pmaxphddy240=`tempmaxphddy240' in 1, b [1 p* K8 k; v
0 }- l) B5 T/ W " e5 c- i) ^! ?6 `/ U
*-------------ddy240pmaxp右侧低峰值 -------------------4 }' b2 F Y- I: Z+ s
$ j6 I$ x+ O! q7 d7 T preserve
* N' I4 w3 ?! n
" x6 K" {$ ?/ W# l0 m keep if dx240>`tempmaxp') b3 S3 w/ f# g# F
# G. M/ g v4 t) \$ \( G
gen temddy240=-ddy240
4 J4 X. v+ _/ I; U& G( Y O% o) X' |4 T ! Y+ b0 B" q7 W( [. ~$ N' B
keep if temddy240>0
2 y. O* R% W6 y" ~: B1 R' t" | 4 U7 W) m; ^5 q
count
( M+ v6 w E/ g% I6 j& h " ? H/ h: K5 t' W( U$ {
if r(N)>2 {. }! I+ G: }9 U0 V& x5 q' Q U* N
4 ]2 e* q# ]- K' a pkexamine dx240 temddy240
% B! B& v7 i4 t7 h( \, j( s" ` $ V/ y4 r9 i3 N& W b* X
local tempmaxplddy240=r(tomc) 0 T2 p' C8 S6 X% A
restore# C+ ^4 S' ^2 w" a" ?
}
; y* j% v5 m, P
* p7 @: M: l4 e; T% n else {
* {2 M# F$ a, c- K restore
( b4 j3 }* k4 K: v& r di "cannot find pmaxlhddy240"
( y2 T# Q" {, A9 M5 ^# G 4 f" n$ |0 x7 ^* L
6 T ]5 x. P/ V3 F2 Q+ I sum dx240
* K0 a3 v( r, J local tempmaxplddy240=r(mean) in 1: P& @) y# L% _& ^$ q- R
+ ?, b; r8 e$ [ 6 o2 G" k0 y" L8 |
}
, c5 B+ j, n: q' H l$ n
0 b/ c0 t p# W _ 2 E# \" z) D3 Q
% L+ Q' v" k7 u3 ^, P' e' n5 k : r! x$ k- e ]
2 L" C# E6 B8 J! p3 O% \+ |% U @
- H' |; i4 Z) Z3 ^ gen pmaxplddy240=`tempmaxphddy240' in 1
1 W b) A& Z6 u) }% u; \, _1 r6 e ( I8 c$ |8 u3 [7 w3 q
*------------------------------------- Q; b# e S; ?6 ^8 K
5 p1 C- j# S6 I7 I/ L7 ?( e1 V gen price5d=v5 in 1/20
' \& |( Y# @$ F; }1 X9 y ' ]* }4 [- X9 V. l2 H
gen price5yy=_n in 1/20
. O2 X4 t" p( _' l, q& f , |: B3 V4 Q0 C# Z
gen price5y=price5yy*(dy240max-dy240min)/209 q4 A& |' x4 H: y7 ~+ U/ d
1 Z8 _, t4 K' C8 V3 K# m! _
*price5y &price5d# `) R" z9 ~ r3 |8 ^6 }( ]
0 s4 F& I% u* A
gen priceny=price5y in 1
6 d( `# K b2 S( h6 Z6 j/ p& j
4 ]1 G% J) X# ~" d$ { gen pricen=v5 in 1- V* r6 y9 X0 a/ L! q( S4 J
! ~# Q/ S7 X% h7 ?; `
4 H0 l1 n3 A# v2 E6 F9 j! n
*priceny &pricen- e6 i5 G" C: C+ B& a
+ E0 I' T* R6 |) f& q _4 C4 Q( }0 S
2 `- j. o6 i$ K9 V) F) j) `, Y *-------------------------graph------------------6 P; c* r0 Z6 G9 E) u4 W
1 Y" W( i( e' s6 _7 s0 ]( @8 |
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)
# F! R( |0 D3 O: q p, Y( N6 `0 _# J) N( X
* ---------可选项目----------------------$ l+ t* F N8 {
# v' S3 J4 F( y: ?6 M' ~& R; @
}: G8 k5 E$ k: Q( s2 |5 q' x
end
' n: l, W& R% H7 Z F( U# q# Q |
|