|
改了一下,这次运算应该没啥问题了
$ Q9 }6 s8 K9 J" \2 N# q. B2 ?( e# T/ l5 x. Y- X
/ v" {3 C6 W, z. o3 I8 mcapture program drop hello
. d, d8 |# q& S5 p& g/ i* l% T) m
/ C2 g x, E0 _; n9 v/ b5 xprogram hello1 j; F; o4 m8 o. A. Y
+ ~/ Y2 \' w4 u- T, x1 `- s* } quietly {/ h' j2 c7 f0 X/ g. |& q
5 H8 U; R% M0 R) |; e7 Jclear# n: j0 p7 d2 Z M( E/ M
7 u# E; X" D& ?& ]' s* l
cd e:\finance\stock\20110101\source
7 M8 @: \3 X$ I4 d& e
$ a' B1 y" R6 a( ]. e$ ~2 ninsheet using `1'.txt& `" k: U( h: g+ M5 V, T
: v p( u3 d! i; g/ [ keep if v5>0
+ W9 ~$ J6 P- C4 t$ o
) ^0 _1 N; O; l# d9 L gen vt=_n
4 g& ]3 s7 I$ {; f E: ^% _ z' v - `9 E$ o& C5 z( U5 {+ J) }
tsset vt! v% }6 [% m8 q( z, B; v# ~7 j' F
% N. v" R" @8 s: v$ M
gen zf=D1.v5
: W4 V0 ~- w+ k8 P2 m1 |' N: I" _, L
gsort -v15 g6 i; t" V A4 ?
4 |6 b( U' g( |/ D9 I( V& I8 j gen avol=v7/v5
/ b7 e/ [3 C$ p* {& s1 R3 V1 _ 4 |; W( |- ^, G9 i/ z
keep if avol>0! g3 c7 E6 ^1 N; ?7 k
0 ~) L! h& M+ Q7 i drop vt
9 b! J6 n( G& X! Z. H 7 y. \$ t1 s# V/ p# [: r. s
gen vt=_n2 W* P X- Z1 m6 Q3 q" c
2 e4 q8 I0 ]9 _6 [4 o2 S' f0 X
tsset vt% ^! N8 {1 J& j! A
# }: i$ |+ `! b, W
sum v5 [aw =avol]1 S) v- s% o' L! t- E4 G- I' Y
! F% A5 c7 d) o4 u
gen amean=r(mean) in 1, m+ i: r: M6 t8 }
9 e+ u0 [! G) E/ u6 ?: m1 \ * 总加权平均值 amean
s( d- @( x; [. X0 W
% \* M1 q! Q# z5 ~5 |2 W 5 B" `" ^* E# m9 P3 h
keep in 1/240" K9 c- W& R; I( q1 P
, V3 ~" M, c8 A% q sum v5 [aw =avol]" ]& _4 h( \- k* a" d
9 P1 ~ t; J4 d, ?/ t6 A9 R1 G( S gen mean240=r(mean) in 1
4 r p4 ^1 V3 f R0 R2 u
# m3 T$ L7 b- d, a% I' w# ~4 r *240加权平均值 mean2405 E1 u8 ]5 P4 k2 z
5 [1 X, h8 @ D
set obs 500
/ h ^/ f% `0 C% [ & Q6 G! Q8 T- z9 s& J* N7 b" D( ~
kdensity v5 [aw =avol],gaussian n(500) generate(dx240 dy240) nograph
; C# t# M g) N- O0 q; m) J3 h/ X 0 H2 U; P: y5 E4 }' O2 ?6 l, s2 X
*240 kdensity(dx240 dy240), H3 c8 R& K- ^8 t; W' L3 g
$ R$ V; J( @7 C( ?2 |) L' E sum dy240
2 V0 S3 |& V5 ?. _6 D% N $ c# s6 A- D, y% y8 y* ^4 J" A, T
gen yxis=r(max) in 1
' p8 O0 p( k5 U6 d% ]0 ? 6 k% j; [" y/ C4 j6 m
gen yxis2=yxis/2
# Q! x, D* o+ b. C! m2 b , E2 J) c% u4 v3 A+ k7 N
*yxis- J( L1 k. P: Q) I, U; ?
; r1 n# `" r7 u2 x! H
gen dy240max=r(max)8 _" n5 S7 c, Q! n
. T* A6 Z; o; ~4 g gen dy240minp=r(min)
% p4 J7 ]) m1 n" h/ x
) j& G' W% U( N: O gen vtt=_n! x/ R$ Y* h4 q
& `! h: Y2 @6 a$ ^; ~ tsset vtt
- q e3 o1 T- p% G2 i! t* x) O" E4 [+ B! R5 k2 Y! I' [' e
gen ddy240=D1.dy240/D1.dx240# j$ P! Z) T& x4 n
V( d8 V2 @! @* m0 u1 e# h
sum ddy240
. I3 s6 q* |4 [7 q+ M5 h
& [, \8 P: I, g4 s gen ddy240max=r(max)
' t) Q; ]9 B3 o R
' n! B1 z/ P, `3 J( X# F: p4 K gen ddy240min=r(min)
8 S* t1 L4 I9 ?* X
8 f9 D- r+ t- ]$ K/ J* t& P' B( M gen ddy240g=ddy240*(dy240max-dy240min)/(ddy240max-ddy240min)
# p c' _0 X) `3 f$ I O A: C 9 s, c8 w h: C: X) A4 v
sum ddy240g, k* g9 p, y! D, u
3 R3 N/ ~. D) j1 x, R! M gen yxis3=r(min) in 1
, D7 ^6 z7 a3 M
2 o! A( a9 o' ^! `* n( u gen yxis4=0 in 1; @' M7 ]3 {; O% a! F7 C
3 Z( r. v g3 u' C% W *ddy240g
& Z/ K2 H/ Z: k7 h
6 K) u9 H) e- K& g( }4 X " S* g$ B2 N9 i" A+ L
preserve
- b5 G7 P6 z1 M2 s0 ?( U/ y8 D 2 o% U9 d8 Z5 E
sum v5 [aw =avol]: S( N1 y: C9 r$ M: d
M8 H+ U( ~6 [6 ?2 Q3 U
keep if dx240<r(mean)$ J% J& [$ c3 s
, i. ]( d" s+ j sum ddy2406 k& w# ^& D ^% G' a
+ Y5 H2 H& v8 G1 l7 e0 j if r(min)<0 {5 M$ ?, Q( p6 j2 V5 _+ P
& X( f# W) u! f5 Q7 N& h keep if ddy240<=0
( T; o3 f4 n, ]$ y 4 v- W# |( N2 ~, ?) h
count
; e( W; g( U9 r$ T- O+ i
7 M# c' o3 ^8 [ if r(N)>2 {
. u& a% B- Q: v2 r
! d6 N8 J3 z: s; o ?8 t: Y* ? pkexamine dx240 dy240, _2 W5 A3 G# I6 d
# ^ h# r8 D' \) x0 ?3 w$ I local tempminp=r(tomc)! I1 z$ Z Q' N& R8 b
restore
) A8 h& V! V5 X+ y, ` }$ E9 H3 v l/ t2 E1 y
; }& T9 Q7 w9 b
else {) W+ m4 a! p5 F) `
# t4 @/ e7 `' ?! Z5 H. P! O9 I& h
di "cannot find minp"4 Y( s0 x; F: L7 p D% s
$ U2 e, R- F2 \
restore . x' H, p0 N$ e/ Z( e( w
sum dx240
6 U1 R9 H# e" a* \; F local tempminp=r(mean)
& I- D$ n5 u$ p 0 b) Z( Z8 U0 u5 z4 o' x! d
}, }' N+ u) M0 s e Y
}" `8 F; n& y- [ W2 _. y
else {) Z+ L7 y/ w: t
0 ?6 \' Q, g4 I) Q- [' ^
keep if ddy240<=r(min)
; C5 G* c5 d, X, \2 s/ ~ 1 }: A" T; ~* h% F+ v& a) K/ {
sum dx240, B, v" Z' b& q- n2 _
6 D: r9 J6 M3 `# B- _0 [5 w, b8 U% j
local tempminp=r(min)
9 k% c3 C5 f/ J" V8 ^' s$ s restore 6 R z! a+ q1 X; E
}& z2 R; p/ [% v: h4 q
|8 ?3 X$ N3 _! t0 P
; S; C8 ^3 D, H" d$ A
7 N$ F/ r0 w7 }( P+ ?. K: o: m gen minp=`tempminp' in 1 f" R0 v7 Y% a3 u8 }
*240 minp4 z+ p/ u" N* Z
3 i- F @/ c9 m w
8 {. b4 _ ]" |
5 D6 d) N& l3 O3 p8 y/ g preserve
. m. A% h; x- u* X0 a. T4 X + U! `& G" |; W7 ^- W2 U
sum v5 [aw =avol]
+ n+ m9 |8 C2 q: ^$ `+ l . Q" R* j* J/ [) r8 |! J
keep if dx240>r(mean)
/ [* P2 ~7 r5 y
5 W7 ~! ? E/ Z, q sum ddy240
, A& f; U) `6 m, b: K # x- N. w/ [/ Y; E1 O2 `& P/ u
if r(max)>0 {
% m; ]* o# G) l9 b5 O D/ s! p / m8 N- v1 {3 F2 |
keep if ddy240>=0
# g0 U* \/ k5 L; U& m
2 u- A! Q# u- h2 B- m5 d% { count
, H. [5 w; @( {, R G * S) i" `$ }/ D
if r(N)>2 {
# Z& D+ V/ r" N0 K : e) X T6 {6 ]2 [0 y( A* ~' s
pkexamine dx240 dy240
) f# d" r) Z* U$ x( r' _
' G; p9 y- z0 M; _8 Y* \( e) k local tempmaxp=r(tomc) : R1 Q2 m3 W+ m$ |' z: h( C
restore # T2 d: Z7 E' t: l' C9 U4 Y
}
0 s/ Y7 A( O2 b
, j5 n M% R, q9 _ Q+ S% h
: a+ C/ J& X9 ], L1 Q; c. x K else {
8 Z+ f) u9 K" p restore
* U* f6 N5 F8 x( V& h( l di "cannot find maxp"
# n: j% R6 s6 x/ E& |; ~ 8 N) `5 o/ @1 }: _
% B& o9 t. c% @: d0 r6 w sum dx2409 ^( C8 U1 q y, \* @# x3 ]
local tempmaxp=r(mean)" I2 o. V2 B! J0 D
- X0 F( s; n4 E9 t# m0 j) D
}6 a( }; M6 G2 ~
$ m) k+ j% @3 D4 G& r* ~. r/ b
}6 K& r1 a& D7 J3 @8 A' H! T6 g8 C7 y
' X, L5 M8 r9 t8 M else {
- l- k. t& o2 u! v$ m9 D ! K3 _# I" I% h- I/ C$ O
keep if ddy240>=r(max)6 u/ V6 n) I) B" n
* q% y( `+ U1 I$ e sum dx240
; S1 o$ o' K8 y4 M! l5 K
% H. _1 W1 a5 k( ~6 G, d0 q local tempmaxp=r(max) % w9 X/ K1 ?5 T
restore
, s: l' ^# K( O* e }2 F' H: K: Z; Z }
6 v; p9 | a$ e, i# a3 z9 v
. { z" [8 O" x$ ]. r$ I " F! k( W& S& t( E j% g
1 C# w) ]* I4 P3 u2 L gen maxp=`tempmaxp' in 1
8 n5 D7 |( _1 E$ c( Y/ @) q
3 E4 x6 e) ^& t {$ f *240maxp
- f7 J$ G, y. S* w) ^
6 j( z' j/ @( L% h+ H
0 e* f/ y6 ]. o0 s *-------------ddy240pminp左侧高峰值-----
& k# S# h/ a/ H1 B9 k
( p. ^6 P; L! F8 {( E8 ] preserve
0 }. M# Q: G# W: [* i- M , m- G5 k% {% @7 k# l) E& {! m) q
keep if dx240<`tempminp'# Z+ f1 V4 X5 T
3 x$ `8 g4 j/ x/ q4 p& s6 J: t
keep if ddy240>0
4 a) V6 A: q" Z" `* N" r . B. {+ r. ~& s' ?0 h# p$ G6 v, r
count. o7 U5 l: H% I& O* g) _! r# m& U
# N/ a4 |1 L6 Y if r(N)>2 {
6 o! X. C& I4 O Y& r$ @6 I, }: O
pkexamine dx240 ddy240
7 \ G( L1 J: l W: g+ {4 h% _% T , b6 I U) K% K+ q
local tempminphddy240=r(tomc)
6 F$ b, E2 u' ` restore {3 h/ m7 [; w1 u
}$ M# p* k S% s7 d' f& ~; u
`3 F. Y7 v$ V' `& X0 N$ a, q
else {
. u- N, C9 ?- b; l4 @ restore 8 I$ A5 V# Y% b) n
di "cannot find pminphddy240"4 _# f6 t% z4 b0 q
+ ?" e" ^9 q* d, p- U % A u6 S7 [$ \5 ]
sum dx2406 E: ^6 D) }1 _' B- T& U7 U
local tempminphddy240=r(mean) 7 [1 ]3 J K+ n1 }4 A
+ i" z: U$ }+ N( `. `
/ m. o. `+ b8 a }
) B! p' o, g/ A% p' `9 E . L9 }# A U7 h' ]' p7 c
" ~9 `* o% v6 A8 Z3 M / Z8 {" i- W6 _( [- S
`% l3 c8 |* A9 I
0 v, }6 A, P" r
. w8 \1 j b% K. \ gen pminphddy240=`tempminphddy240' in 1
0 b- ]3 t: n3 H8 I% m h
x$ C/ H& _1 V. r8 B1 Y " q8 G6 [* g: ?/ F4 @' V8 Y
*-------------ddy240pminp右侧低峰值 -----------------
6 [. _+ e+ m' K preserve ; d& v# d. z: _: l
" c& }4 W5 W9 ] keep if dx240>`tempminp'7 V+ d6 ^3 X4 \* ], f7 e
7 c' |7 u1 j9 ]1 P, N2 U7 T
keep if dx240<`tempmaxp'! z$ Y8 L* E! P4 ?1 n
' z& |( ^9 d/ g" u8 x# n
keep if ddy240<0
0 a, v% _2 A: d2 O; H( F$ U) y% H , g7 k2 _& C6 o0 E' h8 w
gen temddy240=-ddy2404 b# ^1 n/ W$ [' i. `
, q0 \5 W& n S2 ~" W count
D, t, t# S/ m; a: y7 J* `: h
% B8 D, y7 I2 C( Z if r(N)>2 {% N, Z- u: Y; r- |( ?& @
/ i* j* M% J3 N
pkexamine dx240 temddy240
: J% M% t' h; k1 G; ?. A# \ 4 o/ K8 g- R* T7 [$ N t. y
local tempminplddy240=r(tomc)
: b1 d, A, S$ {' Q6 e restore
- f2 {( c& {1 f/ |" N1 U } q, y* g8 M( F) F
+ [ V7 b* E- [1 J7 T
else {/ r: H# F7 l; K5 p) f! B# I1 E
) a, B e: F. {. p0 e) r7 Q8 J1 L di "cannot find pminplddy240"" [ s z9 b4 Q% D2 w
restore
/ u1 m4 r6 B& d' T9 x
+ y, T+ I( ]# D( O sum dx240
% d5 S$ x+ M n% Z& `0 r) z) a5 I local tempminplddy240=r(mean)
6 k8 m6 V! p, R/ T, y8 a
% @3 _6 M7 a, b0 r* a/ t 0 c+ t' X3 q7 |3 `/ `
}
: C1 f; ^. [8 ~+ G9 x g2 v% X
6 Q4 |" `+ D' h- L. X
6 g- L% |9 H' h( o; L+ @
( h4 j" H% L7 a+ r# G2 Q * H( E# q: \2 S! U# v$ T- V
& G5 v: d. a+ U2 I
gen pminplddy240=`tempminplddy240' in 1
* u9 B& d2 I* `7 {1 g ( y$ O' ^4 U. v* V
*-------------ddy240pmaxp左侧高峰值 -------------------
* x! H+ T: w7 M, ?) d4 S
" g3 w7 w3 a4 c& q* J5 i preserve * X/ k$ ~$ h" C8 r5 _7 v" A
- b$ C' I7 s1 j. p8 f; \1 c) M# R5 O
keep if dx240>`tempminp'- c, Q% {3 F' e( Z: N9 H, B5 M, i
# v6 [6 Q& S \. t. D. K
keep if dx240<`tempmaxp'1 N) i4 d0 s7 ~! v7 ?6 r
7 A$ r( s: f0 e$ [# i- f
keep if ddy240>0* y1 p9 ~/ w5 n5 d* r7 u1 l; b; \
count* t) Q' T/ i, ]: L
# @+ \; F# N2 _8 x* }
if r(N)>2 {
* _( W& S. N [7 p * l7 I8 A: Z# I% Y& c" }6 d/ W8 W
pkexamine dx240 ddy240
; t4 B0 Q9 `8 w* v
- a5 W( `7 R- E7 P% p local tempmaxphddy240=r(tomc)
; v7 ?# H' _+ U$ @, `; [ L: ?6 c. q& E9 l
restore
8 n8 T5 Y+ A) | }1 R" m( j$ R0 o. |' n
' J" w& |8 d+ T% t, o+ V else {6 r. w/ I8 ] g' i
0 |! z- F4 H$ x+ b2 R; x di "cannot find pmaxphddy240"
. p: L# m4 Y5 O+ z. s5 ], A9 L restore
! {8 B t. n$ L% }# y- S 1 H( Y' R! S* n: W$ q
sum dx240
4 ?' i, P5 z) V4 _- R- S7 w local tempmaxphddy240=r(mean)
6 }$ r# v8 }. L& H- ^" _7 i, P, ]4 R 6 g' r% y# \, i( f# [, ?
- b8 O( z: X! @ i3 G. z }
, f/ W- t/ s& R; j ( q6 e* _, m1 {; i! i( R
' }6 {; D6 P9 y0 p! L# a* F
' T5 _/ K. u4 X3 W# M, H+ ]
" |" [% W7 o. A$ o: U) {- i
( u/ }5 j7 P& G; j* S: b ^9 C
' V' b/ {1 }4 O; {2 m( A" z gen pmaxphddy240=`tempmaxphddy240' in 1
5 u) v. z' K9 z- _% q
. ], U7 o+ g. T5 g5 v
E+ H( R! L$ h5 a *-------------ddy240pmaxp右侧低峰值 -------------------( C8 M' }4 K! P
7 l1 C& T8 T9 H5 Q2 Q2 `1 F5 x
preserve
& i ^* F& ^% p3 ^- B! i ( Y* f' A( t. P' {* G( S8 `% U
keep if dx240>`tempmaxp'" y1 O1 b: _9 y# [/ U
' W* ^" m/ U% r% N. ]( B* X( p
gen temddy240=-ddy240
# X5 ^! S; a8 Q
# G7 S% e: w8 c2 d# l/ B5 x keep if temddy240>0
D. H$ f+ h& R- ~4 S
8 C) F- z! @7 c count
4 {7 F4 h1 |; [# m
& [: |, a7 t' Z' x if r(N)>2 {
" z! m: d/ S6 H8 f: I: V. a! e
; V6 o z, {: e2 f" R pkexamine dx240 temddy240
/ b! i3 O* o( c1 ?/ g
' \) o' V) n; W1 ]& C local tempmaxplddy240=r(tomc)
( S" l6 n- n. U0 Z, o. W restore( f$ ~& B, l5 r/ Y/ G$ P9 r* a
}7 T# M. `* Y; D& H
3 u- `, f9 ?# s* ~3 W
else {4 c7 e1 b! U1 j( r
restore4 N, J% ]' n1 h2 e8 e6 r8 m4 n
di "cannot find pmaxlhddy240", ?8 ^- q* N- v
( Z2 i2 s7 b& G8 |
. `# `7 r/ Y8 M# X sum dx240
_& W! b% y) c% @. U local tempmaxplddy240=r(mean) in 19 @8 k, n- R) h& _& Y8 |
! J4 L. v0 V7 M8 l 8 ~+ R) Z8 E# E7 I- k5 Z) T
}
' U4 d1 d2 _; G6 z6 |1 V
, l; \9 {& B- I | 4 c$ W1 D( p& a X- R! u: f
; s* B U& ~: h5 r
# N7 i+ y+ E2 W- A
" U4 Y/ }* s5 `% c
. g2 e7 c0 ~1 V4 ?9 b" [: k+ Y( ` gen pmaxplddy240=`tempmaxphddy240' in 1
( `( P& |% _; |3 \
8 i5 R9 V* Z& D- u8 G *-------------------------------------: ^5 k# D+ L# l4 n: N3 R& T
* A% q. ^" @+ J( E/ n. P" y# a$ |
gen price5d=v5 in 1/20- ^& H7 q( k+ A1 L, f/ ^. U! B! P
0 j6 {) B5 |! k+ q gen price5yy=_n in 1/20
! b: s3 j$ V3 I6 B6 l! R & p6 c- t) {; i% q; }8 P
gen price5y=price5yy*(dy240max-dy240min)/20: D3 k6 U- @& E/ Z! \& m
. `6 r$ p6 {8 w7 o# L$ p *price5y &price5d
3 I5 ~# o. b- I: n
9 t9 I- z3 i0 \ ~3 w8 l gen priceny=price5y in 1
) u# t+ u* I+ k" s& F9 V( e ! G/ J# s- [6 f1 _0 D8 x1 O
gen pricen=v5 in 1
/ f- G. b; W* i, O$ G: E' n! m
, u( d3 a* Z% a+ j& S 1 @, O, W0 h$ B& [9 q2 z$ g7 |
*priceny &pricen5 ^+ R$ R& c% L$ u e& _
7 p$ q6 e0 T3 E2 v: c
3 V# L& y3 ?& E" a* b5 g! H *-------------------------graph------------------' N: Q7 U4 Q* u& D; G8 H2 b; o
" e; B ]! o1 V% M: U
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)* h$ v( F( N5 X- v5 P1 {
9 Y1 G/ z8 L+ ~6 O( A N* ---------可选项目----------------------1 l6 N S2 y9 @% E& `3 Y' P
$ c& j; ]) e2 r; Q}" ~+ g5 T' ~" Z, C4 F
end
) L0 f. v* u+ a% H |
|