|
|
改了一下,这次运算应该没啥问题了
8 v. S, I# p+ l7 [+ f
* J* z8 l; ^6 e- K6 R' R: c5 Q1 }
% V' g; Y' s; Y" ?1 u: xcapture program drop hello0 R1 H- t, e5 D8 Q0 Q1 I$ r
J0 x" u/ y. W1 D: E) r; s/ Aprogram hello. ?/ h: e0 J5 r( D, U
2 H& _) h! b& }5 w/ m! v' j
quietly {
6 O% p9 m/ |9 E/ r2 L) J9 P4 K( T+ j! f8 I
clear) ~9 [/ I8 D- y$ e, _' X
$ T% I+ q( \4 j2 L& _1 j' Q
cd e:\finance\stock\20110101\source
! f% U5 d* A }. n9 W5 ]7 t- E2 H R
insheet using `1'.txt
" p% N8 D0 R, M: b/ ]
F" i% t0 [4 u5 F" i keep if v5>0
5 x$ [7 ^- D; C' a
$ J. K* x1 J9 |' J" p3 ]8 Y4 \ gen vt=_n$ j1 H+ z5 M; Q! ?
u/ y1 O6 R1 i G
tsset vt
# J9 G( F& Q5 h8 i. N9 M
' N7 X; T6 k& s) D& @ gen zf=D1.v5
5 J% O& o, I) |, k5 B& Y9 F3 L: J2 h9 {
gsort -v1 L" y+ h. Q1 n% r+ L
& Y1 P1 Z9 t" s1 i gen avol=v7/v5
5 y+ w) j5 ]% z + S8 x0 z( v8 |; I0 U9 K* N. `# z1 h
keep if avol>0: O9 L( S/ w7 B! D3 L" T2 S" l
4 u- R! v& M- V% |# p
drop vt
$ c4 _) X' v i7 f# H% F' [- c: p5 ^' W! b
# b: Y( ]: [0 w( |9 B gen vt=_n; R) T" K. B& B, B) Y! l
/ Q* s' E' G" d7 E0 h
tsset vt( u: g2 W9 ?* Y1 n' n# R" r
& X' z! c' ?6 b( W$ L
sum v5 [aw =avol]& R1 V, \6 p3 u8 e
8 o! A" O: V7 s; ?% {7 ~2 T gen amean=r(mean) in 1
& k1 L4 O$ g2 J 3 N" [3 T7 S z: R
* 总加权平均值 amean" B4 |0 W- F2 k
% }0 q7 r G; b1 D' U9 s- L
1 l* A* S) p2 P& F) u1 o. W
keep in 1/240
n: U) {* ]; E. c" Q! Y% F
6 R% O0 i6 B: @; J' M8 @ sum v5 [aw =avol]
# o% m( J/ o/ i7 U5 G# J$ n! ~% F1 S; n+ D5 a! Q# d
gen mean240=r(mean) in 1
3 v9 ~1 B3 b& b( v) u3 Y; m3 a 6 }2 @3 g8 L8 e
*240加权平均值 mean2405 v( g+ R. F7 k; S
0 j: }, S) m/ t* f! N2 G
set obs 500
% Z! l0 \3 [" C
/ @+ L2 ? O2 F! q# C6 Q8 \0 b kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
0 J$ G7 B# K/ P7 t
1 P" G+ e X/ x! _ *240 kdensity(dx240 dy240)/ L, K3 S9 V! q* o
, c7 o% G: i, L$ z* c
sum dy240) M+ N- @2 x, j/ w
I5 O6 J1 ]4 t/ X gen yxis=r(max) in 1. G2 S6 ?: W- Z# c% a
$ @' A/ p* B8 Q& x) O! K, ^ gen yxis2=yxis/24 l+ e; x. E5 o4 H3 S8 l% Y8 b: E
# a- B$ x5 x' L$ T7 h" R6 z% m *yxis: J7 ?$ f% W9 f3 O8 C: |
4 H9 F2 S J% H
gen dy240max=r(max)3 D8 D( J% E( P' X9 K
. L' [; ]" r/ x gen dy240minp=r(min)9 q- w) |" P. B( W: L
: ]* A5 t2 U9 U' y; j7 w5 i2 W r
gen vtt=_n* K% k8 U! W/ p9 Q$ E3 c
( j: |; I B5 Z, \! a tsset vtt
0 w! g& N% K5 P3 c$ H3 t1 V$ `0 _# `. P$ C6 ]/ {. N' Z
gen ddy240=D1.dy240/D1.dx2408 _$ P! z1 U6 ^# O& k2 Y! \7 Z
- J; i& I; Z( n+ a8 E/ ] sum ddy2400 j% R- ~( n( z) `- b& r
$ c3 G# _8 d* p0 Q. }" m gen ddy240max=r(max)
% Q3 O2 }; c% V+ \7 {! e F
' ~& _# e/ u* ?8 _ gen ddy240min=r(min): H- q- M2 Q: H( T% B/ D
8 e& k! h1 u1 D+ P4 U, B5 y y
gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
A6 ^/ `& Y) e" Y3 c ' Z4 m/ g0 O* g, Z
sum ddy240g$ f3 ]2 y$ S) y- y$ C
% D! T) K8 ~" S N! _# L+ n
gen yxis3=r(min) in 1
9 q# u( K+ j$ E5 u; ]. |( u2 d7 d3 Q
7 o! X! L( b2 K* a/ X# E l! U gen yxis4=0 in 1
/ [$ x! I/ \" G2 e+ W0 [4 {! @
4 L( H" n: j9 |" t c. { *ddy240g
$ I m$ e9 ?8 [2 C1 L* e
b* W9 R! w: k! P . \9 Z5 Q, N6 N
preserve
8 v9 ^# s* W) z# w : i& q, A) A8 ^
sum v5 [aw =avol]
( j! B/ S$ e) B4 k9 | 5 K; j7 W0 y8 a/ {" Y- u" n; g! c w
keep if dx240<r(mean), Z5 F/ m' e2 f9 u1 m! S( |' L% G
5 E# K( u1 O3 s& i
sum ddy2406 Z: N0 a; D0 K5 m
6 B9 c' b& i" H" ? if r(min)<0 {
0 p A* O# A1 ]. B. K( q/ i 1 _5 |* O1 J" d9 ` }# ]! D1 g- J. }8 U; ?
keep if ddy240<=08 S4 g) [$ y. C- O
8 c/ m6 v+ r) |+ s/ k) m9 [
count
- X/ y. i* ~* h3 S+ Q1 t : A( p2 b8 i7 r# |
if r(N)>2 {. {; k4 D8 {0 z- O! v9 P6 W! a
/ a( f$ t0 v9 h! l pkexamine dx240 dy240
# x+ W% [! |/ e7 V! H2 I + ~9 z$ B, ?$ {7 y: q0 d5 u3 W
local tempminp=r(tomc)* e4 n% |8 n0 q. }2 V
restore " }9 |5 ]1 H/ _. |2 k. k5 o
}3 ]- Y3 U5 c/ h' W2 c3 o. w
9 y! I& |# S5 A: I
else {$ x4 R' t0 n3 F! a T$ {; r/ q6 j$ C
' t0 T9 r) i- d: z! _9 p4 G
di "cannot find minp"
" H) ]; u8 s$ Q
7 R9 A1 `: m/ G# X1 d* l4 t restore
6 ^/ ~. R+ c7 {$ Z sum dx240
G; F4 [/ U5 L* c( M% w local tempminp=r(mean)
H: y# |& \" b: N( [' s
& q. |; Q, s6 H2 e+ a# ? }
, \) i( U2 W, r4 Y }" z/ V _% ?, [" f* z4 y) S
else {+ Z+ x% Q$ u. q$ h6 _' Q3 _/ q
" s# q) n A; `1 [% e- y0 h0 ^0 Q' e keep if ddy240<=r(min)
6 G# n' W6 Q2 s) @ ! F4 L5 }9 k, s# ?7 Q. {
sum dx2402 n4 b; M3 o/ r! H1 p' U
7 C8 c, ?3 Z. i1 P$ ]
local tempminp=r(min)7 |0 U' Y- K5 v1 ^! P5 P; Y. e
restore
; M- y& T% o1 {9 y }/ n/ i7 s" ~# c3 w6 g4 b g' L
9 h: X# R6 P/ q0 I \ R5 I- a
$ b2 ~. \, s, I4 I6 t! ]% Q, y/ o& ]2 v2 |
gen minp=`tempminp' in 1( D8 h- q% ]" ?, @) u! C( f
*240 minp9 v: Y6 y& Z" H% T2 S! p! ?
! a! ^( w& g1 b
; E. O# v$ m' V 9 a0 J7 x: B! _" S
preserve
2 t) p4 o4 m0 `9 N" H7 j $ @4 @9 x1 Y. o
sum v5 [aw =avol]' Z. }* T& [8 U+ N8 U
$ H! S, i" @" R0 ]. d9 T keep if dx240>r(mean)
% V- `- R( U" x . q/ C3 a) R) ?0 I- h; p) @/ Y
sum ddy240
4 P& g+ E$ i& M% i 3 P- d* `* W8 Y7 @& }; {( L& Z- r( n
if r(max)>0 {
$ `& W% A1 s+ _: o- S# T, Y$ g0 q 9 T$ R O& h' S' p/ F
keep if ddy240>=0& H$ v' p) g2 f+ [! Y- }
8 x: g& y" `1 t2 U- {; ]
count2 e; |' b: ^# J( I# y
* o: ~5 L$ H: M# ~' f. ]
if r(N)>2 {
; U* d' ` R& D
( I1 x- o2 t: q pkexamine dx240 dy240( f6 ]. l p% g; I0 }9 `+ K# g3 g
- `& @$ B6 F6 o0 E* P local tempmaxp=r(tomc) # N6 s5 b9 ?, Y( L
restore : u! \' o% U) W% m# N. R) s. R% c1 Q
}$ f9 h) N+ B- h3 x8 Z7 E% h" |
5 h3 k) }) S% w- f( c/ B
5 y4 h; L& \ `$ ^( s
else {
- Z! q* ` Z6 | Z8 h9 d, \ restore 8 h4 L+ j: Q' P2 j
di "cannot find maxp". x: L1 L9 K$ @5 x) K) s" c* [
; V8 u$ w* U6 g4 w4 ]2 r% U
! c) L/ ~$ u6 {; N
sum dx2400 g B; s8 ]1 Z) D9 [$ W8 l6 K' E
local tempmaxp=r(mean)- [9 ~% U6 ?" y! k& r k
0 F# W6 I" E% W/ F6 N/ S( s+ p( I& z }
* S" P2 E$ l" N2 O5 @( C # s W' f$ c# T% E: ~6 D3 J
}: F1 D6 H, T) @% ]( ]0 f( K, x
. z' D" G- j6 ~& {
else {! \" q- M' F3 a
( N# W5 g! ]* O. W) q" Z
keep if ddy240>=r(max)$ S3 i7 A7 U: {/ z: C& w$ i
7 L: q6 d% j5 X' r4 {, k
sum dx2402 z0 |4 S4 ^! g: g8 S5 U% l0 L
; p0 K# E$ S+ I" H3 K+ Y! ~ local tempmaxp=r(max) - ] U$ t0 P. `$ M1 ?. l6 V2 }
restore $ [ X! L; z9 W' M7 l( @, k, C( X/ \
}6 z9 _* s' K( s5 i( r
/ v: z. k+ C+ v! g+ f$ V
& s5 r2 Q. u4 g% G6 Z: r, K3 q0 o% l( B 0 b* \6 f7 {5 J$ C: c7 |+ K
& Q# a7 q' I U; c% E4 ]
gen maxp=`tempmaxp' in 1& ~3 I/ B- j* r$ n. O9 f# v' N
, U$ ]4 x) J7 w. ~ *240maxp
) H+ W+ z: I8 ?/ m 2 v( i, N7 M' {% b
( A, W" O: K5 f& T+ l- q
*-------------ddy240pminp左侧高峰值-----# n5 P9 j- z! U
% B3 B; A/ l! E5 T. k
preserve ' E7 e+ ^& x5 H
( E1 E- y% A" x2 I. e# Q7 m, g
keep if dx240<`tempminp'# }, g8 d: t) O' ~. v6 K
/ y' ~% y( x l! f$ Z
keep if ddy240>0
" y9 @4 f5 \/ t' i3 |" ^ $ z! O; j8 s O. t) ^
count9 `" ]5 Y" |3 O! V+ n0 z
: L( R+ E' c' D' h
if r(N)>2 { J6 `$ w; M& i2 g
) c; W/ g7 z; U+ E) O' F
pkexamine dx240 ddy240
# _# v# r/ l/ k( |- } 1 x1 {1 ]$ {1 ^) P, p' G, y
local tempminphddy240=r(tomc) 0 |' H) n- W9 x( X+ s& e. b% z, a
restore
9 |( U' L; J2 J2 _7 v3 h' v }& c/ S; L- ^. Y6 L9 N
; H6 R7 h4 u( u W else {$ I. x( J. F* A3 G% P4 A: j
restore
# W0 y0 v( e. K, y1 P0 P di "cannot find pminphddy240"
8 g1 y+ T1 @* b6 T% i ( |7 |6 ], }4 I- ^) b
8 m5 s) r. O |' x; R sum dx240
2 ^# h9 V/ ^# ^ local tempminphddy240=r(mean) * f( A: A0 W, J) g8 C; s9 a
' `2 i( R) z) r+ ]1 t, }+ K
) G% G% T+ [' w& c h }% J c: ]" ?7 D: Y M+ u
9 B2 Z# q( D3 N3 B& I
) _0 W2 H* x A+ N( ? / d' S6 N5 C( W6 A, N' Z# `
+ S& [' {$ {; \5 ~7 Y( L. m; ]
2 F7 L# [* k$ t2 D- G
) {* t- T8 X' |: k" q gen pminphddy240=`tempminphddy240' in 1$ r* E. X2 j! ]. s
* t/ X( s- u* b9 Q/ \& f. S
9 u7 Z" Q9 e: L v/ q
*-------------ddy240pminp右侧低峰值 -----------------
7 z# y0 ]( d! t" A preserve
3 j4 [% M# ^; E- {: `
" f0 a7 t6 R; s# i" ^: x keep if dx240>`tempminp'
) U/ `* j2 T: D m% D ) o+ h9 H5 b+ w$ R/ S
keep if dx240<`tempmaxp'
' n( u( j( L! x5 @$ a
1 B' g! Y! G3 l0 C( N2 p keep if ddy240<0' J; M& w5 V5 K* l3 f6 i8 j( J
+ }$ y0 u1 ^% h2 [
gen temddy240=-ddy2407 x) J& l/ o/ z0 L4 m7 \- J8 u
( B6 U3 ^; E* U! q. V, w2 r
count/ }; z% _- Y$ D3 ?5 K
( r% Z; ~' W2 T
if r(N)>2 {0 b, q- u7 d: j2 p2 |) y4 l
; c# w: x: n5 C% N9 B6 v
pkexamine dx240 temddy240
0 q, w: C2 I7 ^& | G f" K . S( l# r) `( N; ?! X* l; g
local tempminplddy240=r(tomc)
6 H/ q# h2 `2 h, V7 s: P: J restore
" b# C' P/ t* s }6 |1 `* y4 B* V* T- W S2 [
3 v; I1 P$ @. m3 e0 M3 u# v else {
; F1 k& [( W$ W0 s7 P
1 z2 {7 z) T' C7 r3 k' x di "cannot find pminplddy240"
6 v! J/ A! s F4 m: T restore
5 q9 w) [ V _3 {6 p : i" R# O& ?" y1 Z6 E
sum dx240, u& c: q9 ?& {
local tempminplddy240=r(mean)
/ m' r7 n: k% f. {4 c; ~ 9 q0 J$ J. m6 Q r' V4 O1 g
. q# ~6 x$ g( f& r }7 ~4 z* l" E% [
& E. N2 ?) A/ W l# c' Z- A
8 ?. Q; q3 J! p' e5 J. r7 J
' }5 m2 w" N+ J$ c% A+ ?$ D & }' b' d( V" j/ Y' M
, _! y+ G. L9 p+ v+ V" `; A4 c gen pminplddy240=`tempminplddy240' in 12 a2 M# U7 `( p/ \9 ?
; d/ Q( B) y0 b9 Q( E) ~4 W
*-------------ddy240pmaxp左侧高峰值 -------------------$ I* R' n' e) j7 U3 |3 v. T# C
- M/ X9 \1 }4 J* J/ x preserve
3 h1 |3 b3 Y; a. W: p& h ' H1 x4 j" y0 ]# T8 ]9 r/ K* g
keep if dx240>`tempminp'4 e" L- r6 n( j5 m0 p, _' _8 C
2 D8 ~% k+ `3 z! L0 f5 l& ~ keep if dx240<`tempmaxp'& K& o$ i8 X: Q: Z
# ~7 i C( j0 n, c6 L6 I keep if ddy240>0+ ~3 S, q) `+ f2 j2 m; H
count m. a w" C1 c
, C& }2 D, S2 M
if r(N)>2 {* R# V; z: f$ {) a( x& m
. \" b0 M2 L) n* u
pkexamine dx240 ddy240
0 E4 l: R' d! i5 b- H- l* q* L, a " o3 y6 X" A0 t/ e8 w6 E& x: E
local tempmaxphddy240=r(tomc)
( N+ W3 c: E! F5 b2 l
# \: t# j) m- D. {5 b restore* [2 }4 \. S# O* q+ f
}# d% Z- Z: n/ |; P; f/ K+ _1 d
9 C; L0 R/ a' b p$ T
else {9 E; B- I& I3 w5 g; D% d
6 z" c, L* v/ @5 c7 ^4 ?5 O di "cannot find pmaxphddy240"
1 W% i/ r) G" G6 N9 p1 b0 k- Q restore
0 n6 ?, W; x! `" l5 V& F" F 1 M/ ^4 C7 A( X" Z
sum dx240 U. Q1 j* I O
local tempmaxphddy240=r(mean)
* K# I5 y, o6 f % O9 k$ r8 k) S( P1 I
& L( O; @$ E/ g
}! i1 F- U2 d3 {) n! O+ S
9 E6 K( B- q( c3 b
- u0 p; [9 O3 Y. m& D' m
$ X( P: m: _, _ z: k
2 m, g9 Y% l, ^0 A! x) l# M
; k i4 ?0 R& y0 b- F
# n8 R0 w: Q4 O gen pmaxphddy240=`tempmaxphddy240' in 1
* N1 F5 U6 C/ V2 d9 X) S 4 |+ ^7 U4 R+ C8 Y! D" O
) W0 ?. y4 A1 `8 ] *-------------ddy240pmaxp右侧低峰值 -------------------: X( P% t. A3 D7 n4 _# _
9 p4 `* n m! h; N( E: H+ U* u
preserve 2 w8 l7 v+ z0 _, S
3 S V: N( H# _+ u8 f" o4 C keep if dx240>`tempmaxp'% w' d* b Y7 u$ F# `
" \* i8 g+ Z4 Y' [
gen temddy240=-ddy2403 Q3 E; ^$ ~2 x% D- L
9 N9 `2 }) y1 X6 X# m keep if temddy240>0: _: [' p7 H- X& i3 O
; h- w) G$ H& g" n7 e count$ \2 M* Q: ~7 M" k; U3 r' ?
3 E( I/ Q+ v5 |8 V# c6 u1 c& ^
if r(N)>2 {
* g3 @# q! }; C W
8 {5 k, _/ H1 i3 I pkexamine dx240 temddy240* [ I! ~- S( ?
* o. `* u1 g% t local tempmaxplddy240=r(tomc)
; \( u* b4 }- N: x$ C5 e restore- u, B# I# M' W" x6 i! @
}; d6 [' B' } C7 o* v+ F0 u! U
5 o3 \* [4 w0 v4 { A2 _4 L) G* T ~
else {
0 l: s9 D: d: d/ | restore
. {9 v, g" L( Z" A4 {' O" w( \ di "cannot find pmaxlhddy240"
4 C8 M5 C& m; V% M 1 ~( U( O2 q ^
. j8 w* [' R3 X! u/ q+ ? sum dx2408 I6 s8 h% M: b# G7 J' J8 l
local tempmaxplddy240=r(mean) in 19 y0 ?0 h& i# [
, P4 v) F4 C O8 h2 p/ e& y x7 ?% P; _5 @& R
}
: T* y( U; e4 n1 w6 p& T4 c+ [3 V : y5 W+ `* n8 @1 ]$ ^+ P A
+ {: d9 C/ ]$ ~
! Q/ L* Z; k; m) m: h
: d! _9 R2 W8 H : W: ]. d& W4 ?+ ~ A
) \; z; j; Y( g! v8 T8 d
gen pmaxplddy240=`tempmaxphddy240' in 1
' \1 a6 u: w1 w3 Z A i
! I1 @* U6 N4 L$ z2 z8 [- @% D *-------------------------------------6 D5 u* V4 Z2 s! s6 j4 R" _$ [
% F# E; s% O9 `( o/ | gen price5d=v5 in 1/200 ]/ ~! q; J4 f
$ M6 `/ X3 {) i0 \5 t( d7 J* U gen price5yy=_n in 1/20
8 u. E# {. p5 t
0 ]# l: N0 a7 T1 e% u5 Y gen price5y=price5yy*(dy240max-dy240min)/20( z4 I; |% N" `% T8 r7 C: F
5 M3 ^: _. e& ~ *price5y &price5d
5 V% T; a/ I1 K" r0 j9 Y$ w ( b: Z& y$ ]3 Y2 f# J. U
gen priceny=price5y in 1
2 l# n2 U8 k7 I/ I* I
3 b1 q% \/ z, `3 Y gen pricen=v5 in 1
3 h2 J5 V+ p; r" m6 J6 Q, h: ~
9 H# ~, c' |8 b( s
: g9 G$ c1 a- F; I" c0 @" m *priceny &pricen% t3 h3 B! B( g* Z* S8 l' c) B
. A$ K: F) K9 N. u& [ 2 r2 V) N/ \5 u9 O- |3 ?
*-------------------------graph------------------# i( y. F' R/ p3 V# k( k
) O3 F- N5 ^5 ]2 y) u9 } 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)9 Q( w! P7 N! }9 a+ E
( M- ~2 H e- f: Q2 v/ M
* ---------可选项目----------------------0 n5 v6 D j; y e n
" R% Z, S$ u# Z: ?+ @
}( c; g6 x8 t/ I. ?6 |+ I
end
$ a6 ^9 t: D; q# n; ` |
|