|
maodeng 发表于 2013-1-28 13:13 - h A5 u; l m3 y: n
. hello 300236
7 K4 ]7 _6 f% r7 \; fstatement out of context
2 y* O1 x. N, n6 t7 a# F* Zr(119);
4 |/ s' p v0 s抱歉,最近太忙了& p; s' B7 U3 v9 K$ l! a2 }' h
6 p7 \7 J: M9 ~+ \$ P: V( _300236 我用下面的程序试过,没问题
) A% E% c5 j8 L! @- D3 ~+ }8 ], A+ R
% X. V7 ^5 Z7 l4 G5 J; p; s你把 D:\stock\test\source 改成你导出的数据存放的目录,再试一试 j9 O: T& ]+ F
9 N+ D/ U/ C9 w4 H& p7 x# Jcapture program drop hello6 a5 u, }( d& S, W* r
) `3 D# J4 H- w* D! \5 u
program hello$ h9 p- o) v% p( I
& ]! z- p1 y9 O4 J
quietly {1 o7 q' Z) I4 T: y- V
\: R7 b* g) _5 h. B
clear
6 `- I; O% q, E: p* U: C# M& L# u4 u; x0 u/ Z& F! w9 q' ^$ F2 E
cd D:\stock\test\source/ ~) ]2 U z/ s3 u' B/ I, g
: x3 D4 O% n6 d+ N% _
insheet using `1'.txt
- }; t6 q- |+ z: z
$ q- w F, L) ^: W# K/ } keep if v5>0
4 o1 P- E0 ?( W . p# R: k$ t% ^/ q, M8 {
gen vt=_n, h) p+ g9 z& T5 G1 d7 r/ \0 R. {
2 ^) f* P6 r6 v1 k4 y tsset vt" n( M |6 q2 u) v+ P
' A+ r2 _4 E t" z, Q9 O2 T# a+ n gen zf=D1.v5
9 Q% U8 L" x# Y% O* d# G
9 e7 N1 h4 }3 |7 X) |, L( P( W: U gsort -v1) R% ^/ E1 v6 w
L* E1 m% u" Z- P gen avol=v7/v5
; G/ p2 K: w: t7 s0 l2 U ) {) U8 {) Q' N
keep if avol>0
0 d" w- j. P, v% m% G) J. m
# a; ^8 x; e/ q0 L2 O drop vt* s6 z. [6 e( E7 ~
7 f$ ]9 ^+ } b) N7 {. ? gen vt=_n6 x. S y3 }- f) }! b+ E& p
2 q9 u4 P4 v' r6 Y9 M( g2 @4 a
tsset vt4 b y9 K7 a* z
$ V/ [) |* o# X0 @" M1 Z sum v5 [aw =avol]
2 F) U2 S+ g/ v* L* A* B( n, J7 F5 J" G! S
gen amean=r(mean) in 1- I* Q$ x7 T6 Z' B; J
) `- W% e7 `, D) D+ p
* 总加权平均值 amean" x! K8 o. M; }
8 c! m: _' g: M- h* j
; o( o7 f1 W6 ` keep in 1/240% e( o2 n' K; A7 w
" U8 q, I+ g3 q) D' |
sum v5 [aw =avol]7 J. v9 k+ f8 ^7 m
4 o, S. d" i( m: |+ B' L
gen mean240=r(mean) in 1
! e* T/ p9 B% a" \. T7 t1 h & X4 L& k9 s% V8 N
*240加权平均值 mean240: F1 f3 u! Z$ m" ]+ b
# |* j( g$ P1 G; k/ F
set obs 500 + y. ]4 J8 N1 w- c- r4 W, r6 Y
! v+ n/ P+ l1 D4 r6 P+ t kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
' i h2 D7 R2 G" A ' e6 H7 K9 I0 T9 P0 v V6 Z, }$ R
*240 kdensity(dx240 dy240)
8 c9 q$ z7 k" q0 b2 x2 b: k2 u
2 P' B! @& {) e/ f+ s0 F sum dy2406 z; `5 W; Z; ^9 a! R" u0 J* O
( f* r& n3 v- x gen yxis=r(max) in 1
/ H4 V/ k1 ~6 {- c w" D$ O! o# B; }
, r* ], H& x/ ] gen yxis2=yxis/28 N/ Q; _7 `) Y* n
# W0 X' O; q9 i% F7 G8 _8 Q *yxis
1 _' K7 J; n, b- R
. g) H4 T! j* {$ B2 c gen dy240max=r(max)! b2 l6 |$ h5 m8 r. `6 L( E' f' K
( q5 [! J" {* ]' o: ? gen dy240minp=r(min)
& E/ e2 V! z: @9 Q- w& z
5 s( e* e- k! W& X$ H gen vtt=_n
5 ]( c# S+ Y, J
3 s0 L; t% g' Z tsset vtt3 o1 B+ c! ~" u! K/ l" \
9 |7 q3 [" V8 G E& @ gen ddy240=D1.dy240/D1.dx240
7 C9 c H( d7 K o' V
+ D4 z# ~. t2 N7 j1 B sum ddy240- X& r" R$ @" a+ h) e3 b- e$ }. W
/ K# `0 C* O* D( ~ gen ddy240max=r(max)9 }, ~; F* b6 g
/ w' x) K7 s1 J+ d# V2 n
gen ddy240min=r(min)7 o E# a2 ~" s) \* {
' j5 h3 H0 z `, i gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
0 i- F7 b' U% B5 I
$ ?6 e' o$ m: W* Q1 V% T( c: U sum ddy240g5 K! F# J+ h7 t& `% T5 d I
; t" Z0 G* J6 J( w
gen yxis3=r(min) in 1
* @. w1 R' N4 V- @; T) w 9 n- H* b. w- V1 a
gen yxis4=0 in 1
7 K1 w+ G! G Q3 ? " m o/ m& v- B
*ddy240g 1 J$ B1 H8 A. e8 ?9 L4 A
2 k2 f; B- Q/ i- ~2 M: N9 s# ]
d$ R' ]: X0 c" i3 Z preserve
1 b% ?3 V5 n- ?' U 6 U$ O7 _+ E1 M9 k9 `3 D' j* S1 B
sum v5 [aw =avol]
4 n" t- V/ m& ~/ q5 T" A: k. t 2 [4 N j6 ]- f0 x" _
keep if dx240<r(mean)
8 G3 W- q0 [% {: x
8 s1 k' N! n$ d* Z1 E( g- b sum ddy240
8 a O3 [. b+ n0 t4 Q 0 j) }5 |4 Z8 F9 l' o
if r(min)<0 {+ E% V! V7 f4 G8 }
% q/ c# d1 K/ a* I+ i keep if ddy240<=0
+ ?5 f% e* u. h( A* x
- b# T/ z, \4 n B6 f' M* _ count
. X1 z" B- s6 P' w) `
0 S, F% V/ |! @% I+ g if r(N)>2 {1 n2 w! U' g1 d* z6 y8 {
7 n! u, t0 b& Q. X
pkexamine dx240 dy240; ]2 S. w! R0 W8 S
" [" Q6 q9 b: v: J% c! p9 ^) {; ?- g
local tempminp=r(tomc)+ p/ K6 x1 q# h8 n% j
restore 7 [7 U' {4 a0 ^' a2 k' w) g! i- m k
}' p5 X! ]3 a4 ]2 R+ w; S: v
& q: c1 w. v. o3 x3 {2 U7 a
else {
" P R: Q& J+ C$ G6 N6 k- R 9 b$ k8 E4 y2 B, F1 Q
di "cannot find minp", k4 R( z) i" I6 X
8 `0 _& W0 h6 k" F! k restore 7 g+ |# i7 d# s- ~+ x
sum dx240/ c: T' q, i% W" n
local tempminp=r(mean)
- `: C' l( b- [5 O2 U, n0 M - j* [* @' v! k' K& c+ `& s" I
}
* j8 V. H* T0 Q: d }
7 L4 R8 o+ {2 W7 t6 c2 Y3 V+ M else {$ [" X& s; N, j+ o& B
5 ^! r5 a/ _' B) `6 r' n& y4 Z R keep if ddy240<=r(min)3 I4 o$ i. v9 v e
0 t5 }2 V* [+ ~- Q' [
sum dx240
: ?! ]1 r* j; n! D9 c7 O
" Z4 T* f" x+ t. u/ V( ] local tempminp=r(min)3 a& p# J- ~: y1 l y8 H) s9 f
restore
+ Y; v* x- ]% e; j% v" c o( Y1 B }( D' |% C5 E" ~ Q# ]
: h1 ]: h( m2 T, X6 z2 A
: Y% T) l* A( z8 T
+ g* k5 i" W9 M* Q) q+ C0 X gen minp=`tempminp' in 1& C' E: c5 F! @
*240 minp8 m# d g3 [+ G8 W% o$ Z
! c9 P, a( }5 e' r6 c: e/ p
0 f9 X$ |3 [# P2 f, {: s' K$ |
, v8 ^% ~6 _' [2 @4 P) ]# W preserve % j( c1 \6 f0 L6 n9 g8 M: P, G( u
# D. y8 z* x* Q' A
sum v5 [aw =avol]- v5 L5 [) J% _. g3 E. T X
7 w: Q9 D9 ~ c9 ~: H: L
keep if dx240>r(mean)7 a1 l$ v3 _1 X' P
" l2 w6 T, L q- X8 _! Z% o' X sum ddy240( |8 J& c% @( |& R; f
/ j" D5 p) M9 Y* V y4 \ if r(max)>0 {
6 U; V' C4 c. P( U+ B, F7 x , j) A7 k* z) E1 n- q. w
keep if ddy240>=0+ H3 ]# ^7 X# O& ]4 l* ^4 B
7 T5 k. j7 |$ K* Y( f9 Q( @3 B) }
count/ b6 C3 Z0 C6 [. a9 R! p& q% w
! X; g2 d! C0 B& N6 x if r(N)>2 {5 p( @# D* R9 P, A
$ b/ m1 U W( z- x1 L- X pkexamine dx240 dy240+ Y; n" u0 E! |- l& t* z! x
n9 W; V: O& J+ c7 u& O$ Q local tempmaxp=r(tomc)
& b' Q2 d) u k! D7 r$ z! o) ^( O2 f restore
9 d" v6 J7 y; ~) K3 s* H: N7 S }
* F5 j1 o+ F- F. Q' u# J & B1 [4 T# M" p
+ j# Y8 |( b- U. M else {- v0 ~) }* \; C' D! H% [
restore
2 ~9 J! g/ F' S6 V6 a di "cannot find maxp"
' F$ T& a. n% x/ I4 x3 M
( x* e5 q" S0 h* w7 `; t* r* I- I
" w3 `9 a; ?. d; h sum dx240
/ G9 B* ?8 }. z" h' S0 I0 D local tempmaxp=r(mean)
* M- Y4 d+ Y' Q& i/ e6 h 1 s, m. k2 Q- i' @; [: X$ `
}$ X% U" ^. F4 p* F3 j5 d
/ p5 K" G; @0 W1 r/ L( @
}
4 X# Z: Q6 _; W2 F- `4 t I5 K8 \ _
6 d H: m" k+ x# S: a# N4 ^) R, T else {
( i- q9 x7 e2 Y; `; q+ M+ p ) e/ X. W- L2 r
keep if ddy240>=r(max)
- h- s' U7 g( Z$ n 3 D4 L1 S& u* p8 k$ w
sum dx240
- [4 y7 q- U3 W. K# u
, M2 A3 [/ E7 _$ w' g4 T* k local tempmaxp=r(max) 5 _' G! s, R. c; E6 y1 @! r
restore * P9 n+ P1 Z% H$ a8 D
}
/ V7 d! f( s/ z. b1 j+ f, r7 Q2 i1 R
2 q) {8 O2 h# `% a1 u' N# B7 R( H6 Z3 M1 U4 B3 H, p8 @' g
0 o5 |% A1 K9 Y9 S2 D' F9 p' g9 Q7 p( e3 B
gen maxp=`tempmaxp' in 1
! k0 L: _! F2 r/ L5 B 0 O. m k3 g- t! r4 @+ T5 k) A$ z
*240maxp4 j' V7 ~0 |' S" @2 q
, ^% F! ?" V, a& U, i" Z . V# J1 r7 U2 S$ @2 n4 c
*-------------ddy240pminp左侧高峰值-----
: u6 G5 _0 N {: x % q/ q5 T' e* K1 }# T. u: u$ N
preserve ( \% L$ [+ O# v6 F0 h& Y/ [" }
: V7 t# `4 ?8 C* z* u keep if dx240<`tempminp'
) @* u4 l) T: z# N' L7 o9 y4 S
. S6 a, b6 u% Z% v keep if ddy240>0
- S. D0 ?$ E8 H4 z2 C" i0 @; M
{7 C) t' y1 A0 r count- g( [ b( m+ L) B4 r3 I$ m
" B% j# U/ B9 j5 {- K if r(N)>2 {
( t; w5 B/ h6 K: P
+ T/ |3 `+ K) s* N+ p$ r( c pkexamine dx240 ddy240! I. p. E; l4 d; C. z1 I
- V/ \0 ]! C7 o/ R
local tempminphddy240=r(tomc)
! P' Y e* M" } restore0 i- ^" S4 b) `# k4 r6 i1 e
}! b0 P7 v1 {7 J) g! n1 }5 F
7 ^8 b# p! e4 V3 W* k else {
9 e0 m( S' I0 ]# _! o5 u8 s restore 6 m5 F& H' y- P8 O$ d8 l& l* H1 U
di "cannot find pminphddy240"
. g' Z( h& g+ H; e8 R* ]+ q
# Q$ x0 G2 i, q ( c/ Q& {3 d8 R2 ?# f. _
sum dx2402 C) Z, O' s3 T- \/ T
local tempminphddy240=r(mean)
8 i- @4 a4 @0 b3 ?0 b1 X
* c9 @$ g5 u' k; \
5 ^( q' A8 i# K- `/ _: I! {3 _ }8 q$ [' r+ ?% `! ]
( E0 O: X# a- i9 s+ c, K ^, w
! `8 f6 Y' i5 h Y' J, ]7 U; m% ?
C+ x. j6 p/ ?$ N ! X p% ~! P, m) l0 z
2 u o% u' p" H1 K, P1 e* v
9 l; a' @4 }# [ gen pminphddy240=`tempminphddy240' in 1 y: U3 R5 s; G8 B' C
F8 P" K9 R- [
$ q. j7 ^9 T# f' | d
*-------------ddy240pminp右侧低峰值 -----------------
- e$ G0 D: [5 \2 o preserve
, A' E% y) ]* e, ^ P# U. A6 {! D 9 F6 {! c g) w4 i
keep if dx240>`tempminp'
7 j% x3 p! S9 W# L* ~# L$ g w4 R
2 |+ C, N% }; _ keep if dx240<`tempmaxp'
7 x. a5 o! a4 `7 Q' P+ K) C3 R
5 S9 W# |4 ]! P' L: w7 z( w+ J keep if ddy240<07 F7 i2 r. P# s% I; I; A4 X8 s
4 p# N, P+ k$ T gen temddy240=-ddy240
2 [) Y( u* r& Q
+ [6 [5 v4 b" m5 S8 t count
9 L/ v$ a0 R9 n; y8 Q( R2 a 5 g# n( U' U/ |: p. K: d* e
if r(N)>2 {
- H+ R! _' u9 d" m& [& C! ~4 y# _ - {8 X l- E2 Q5 o( L9 ^
pkexamine dx240 temddy240
9 @( o0 [6 w: o) w
$ O( ^$ Q/ c' ?7 m9 e4 _% h3 D local tempminplddy240=r(tomc)
+ K0 `5 Z" ^2 M" t$ D( x3 c- N+ t restore
# h7 H q* ^( W# @7 O }
/ W7 x' w% V- y2 Z
3 h& `! G! y5 Q+ l7 O, r/ { else {
, f! x) W* r% v5 Z
/ _2 {4 x Y6 \. A4 l Z8 I di "cannot find pminplddy240"
H# t5 |# ^0 R( L restore3 M3 e4 h* V5 [" h) l
8 N s* _: V1 E6 x7 t- \9 a
sum dx240- Q5 V% J4 h t( W$ }4 y
local tempminplddy240=r(mean)# B& q2 }2 g& _9 r0 Z
* p* m5 b/ W A' |! R; \+ ]" p
' w+ N# s9 ?- {$ p }
" `5 _, h ]4 c/ i 9 Z' u( S1 [0 X2 i
# C l0 b9 y+ [4 F+ H; T
: `' S# S/ ]' l: @7 X! L
, y# Q+ l1 _' S; H' x) o# P- z7 t6 q
- Z4 l/ E3 D. E+ o; G% R gen pminplddy240=`tempminplddy240' in 1
& y6 \) b! U9 o8 z. u$ } X/ y- @. @3 G7 f5 u8 ^
*-------------ddy240pmaxp左侧高峰值 -------------------
6 D3 a- ~, c+ N6 w; k8 P8 W6 C / v2 R; b5 e, K
preserve ! h/ F( t: i" L) q3 z# i
7 _ A& R8 K! R$ Y" a" L' K& @ keep if dx240>`tempminp'
0 S+ T9 h8 O, Q! L4 }
6 X, D$ J. Q6 k2 c9 i9 @, |7 U keep if dx240<`tempmaxp'0 g; s7 S9 T; ]7 z% K
* K9 \. G. k1 U9 ~ |" T" T
keep if ddy240>0- C. m+ V; h& M9 a/ Q& ?' v
count
0 T" x+ G, B; f& L0 h" B* v ( i5 {: k( ^, Z! I( @
if r(N)>2 {
! a+ I6 h% O1 K9 m. x. p8 c 6 b6 t" H x9 a' f1 ?+ v8 }
pkexamine dx240 ddy240 X! i6 v) F- O* E9 t+ [
5 H& H3 n% M' }! c local tempmaxphddy240=r(tomc)
, b- n3 y, p2 S7 ]
; W% p' D" P# [/ z restore% G" I8 ]* W9 ~# P. i
}" e, B9 g: E! i: P$ B; a! X" ]* q
0 Y3 Q: x5 [: Q& C. ~$ ^: J
else {
, Q2 x6 S# r/ @
) J! O; n' g& P" @2 j# q di "cannot find pmaxphddy240"
) @% P8 \0 Q& ]* a( U; _& b( m restore' L2 s4 F( f, f3 K! Y& g4 X
2 |9 Y; ?1 ~5 ]4 l( i3 r. {
sum dx2406 y+ g% V3 j+ s& k
local tempmaxphddy240=r(mean)
6 M, b5 {% n" L: O0 ? 2 `; ]6 ?( k5 ?+ l6 X# O; A
" |8 N, Q( N2 [' ?9 t$ N }( k3 J0 @' S2 ]- H
* N$ I y' p5 Z
" E3 R4 E& b" Q0 }* E, ] ' L4 `: d3 k: u3 X9 o: V6 Q: a
6 ]# N" K# j; O+ {* f
: K2 z8 `* d" e& E+ J# s
1 W+ O; X7 H- x! J. O
gen pmaxphddy240=`tempmaxphddy240' in 1
. y; i# `- w1 Q; \ 2 E6 w8 @! \& e) {0 y* U6 E$ K
t0 b7 l# S0 d; U% g0 Q1 W3 |
*-------------ddy240pmaxp右侧低峰值 -------------------- i9 S- F1 z9 J
$ L: N! |7 `- ^& j2 Z( Z
preserve , \) c7 a7 `& |& j( ^) j
2 C7 T- z. S6 q/ Z
keep if dx240>`tempmaxp'
7 \' j( v( W) W3 t o0 ?
2 |/ n+ d5 T1 r0 w% g" P gen temddy240=-ddy2409 ?: e z$ S5 S5 r( k( P: [4 m
/ O# h4 |1 q: ~+ V# c* u
keep if temddy240>0
! S: ~+ O9 |1 K0 u0 E- c & x$ |7 ~$ P' \/ s
count0 L9 ~1 v/ h( V0 k' P
! t3 u3 }( s( [' q if r(N)>2 {
+ ~8 f. q3 t. z6 v$ K
0 x7 ^- Y+ g4 P% J& |% a pkexamine dx240 temddy240
0 t$ U/ w- K/ a: d9 [
: k! z% H& s# z) M( \6 v9 |8 R local tempmaxplddy240=r(tomc) 9 \2 s2 G; @% R# f6 V6 |; _( s
restore- h2 a3 c: ^& h/ {0 D
}# @, Q" D# [" S8 s# N3 k5 ]
, |( i; L, }; K8 I* N- q* e& j else {
: D2 Z6 Y r( f5 g5 f0 G2 M restore7 H2 R& x+ j( M a5 K1 L0 l; y, ]7 C
di "cannot find pmaxlhddy240". V& U, r% _2 ~6 d: \1 t
; D& B n9 K. b1 j2 B0 G ; Z. a: u# m2 Z0 X
sum dx240
2 o) D% ]9 ~- M% w& Y8 G local tempmaxplddy240=r(mean) in 1: D3 {& A+ U! ]
9 k) Q6 Q0 p. A- @0 { 6 q) @7 D$ T1 U' [) a
}
0 J- _6 u1 D& ~ T @ Z8 ~0 v
5 X4 I1 _. [$ }0 P9 D 5 b! N& D1 T v& p' ^, Q5 i
# w0 A" P) G# K/ b 1 C! S- B% ^. V* T
3 t1 [" L( z( P! C- n+ _# m
0 E7 v7 E1 a: p" } gen pmaxplddy240=`tempmaxphddy240' in 1! M/ o; t, u" ?& X9 j* z' o
2 K6 `: {! ]$ l% ` *-------------------------------------
: p# L: `* _# r# M1 u* x7 X
, T; v1 V1 G" I5 ] gen price5d=v5 in 1/20
$ r$ }8 e- g3 A+ e( ~ W0 l( I" }% F
gen price5yy=_n in 1/20# y% ~& d& T! w3 p5 f2 K
" m+ M* N! |9 n0 R# M1 d7 y* H
gen price5y=price5yy*(dy240max-dy240min)/20
$ O) \% P& N* p1 L k S0 F, d% z . R6 ]1 A+ R( W8 c( r
*price5y &price5d
( P5 O; C2 u2 H. ] L; J* C* m8 {
9 d# ~0 N- r' I3 m5 t5 j- y1 b gen priceny=price5y in 1 ^9 d; ?; Q) x8 I' C9 F5 ~! A$ O: B
# m5 S# Z, w+ B
gen pricen=v5 in 1
- T4 _0 e7 ?2 T' X/ a& S5 g$ ^7 G+ Y
+ f1 w+ V( |1 L+ f& _
- o4 B1 G; i! w) H# m& W *priceny &pricen
9 J& ?( n! e2 c0 S
$ ]) d9 J8 i* W
' F% R- h! M7 W4 Y0 @ *-------------------------graph------------------
2 M. |$ [, V4 ]1 j# e" }+ J: ^ 2 k2 L$ H; ]+ y0 s H- T
tw(line dy240 ddy240g dx240)(spike yxis mean240, lc(red))(spike yxis maxp, lp(-) lc(black))(spike yxis minp, lc(black)) (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: c% n9 S! c' j: J/ ]: L
' G+ m: ?7 y% W; B+ m* ---------可选项目----------------------
6 h3 b& l( C4 x0 X1 b! W*(spike yxis amean,lc(blue))(scatter yxis2 amean, lc(blue) msymbol(+) mlabel(amean))
* W% g0 n. _' d- \+ ]' g}- A0 \1 t2 f; g: z% ` d( e
end5 P. c( H8 \4 b' R, E7 B' a% _% p. O
|
|