|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
求教大神:
9 S1 P9 ~& D i2 _function f=nsllh(x)5 \8 N8 F% }! a' Y
close=xlsread('HW_3_Part2Data','#3','D3 1257');
2 Z P8 Y7 p9 i( envix=xlsread('HW_3_Part2Data','#3','H4:H1257');
- A# p/ E" R' v6 ~; l& n8 X: Lalpha=zeros(1,1);beta=zeros(1,1);theta=zeros(1,1);gamma=zeros(1,1);0 n. t, ~6 `% g/ y0 O6 U7 a
x=[alpha,beta,theta,gamma];
+ @# t3 w8 S0 G$ e" ]r=zeros(1254,1);7 G! _2 c) p7 j" ^: [
for i=1:12547 t* s5 O$ U# t; w7 ~4 n) i- j; p
r(i+1,1)=log(close(i+1,1)/close(i,1));* R" t% w# Q% X9 i
end* N1 c: [4 C1 _
sigma=var(r);
( Z h7 y i; d0 j7 e5 E- D" Somega=sigma*(1-alpha*(1+theta^2)-beta);: x/ n3 G9 W( P; A. s* Y
npsigma=ones(1254,1);
" x1 y; J6 i- {$ n$ h1 n! Gnpsigma(1,1)=sigma;
- x2 x I1 F8 O5 K8 ?7 E L; J# Afor i=1:1253
+ Y9 o- ]; @ f. ~# t1 n+ e# Cnpsigma(i+1,1)=omega+alpha*(r(i,1)-theta*npsigma(i,1)^0.5)^2+beta*npsigma(i,1)+gamma*nvix(i,1)^2/252;
8 |2 s$ J$ i" }, e uend# g1 X* r6 h# X. @. m, S. ?
alpha=x(1);beta=x(2);theta=x(3);gamma=x(4);
0 i' h, b9 J, [2 Rfor i=1:1254
) z2 C1 e- Z" z5 fnllh(i,1)=0.5*log(2*3.1415926)+0.5*log(npsigma(i,1))+0.5*(r(i,1)^2/npsigma(i,1));/ @6 q# V& o1 c* p& F* A2 }
end; W# D3 n- R# j0 ], H1 p$ z/ o$ \
f=sum(nllh); W: M8 g: H3 {; g- M1 ^7 w2 A) @
, R* y+ X$ x, j. L( z4 F: m
另外nonlcon的code是:; `7 k# t! `! K6 g
function [c,ceq]=mycon(x)
. n8 f- x" B3 a( q6 @( s8 H2 g& K& Galpha=zeros(1,1);beta=zeros(1,1);theta=zeros(1,1);0 n0 c V0 M+ e6 q! y+ r+ c
x=[alpha,beta,theta];' t( J& R% X- {% W) q
c=alpha*(1+theta^2)+beta-1;' E4 g4 E. |8 s* z
ceq=[];
/ {# \8 U: z5 J, g( i
3 q3 Y; Y @6 erun出来显示:$ s) w6 [8 w7 R0 m
x0=[0.04;0.5;2;0.07];
1 n' H# ~# |# p8 v9 _Optimization terminated: first-order optimality measure less7 [) t7 g- e& d5 T
than options.TolFun and maximum constraint violation is less+ P. A+ f6 `( y
than options.TolCon.
; x, D/ T' g G6 ]* DNo active inequalities.6 x# o& R- ?6 Z) r- @$ z0 {
' Q0 P8 @2 Z7 A8 s* [x =- \5 h8 E5 ^; O0 C
7 x" R8 a" U+ U9 k: V* @
0.04005 z9 i+ _% T7 u$ g/ H4 E* q7 J+ j: Y
0.50003 R! i+ {$ B2 v! l& b* p! M
2.0000
- E0 W E- z% W% u! V 0.0700
0 U. [8 _5 z3 M7 f8 U. P/ v; i% q$ s$ p' p* u
1 B q" ^9 c0 | G8 k" |% L0 Y3 ufval =
0 W, ~ j# M. L! P! W" S
6 _4 O( s8 Q& y$ V: |+ o ]" [-3.6963e+003* x B1 R0 I% o# s: w
- T' l1 H: ~, K: c4 g- \- q6 T
+ u4 t$ m- } Q0 b3 C2 Y+ E5 U6 B
exitflag =
/ q! m( ^8 J' a9 r5 @3 M7 B5 a% I& y/ h
13 \: w! n3 }3 B6 H6 L. U% j6 l8 e
( L1 A( v) O* ~
/ Z/ G& O+ |9 N6 V1 b+ woutput =
5 E7 @& U# L+ h. [! z; l9 }- s& ?6 A9 W- \+ c* F
iterations: 14 h! V; ~# N; { S+ U. V! t
funcCount: 10
! Y) n- `8 S% p* A7 k; i% d% Q stepsize: 1
1 c& M4 A& w* F5 S6 p6 ^; |) N algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'5 ?" n$ f& O+ o) K1 B! N7 C. U
firstorderopt: 09 _# [& u2 p( V: a' B
cgiterations: []
: G- e$ y* d- e message: [1x144 char]( D; c9 [& K! G$ w6 ?- ^. }
& i+ P$ O! h- @# V; ~
3 S1 g0 q8 z9 S; Jlamda =
; b' I! j9 R1 B- r. Z' Q8 s! ]' k: z o1 X% ^% N6 X
lower: [4x1 double]
/ D3 k9 P3 j/ n, o. H upper: [4x1 double]- ~9 ^/ _9 W8 }9 ?3 X+ g$ U6 d: s% b
eqlin: [1x0 double]
" A# T! ?4 Y8 ~- i! `4 T eqnonlin: [1x0 double]
* `3 Y& ~1 |4 b8 J; Y! [ ineqlin: [1x0 double]: b& [, N; O0 |) P
ineqnonlin: 0+ k+ Z* Y* \% `/ D9 K0 ]
) d5 X( b, p1 c4 K9 c7 y4 _9 t2 a为什么会这样呢?fval已经改变了但是x不会变?而且iteration只有18 Q2 [5 A& ~3 W6 Y, g. r: j2 `) r
0 n5 i4 V5 b+ D4 O% T |
|