|
改了一下,这次运算应该没啥问题了
, g# A8 N: z: k( }1 N
' I8 h; ~8 `% L2 L! T+ \" b/ ~9 ?2 f# t
# p$ L" M- t5 |$ Q8 Xcapture program drop hello
8 v5 [3 s, [6 H& D. z
/ C; K* o( m: E8 A( Z9 b# L: {- |program hello
: b+ B" @) h2 C# x/ G, n" c- J/ B! K' m$ f, \, b# Q. q9 p+ {: o! a
quietly {
: {9 k, K, p, U$ p* I8 |. t6 u& f3 |& i0 f: @. M$ x
clear( I! F6 `$ \4 l- @
- X% Q4 A) [3 h2 N" k
cd e:\finance\stock\20110101\source
! q5 i( g& }5 c1 J1 I/ v5 E* o
' n( o7 y. q/ E( Ginsheet using `1'.txt% U- n: D* U+ q
8 b) R* [* l7 m) }+ Y7 h9 I1 I keep if v5>0% x4 c6 ~' t$ [. F3 _3 g4 r; }& O
( s2 \+ r7 ^' e
gen vt=_n9 d, m* Q1 c9 Q# l" W+ h$ N. Y
, X# ^+ Z1 x* D, I
tsset vt
2 b( q0 Q3 j& w7 b5 U: [+ E+ s4 m' A, {0 J3 h; L+ z# y* a( ~
gen zf=D1.v5' C( {/ s, C& s' l( d* ]2 T
% g1 G U0 u( _' y4 F! W
gsort -v1
7 a+ ?0 u6 m: T" x. n# B& U9 u5 t# |" ?1 a
gen avol=v7/v5
8 L! L# D) a% C: X% W) A% j , O1 K0 }( W# I3 I" G, |- V E
keep if avol>0
1 ]4 W1 W2 |# K% Y& X" P6 X ' a& F, h5 j! x
drop vt5 r, i% x" ]) u' g( Q7 N
- e3 H" K% _/ E0 ?$ d' V gen vt=_n
* |! `- n# _( M; r. W9 j; ~) s, B + V- a+ J K2 u+ {% `
tsset vt( M3 Q/ ?5 Q$ k$ X# q- H7 g
* A; i1 K( x( i sum v5 [aw =avol]
& F) X! Q5 F6 X8 O# i4 ~) s
, M g& A$ K1 ]5 ]+ {! G: q gen amean=r(mean) in 1
- ~! T' k* a% d" N
1 @3 f' S1 E4 ~7 G9 c3 W- F5 W* J$ ? * 总加权平均值 amean
+ A4 x! H! i" m& r3 i2 t% q 0 M" B# a4 r- ]; j* P( J$ w- H
5 V% f9 i& h Q; Q* f6 F
keep in 1/240
$ |" X, P8 V9 B$ ?& ]3 H5 y. Z: e" M" b. l2 L6 [
sum v5 [aw =avol]
; g+ }6 v8 F0 N5 I' R4 P. `: T- |5 C5 P
gen mean240=r(mean) in 1
7 B4 I* t2 ~" v9 ?# N6 L O: b4 |& M / u: N- M0 `. G0 P( I* A' ?
*240加权平均值 mean240
1 ]: q& j5 L$ e7 _' |' [4 \! ^
7 H. d1 d& O, y# w set obs 500
1 b+ i1 @$ Y+ w' M& v k& ]) A- A6 D$ E: D, [& P
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
0 o- ~/ ^7 l$ |
& e3 I4 N5 z" C C" S# \ *240 kdensity(dx240 dy240)
+ k0 t* q6 c# a" g( D j+ j 7 _1 _. a1 k+ t9 M& c, }* j
sum dy240( `" K/ g+ ~/ Q& y- K# p# b n
9 W: h* _) b' S8 ^4 ] gen yxis=r(max) in 1
- W0 c5 n/ M4 i/ _. \ }
% g2 e! {" ~8 { gen yxis2=yxis/2
( h* j c: h6 s
8 D! r3 J) S8 @$ C& n *yxis
5 |+ w W& z+ d# g) m0 v! f
V$ y d' R/ b @( T gen dy240max=r(max)
7 {9 Q$ u, H" Q$ o 0 R/ Y" z- ?' ^7 E/ k- c) p
gen dy240minp=r(min)" Z' y. x- c' Q. o' C
4 _6 U& J" o- ~! W1 K6 L; T
gen vtt=_n' K% A8 B$ i, W5 a$ K) z) i
$ O. V. u9 n; ~: h( s+ B tsset vtt. B) w9 f, H8 i+ ^# S
/ z' N, ?8 B2 ]- c9 f+ m4 Q# y
gen ddy240=D1.dy240/D1.dx2406 p+ @. S- K e
9 Q4 d2 ~8 w# e* w$ Z& f
sum ddy240
1 J$ A/ H0 ~6 R6 M8 k 3 c. D3 z& [2 i- `# Q Y
gen ddy240max=r(max)
0 P0 ?% j* }# b+ p) Z ! ?% S& u | k7 t
gen ddy240min=r(min)( q) t" q, L* z* Y, A+ L, {
; f7 A% S* i9 O0 c T9 |% L gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
% B* k2 G$ r4 U3 e& K- B . q4 L% Q. }8 L: P+ r D- V8 w
sum ddy240g: Y |$ m: }) t2 {, E
! D3 g0 D5 y$ _& T6 s
gen yxis3=r(min) in 1
! O1 \$ x" V- o0 F; H7 v6 P7 }/ v C- r 8 C1 [0 ]. [: ?/ C7 ]% s6 j1 [
gen yxis4=0 in 1
* t H. m, ?4 ?" r: Z2 Z% R* E " q9 o# a# F) r) a: O: `& S; [$ x3 w& X
*ddy240g
- T' i6 O' X! A8 T R
. L( K' W! W. I' |6 T; b
% F0 o) l K3 l( W, H+ e preserve : f) i1 E/ p5 W; s2 {5 O. v) a
) B; e ~% X# Q7 U sum v5 [aw =avol]7 U" |9 ^# R/ ~5 t
z" G. L8 P1 J; f keep if dx240<r(mean)
8 J$ I: {. k9 U' q( |5 S& @ 3 \% o, o8 }/ P: g* V& R
sum ddy2402 ?) t1 T# q0 X3 h, D: I d
8 ]- [ ~& V5 o2 x$ ~
if r(min)<0 {
8 B+ |0 M2 I' Z$ k" u
& i6 s1 C9 U, H0 ? keep if ddy240<=0
6 `( T( e: V3 c/ l: p2 J* [
( Z: d) R ?2 J2 l count% B3 B {7 Q6 T8 h5 e1 `
9 Q1 d: m, j, C1 D7 t9 t1 k; v! ~! B
if r(N)>2 {
* k( |+ G& j# ?% c9 ?3 |
8 @* J8 T( X- q, J& E# I. u! Z pkexamine dx240 dy240
/ a0 V' A" l& M5 v# z7 U# a
1 U& h' ^, l, I# ^ local tempminp=r(tomc)
8 K& |" J3 |& k& Y6 n restore 0 u$ L- i2 U3 E$ z
}
# G: ~% h+ u8 p1 h. c. I" y
" {6 U# c1 Q- @ else {0 t! |& U0 a, h! R0 N( Q
7 W, k6 W) q: A Y9 a( B: W: h& ~ di "cannot find minp"+ D# v |- F( d7 R: r1 I; j( J
$ O& J' c6 j: Z& D7 ~. [, [
restore
, M" T j) f. r" T sum dx240* [: f0 h. k) k8 C) | T1 m/ _; L
local tempminp=r(mean)7 \9 u/ y$ q8 m" I6 D
* o9 t: D2 z. p$ ]5 I# }
}
+ t/ T+ d4 X' O" a1 E: S' a4 d }
3 q$ q! e/ ~+ b) Y P L else {
( |1 g5 L8 L" k2 X; n/ E * u7 w. y4 Q) ^9 A+ i" _
keep if ddy240<=r(min) E! x1 \( M+ e3 J6 h$ T
( y. V- V2 j0 f* b# Q4 y* T sum dx240' T0 ?: a- ~/ ]8 n8 c1 M' z" ~
% J- z& T! w/ T D8 M- P
local tempminp=r(min)
q* J3 l9 Y5 S$ {. D6 |* q restore % }6 g/ u# P7 N5 T& h! C
}( C2 p9 o/ E7 c8 |
. i% n# n7 w- `' n
4 ^5 w7 m2 n# j+ J" f1 A- }' E" f3 |- \3 n- _
gen minp=`tempminp' in 1
+ c/ B! _3 s& C& `3 i9 r% ~" S *240 minp
2 ^; W' |1 L9 Z6 L" n
+ O2 M" _& x# ~2 q, {: k0 }1 k+ `- h* y5 h4 L
( u9 a" I) G- H" t1 C; ^7 p preserve
t& J1 N# P A& H9 m( A5 S 3 U6 {5 r" }) x! ^) Q# T7 p
sum v5 [aw =avol]
' N1 Q4 L! v0 d. V' o
% R2 d4 [ Y9 ?8 Y" i/ B/ p keep if dx240>r(mean)/ C: J+ J3 o1 o: {$ N/ Z: `4 N) d
l/ n, o5 G3 p' Q p4 _ sum ddy240
' ]) |# q. i/ F# _/ n5 l 0 M: {& q, r5 H, D, j8 q" i
if r(max)>0 {6 R7 L: @5 \# o+ u
4 i/ z, g. ~; w, Q R
keep if ddy240>=00 U- q6 d- r+ V9 a% t
, K3 e0 G" g% E8 d
count# H& r; g) f" L7 F" B/ D
; g& h# g- a! f8 B7 N$ C if r(N)>2 { N- Z2 D; |/ U0 M8 f* A; Z1 h/ v
, D" ?' |3 T+ \ P/ N( I pkexamine dx240 dy240
2 I* z! \+ P+ [$ ]( ]. @/ @ * n; U4 p8 `; R8 J) O
local tempmaxp=r(tomc)
- c! i$ b& `, b7 F4 @1 P restore
/ _2 F# o* r5 A) J }$ |' {1 [6 W+ j+ l# d
, Y! Y6 X8 H3 V8 T1 I. w
8 p7 u8 z# L! r8 a) F6 ^( B: s, w$ h else {6 b) x7 x/ n- J$ m, v' C, O
restore
+ \& S0 d5 |" m4 X di "cannot find maxp"
1 T! ^1 Y) @ R3 s4 ~
: t1 |% j" J& Y5 g
: X. i3 N4 }# X0 `: C: c" _; I" u sum dx240
; Z0 ^( w: y$ s local tempmaxp=r(mean)! t; _2 S* q, j& D) l9 |; @4 K
, A5 Q, C+ G# c7 D" P }* S% N. G2 w. B' v6 N2 ]/ K. Y
. g# F4 Y1 W! }; v) q
}7 ]# J6 k I* `1 h, n1 V. w
% g3 I8 u3 @/ H9 i5 W5 e+ r else {
6 D& U; g! O& B5 E" ^ ! q- K$ y3 G* D& |$ h! v. n( Q0 I
keep if ddy240>=r(max)
: Q4 m+ M& J: x* z. p$ S2 G4 Z2 u
+ p0 P0 ~; _0 t3 H5 {5 k sum dx240
$ R1 E T9 c A, f
2 P$ N, J' c4 [7 N( B9 g local tempmaxp=r(max) 4 d4 w+ `4 ]! n, a, m* X
restore
* A5 |$ M A5 B' k2 L0 y }% J1 a1 }5 Z$ l4 n, x3 i. p( t
c9 d8 S1 H" a( w2 f- Q
4 e( _1 T. l9 n* k; e8 {5 \( x a* H9 g: {8 D8 k6 [
4 J& W/ v* q! S3 |" g5 T0 Q
gen maxp=`tempmaxp' in 1( H. H# |9 Y- x4 c5 _4 `
4 }2 J' v+ A3 ?8 l( U
*240maxp' L+ R0 c. i) x6 o1 K
+ k$ E. J8 ?; O) O
* d0 _- }$ K9 r% O- ]- w" f *-------------ddy240pminp左侧高峰值-----
' N( q+ @8 {3 d+ ~' Z3 \, ~
" \- Z, a) B: J# ~$ _% } preserve 8 m* ]. d' S. c" M- Z/ N2 M
! y/ e! g3 |3 R, [6 K keep if dx240<`tempminp'
0 z7 ~# m. I% _4 b7 O* b- } 6 _4 v0 s8 e6 B$ ^/ X- L) H7 Y
keep if ddy240>0
2 O5 ~. F+ _, L4 H( R5 a 3 h! ^' g2 t0 p* {. t1 F( V
count
1 s! P% x0 F5 _0 y3 _/ z ' k% z R& y- n( u q; N$ N
if r(N)>2 {
: D+ w- f5 ^; s, ~1 ` 3 @2 A" j( L$ o- g w) P
pkexamine dx240 ddy2405 _1 ]' }: t& B
" d3 n3 ]6 V. S8 m local tempminphddy240=r(tomc) ; {" c# Q& z1 E/ Y
restore3 {' D2 T8 B7 u0 l& f2 J
}' m9 j8 W+ U& w& x$ J, A
/ Y- J; w. u/ j. j, X2 C K
else {
! J# t$ y2 t$ {1 X restore * G) p: `6 Y5 d$ M
di "cannot find pminphddy240"* R/ K: U8 ^. m0 V5 _- ^* }' R
2 a, Y% v& H$ \0 N/ w9 o) Y8 M# }
0 Y0 n; a. L8 z sum dx240
7 i$ N# _5 J4 g7 n& g9 @: ] local tempminphddy240=r(mean) . f2 D( B9 @; p$ r( F6 t& J4 S
" q5 y3 w' ~0 e8 v: C9 j. g2 w
3 K" w @& ?8 T% `& y/ Z7 p }/ g% d$ ]. |: F: D
3 F5 b* }9 K% R+ i
$ K) q8 S0 j, r9 s$ Z ^ ) r& V+ U9 J8 C0 _5 N
2 C0 C, K3 x8 ~3 N 7 |( ]" y! u3 [0 H6 d0 j4 A% B
f+ d2 @3 }$ c. Z gen pminphddy240=`tempminphddy240' in 1
a) z" M. H7 w+ h7 z2 k
. c" V0 J5 R( M7 h' z
& o, S$ R h# }6 Q) u *-------------ddy240pminp右侧低峰值 -----------------+ D0 |1 C" j9 O) |) E, b
preserve 5 i# h# |. a7 x; R$ ^4 |+ x
3 ?3 ]0 [8 g: j keep if dx240>`tempminp'6 R4 Z, D+ |$ i. T! ]1 }
; ~0 y- R/ P" W! k$ o4 g3 u
keep if dx240<`tempmaxp'
9 R- T1 y) S6 x8 Z( f * y$ b/ t. X& J0 h, d3 c- }
keep if ddy240<0
2 J' ^* c3 L. O3 U6 m" ~, ~ 6 z9 y6 j4 d) h
gen temddy240=-ddy240
$ Q, q* F& C3 q$ D 9 |, P% G7 E& E2 n9 A7 A* T
count' h: z5 V( I) h2 p! `6 X
# j: n, e2 x& m# G
if r(N)>2 {
( V* z V Z+ L+ r" d & a m5 D6 ?8 A. y3 a, w: \
pkexamine dx240 temddy240
$ u" i$ D# J5 a: ?& y; [5 s+ M
( k: |6 n# p8 R' f1 J local tempminplddy240=r(tomc)' A1 |5 k" _* e& X2 H4 R
restore
% h h# a! `$ Q) x' m4 E' g) r }& _8 v$ e' m& V6 _+ L
( \2 \6 k. Q4 M( { else {! B" z) v4 X, L8 Z. y
2 S G/ k$ f5 q6 V3 `
di "cannot find pminplddy240"
8 Y# H. E3 B3 p restore
$ b- e" L) h+ S9 J
m! K: N( V, a- n. a9 ?7 A sum dx240
$ S, s6 W+ o* p z3 [2 I0 x0 m local tempminplddy240=r(mean)5 n9 I! \$ e) S, V6 s. u( f4 l
! C" o& e/ n, q
% {+ D# v' c' m- ]6 j- Z D }
/ \: q5 I$ f# m7 G! {6 }8 b3 @ ; z* v5 c3 {2 g+ W
3 F k3 K! A8 x. ~. x5 J , I( F9 I7 D( c& Z1 E( u6 ~1 t: y: P- O
* h, V& o0 H* y* w7 z6 O 7 a9 i' ?& Q" U- z9 N
gen pminplddy240=`tempminplddy240' in 1
' M" r2 }2 f0 Z/ a/ o2 S/ U
" r0 x7 f$ b9 [, [+ i *-------------ddy240pmaxp左侧高峰值 -------------------
0 [8 P/ j6 ?* Q7 g$ M ) d `5 o2 e, v3 K+ S. }. H: {
preserve 5 h# q8 @, j0 c; m
) d# e& z! P3 k9 y& Z keep if dx240>`tempminp'
, l1 h0 O" Y3 a # v2 r9 S) p; j( |& d! N
keep if dx240<`tempmaxp'# R6 p" F+ B- s! I& O+ ?% W
7 R' M1 }# ^+ t V# L keep if ddy240>0( C7 k- b8 u) h3 Z, M. Z2 g. E* h
count, O. g! M) j& s
' m5 J/ q! J8 h1 Z. l
if r(N)>2 {9 K6 m2 `* d. U( k2 o/ u0 |
# V% [: V8 U3 S. D+ y9 w: T& T
pkexamine dx240 ddy240
+ ~% B" V8 Y- V4 I/ ^' m
: ~; m% c$ o# l( n$ j local tempmaxphddy240=r(tomc) ' T# H8 A8 E0 l6 O- L W
7 ~# D6 s8 e, B5 n, Y restore
9 L( y8 N5 G$ t, p) m5 s& M6 e3 G }( O( l7 C+ w# L! f
* l' E9 h1 v; x2 Z M
else {/ s4 d1 Y `6 {( y
8 G3 V+ V; t2 b di "cannot find pmaxphddy240"
/ }5 i7 p# U4 [$ @ restore
, y e+ _+ b& [# i, D/ I
# e9 U$ c3 S9 ~1 F5 W2 _ sum dx240! b$ T1 ~$ A q3 o
local tempmaxphddy240=r(mean) . s, u0 y+ C+ |
3 d& |; X+ O' q+ M7 k/ I6 I
8 ]& ]! q9 t; z% I' L/ o }
7 f3 R e* E" p - @5 F! J2 B0 o6 B8 A9 Q
8 d; Z1 m9 m/ G! V4 E
' V0 j7 {5 [4 u2 |( x) G
$ K, m2 M- Q$ M: D& ~0 n; h+ q) e
+ y" w3 ?1 h% R+ C. ^
+ @1 V& [+ t* I4 f5 X- C6 e% ]/ R6 D gen pmaxphddy240=`tempmaxphddy240' in 18 ]1 c0 q' Z9 V4 B
1 B, K2 L" K* ~1 K) Q8 H
8 U5 c7 |8 [% M! C
*-------------ddy240pmaxp右侧低峰值 -------------------
4 a; u W+ W. A) K: t
! g% V/ y2 T! s/ h* E preserve 0 E8 w; E1 C/ R6 @( l
Y4 n8 T1 @( n/ r keep if dx240>`tempmaxp'; |. T. e/ \' H. z% U
1 W) o8 |+ z3 R; {1 z
gen temddy240=-ddy2407 w/ W a1 U8 }! H, N* f
' f3 r3 M+ L ~# F9 B- [7 D$ Q
keep if temddy240>0# o; P+ ], P8 M* V/ b
% f! A1 j5 p, u) h
count
( Z/ r4 z/ q' `) L" Q' B ' l1 @. k6 E {. o
if r(N)>2 {
* n0 [$ d# p: L% h$ a- w 8 F7 M+ b/ ]. x
pkexamine dx240 temddy240
% y4 C* z4 \" R4 ^4 l! s 9 N& s) z. ?6 L
local tempmaxplddy240=r(tomc) , V! k3 T. @& [6 \9 C
restore5 t! n7 c0 R" Q/ Q
}& b0 E! {8 ?* Q
/ A6 H& g! n. M/ \ else {9 ^7 P( s3 r" ~6 {
restore
0 ^3 b# Z. t( K3 d; ^; `5 s6 F di "cannot find pmaxlhddy240"
$ [$ C% N, Q) e) v/ s
) l! K% r& [+ R( h) V% {* f2 G
# A. w' M D q# E' D% J sum dx240
% J5 W0 D) E; u/ Q+ U' ~ local tempmaxplddy240=r(mean) in 1
- n: L2 M. \5 X* C
! ], s9 }7 z# Z/ d- [* u4 R
9 [, z4 f) e+ A' o6 B( q }: P& d5 T1 J8 x; G
4 |) F7 V: T2 s- _1 P
) W, V( @1 t. Q' o3 K4 l* U2 c ( M! U$ o* @3 n# @2 I4 M5 q
' i# s$ Y$ s4 v, j- l
, m+ T3 ^: ]8 R3 x! K1 r3 l. X . A7 ~9 _- T1 d9 M2 b# C
gen pmaxplddy240=`tempmaxphddy240' in 1
. u+ {" z1 |' D
; {: Q+ n- J$ ?' t$ v/ ^; B% U *-------------------------------------
' p! X" m1 _" M
6 P- f2 `+ T. D) I9 g gen price5d=v5 in 1/20
1 y9 d; {0 C0 T6 q* ]
! Z4 b2 X2 L1 B1 s gen price5yy=_n in 1/207 v- s* @8 V8 B. l) K7 e, u
" k; m# d p/ c2 @- ]7 F
gen price5y=price5yy*(dy240max-dy240min)/208 A s; e4 a' e
* t* _: t1 m! u* Z *price5y &price5d; d* @9 ?; C4 _# k t, u
8 N1 Q2 R8 A' a7 i& ?, M
gen priceny=price5y in 1) _1 J- t. I' ^& X
7 f2 J; E4 u9 {4 `* `
gen pricen=v5 in 1! {! k0 n% x- s1 n/ f- X; F! o
" N7 i$ W+ z) E- B+ _, u! }: V
2 R5 X: H) B. v8 \) M3 q *priceny &pricen
4 r* C, J" @% t3 k0 \% A
* T; M9 B& E; F1 g, o5 k
4 y: r+ V" X6 E5 E. u* w *-------------------------graph------------------
9 D E" R! H1 K* N% l( t- a c' b$ t6 ^( d' i
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)
( w9 A6 ?9 z7 c, L% C6 Q# Q9 r" T) z9 t
* ---------可选项目----------------------! _" E% y. C$ d1 J: X Z. M' p2 ~
) s0 a& h/ j3 g- c! R. S. L
}& a" r* V$ U+ D4 b
end
( B' l2 I8 P5 c. g* r* e& Q7 M |
|