void cArch::ComputeHess(uint theDate, const cRegArchValue& theData, cRegArchGradient& theGradData, cRegArchHessien& theHessData, cAbstResiduals* theResiduals) { theHessData.mCurrentHessVar = 0.0L; uint myp = mvArch.GetSize(); uint myBegIndex = theGradData.GetNMeanParam(); register uint i,j,k; for (i = 0; i < MIN(myp, theDate); i++) theHessData.mCurrentHessVar -= 2.*mvArch[i] * theData.mUt[theDate -i-1]* theHessData.mHessMt[i]; for (k = 0; k < MIN(myp, theDate); k++) for (i = 0; i < theHessData.mCurrentHessVar.GetNRow(); i++) for (j = 0; j < theHessData.mCurrentHessVar.GetNCol(); j++) theHessData.mCurrentHessVar[i][j] += 2 * mvArch[k] * theGradData.mGradMt[k][i] * theGradData.mGradMt[k][j]; for (i = 0; i < MIN(myp, theDate); i++) for (j = 0; j < theHessData.mCurrentHessVar.GetNCol(); j++) theHessData.mCurrentHessVar[1+i][j] -= 2 * theData.mUt[theDate -i-1] * theGradData.mGradMt[i][j]; for (i = 0; i < theHessData.mCurrentHessVar.GetNCol(); i++) for (j = 1; j <= MIN(myp, theDate); j++) theHessData.mCurrentHessVar[i][1+j] -= 2 * theData.mUt[theDate - j] * theGradData.mGradMt[j][i]; }
void cArch::ComputeGrad(uint theDate, const cRegArchValue& theValue, cRegArchGradient& theGradData, cAbstResiduals* theResiduals) { uint myp = mvArch.GetSize() ; theGradData.mCurrentGradVar = 0.0L ; uint myBegIndex = theGradData.GetNMeanParam() ; theGradData.mCurrentGradVar[myBegIndex] = 1.0 ; register uint i ; for (i = 1 ; i <= MIN(myp, theDate) ; i++) theGradData.mCurrentGradVar[myBegIndex+i] = theValue.mUt[theDate - i]*theValue.mUt[theDate - i] ; for (i = 1 ; i <= MIN(myp, theDate) ; i++) theGradData.mCurrentGradVar -= 2.0 * mvArch[i-1] * theValue.mUt[theDate - i] * theGradData.mGradMt[i-1] ; }
void cTarch::ComputeGrad(int theDate, const cRegArchValue& theValue, cRegArchGradient& theGradData, cAbstResiduals* theResiduals) const { int myp = (int)mvArchPos.GetSize() ; theGradData.mCurrentGradVar = 0.0L ; int myBegIndex = (int)theGradData.GetNMeanParam() ; theGradData.mCurrentGradVar[myBegIndex] = 1.0 ; register int i ; for (i = 1 ; i <= MIN(myp, theDate) ; i++) if (theValue.mUt[theDate-i] > 0) theGradData.mCurrentGradVar[myBegIndex+i] = theValue.mUt[theDate - i]*theValue.mUt[theDate - i] ; else theGradData.mCurrentGradVar[myBegIndex+myp+i] = theValue.mUt[theDate - i]*theValue.mUt[theDate - i] ; for (i = 1 ; i <= MIN(myp, theDate) ; i++) if (theValue.mUt[theDate-i] > 0) theGradData.mCurrentGradVar -= 2.0 * mvArchPos[i-1] * theValue.mUt[theDate - i] * theGradData.mGradMt[i-1] ; else theGradData.mCurrentGradVar -= 2.0 * mvArchNeg[i-1] * theValue.mUt[theDate - i] * theGradData.mGradMt[i-1] ; }
void cConstCondVar::ComputeGrad(int theDate, const cRegArchValue& theValue, cRegArchGradient& theGradData, cAbstResiduals* theResids) const { theGradData.mCurrentGradVar[theGradData.GetNMeanParam()] = 1.0 ; }
void cAparch::ComputeGrad(int theDate, const cRegArchValue& theValue, cRegArchGradient& theGradData, cAbstResiduals* theResiduals) const { int myp = (int)mvArch.GetSize(), myq = (int)mvGarch.GetSize() ; theGradData.mCurrentGradVar = 0.0L ; int myBegIndex = (int)theGradData.GetNMeanParam() ; double myDeltaDiv2 = mvDelta/2.0 ; /* derivative with respect to the constant */ theGradData.mCurrentGradVar[myBegIndex++] = 1.0 ; register int i ; /* derivative with respect to Delta */ theGradData.mCurrentGradVar[myBegIndex] = 0.0 ; for (i = 1 ; i <= MIN(myp, theDate) ; i++) { double myTemp1 = abs(theValue.mUt[theDate-i]) - mvGamma[i-1]*theValue.mUt[theDate-i], myTemp2 = pow(myTemp1, mvDelta) ; theGradData.mCurrentGradVar[myBegIndex] += mvArch[i-1]* log(myTemp1) * myTemp2 ; } for (i = 1 ; i <= MIN(myq, theDate) ; i++) { double myTemp1 = pow(theValue.mHt[theDate-i], myDeltaDiv2) ; theGradData.mCurrentGradVar[myBegIndex] += mvGarch[i-1] * myTemp1 * log(theValue.mHt[theDate-i])/2.0 ; } /* derivative with respect to Arch */ for (i = 1 ; i <= MIN(myp, theDate) ; i++) { double myTemp1 = abs(theValue.mUt[theDate-i]) - mvGamma[i-1]*theValue.mUt[theDate-i], myTemp2 = pow(myTemp1, mvDelta) ; theGradData.mCurrentGradVar[myBegIndex+i] = myTemp2 ; } /* derivative with respect to Gamma */ myBegIndex += myp ; for (i = 1 ; i <= MIN(myp, theDate) ; i++) { double myTemp1 = abs(theValue.mUt[theDate-i]) - mvGamma[i-1]*theValue.mUt[theDate-i], myTemp2 = pow(myTemp1, mvDelta) ; theGradData.mCurrentGradVar[myBegIndex+i] = -mvArch[i-1] * mvDelta * theValue.mUt[theDate-i] * myTemp2/myTemp1 ; } /* derivative with respect to Garch */ myBegIndex += myp ; for (i = 1 ; i <= MIN(myq, theDate) ; i++) theGradData.mCurrentGradVar[myBegIndex+i] = pow(theValue.mHt[theDate-i], myDeltaDiv2) ; /* Need now to add the derivatives with respect to u(t-i) and h(t-j) */ for ( i = 1 ; i <= MIN(myp, theDate) ; i++) { double myTemp1 = abs(theValue.mUt[theDate-i])/theValue.mUt[theDate-i] - mvGamma[i-1], myTemp2 = pow(myTemp1, mvDelta-1) ; theGradData.mCurrentGradVar -= mvArch[i-1] * mvDelta * myTemp1 * theGradData.mGradMt[i-1] ; } for ( i = 1 ; i <= MIN(myq, theDate) ; i++) { double myTemp1 = mvGarch[i-1] * myDeltaDiv2 * pow(theValue.mHt[theDate-i], myDeltaDiv2 - 1.0) ; theGradData.mCurrentGradVar += myTemp1 * theGradData.mGradHt[i-1] ; } /* we computed d(ht^Delta/2)/dTheta, we need to compute dht.dTheta */ myBegIndex = (int)theGradData.GetNMeanParam() + 1 ; // We get the index of Delta double myAux = theGradData.mCurrentGradVar[myBegIndex] ; /* Correct formula for all parameters except Delta */ double myTemp = pow(theValue.mHt[theDate], myDeltaDiv2-1) ; theGradData.mCurrentGradVar /= myDeltaDiv2 * myTemp ; /* For Delta */ theGradData.mCurrentGradVar[myBegIndex] = (myAux - 0.5*log(theValue.mHt[theDate]) * myTemp * theValue.mHt[theDate])/(myDeltaDiv2 * myTemp) ; }
void cAparch::ComputeGrad(uint theDate, const cRegArchValue& theData, cRegArchGradient& theGradData, cAbstResiduals* theResiduals) { uint myp =mvArch.GetSize(), myq = mvGarch.GetSize(), myBegIndex = theGradData.GetNMeanParam() ; theGradData.mCurrentGradVar = 0.0 ; double myDeltaDiv2 = mvDelta/2.0 ; /* dérivée par rapport à la constante */ theGradData.mCurrentGradVar[myBegIndex++] = 1.0 ; register uint i ; /* dérivée par rapport à Delta */ theGradData.mCurrentGradVar[myBegIndex] = 0.0 ; for (i = 1 ; i <= MIN(myp, theDate) ; i++) { double myTemp1 = abs(theData.mUt[theDate-i]) - mvGamma[i-1]*theData.mUt[theDate-i], myTemp2 = pow(myTemp1, mvDelta) ; theGradData.mCurrentGradVar[myBegIndex] += mvArch[i-1]* log(myTemp1) * myTemp2 ; } for (i = 1 ; i <= MIN(myq, theDate) ; i++) { double myTemp1 = pow(theData.mHt[theDate-i], myDeltaDiv2) ; theGradData.mCurrentGradVar[myBegIndex] += mvGarch[i-1] * myTemp1 * log(theData.mHt[theDate-i])/2.0 ; } /* d�riv�e par rapport � Arch */ for (i = 1 ; i <= MIN(myp, theDate) ; i++) { double myTemp1 = abs(theData.mUt[theDate-i]) - mvGamma[i-1]*theData.mUt[theDate-i], myTemp2 = pow(myTemp1, mvDelta) ; theGradData.mCurrentGradVar[myBegIndex+i] = myTemp2 ; } /* d�riv�e par rapport � Gamma */ myBegIndex += myp ; for (i = 1 ; i <= MIN(myp, theDate) ; i++) { double myTemp1 = abs(theData.mUt[theDate-i]) - mvGamma[i-1]*theData.mUt[theDate-i], myTemp2 = pow(myTemp1, mvDelta) ; theGradData.mCurrentGradVar[myBegIndex+i] = -mvArch[i-1] * mvDelta * theData.mUt[theDate-i] * myTemp2/myTemp1 ; } /* d�riv�e par rapport � Garch */ myBegIndex += myp ; for (i = 1 ; i <= MIN(myq, theDate) ; i++) theGradData.mCurrentGradVar[myBegIndex+i] = pow(theData.mHt[theDate-i], myDeltaDiv2) ; /* Il faut maintenant rajouter les d�riv�es par rapport aux u(t-i) et h(t-j) */ for ( i = 1 ; i <= MIN(myp, theDate) ; i++) { double myTemp1 = abs(theData.mUt[theDate-i])/theData.mUt[theDate-i] - mvGamma[i-1] ; theGradData.mCurrentGradVar -= mvArch[i-1] * mvDelta * myTemp1 * theGradData.mGradMt[i-1] ; } for ( i = 1 ; i <= MIN(myq, theDate) ; i++) { double myTemp1 = mvGarch[i-1] * myDeltaDiv2 * pow(theData.mHt[theDate-i], myDeltaDiv2 - 1.0) ; theGradData.mCurrentGradVar += myTemp1 * theGradData.mGradHt[i-1] ; } /* on a calcul� d(ht^Delta/2)/dTeta ... Il faut calculer dht/dTeta */ myBegIndex = (int)theGradData.GetNMeanParam() + 1 ; // On recup�re l'indice de Delta double myAux = theGradData.mCurrentGradVar[myBegIndex] ; /* Formule valable pour tous les param�tres sauf Delta */ double myTemp = pow(theData.mHt[theDate], myDeltaDiv2-1) ; theGradData.mCurrentGradVar /= myDeltaDiv2 * myTemp ; /* Et pour Delta */ theGradData.mCurrentGradVar[myBegIndex] = (myAux - 0.5*log(theData.mHt[theDate]) * myTemp * theData.mHt[theDate])/(myDeltaDiv2 * myTemp) ; }