1. Estimation method: Yule-walker Estimation
.
2. Operating environment Spyder2 (Python Scientific calculation editor)
3. Implementing the Code
#-*-coding:utf-8-*-ImportNumPy as NP#Create a package for an array#Set initial valueA=9F= Open ('/users/gaojiaxing/desktop/data.txt','a', encoding ='Utf-8') F.write ('time span'+' '+'P-Value'+' '+'Lamb Value'+' '+'p mean square error'+' '+'lamb mean square error'+' '+'Estimation of P'+' '+'Estimation of P'+' '+'Estimation of P'+' '+'Estimation of Lamb'+' '+'Estimation of Lamb'+' '+'Estimation of Lamb'+'\ n') F.close ()defSample_cov (alist,k):" "This function is used to calculate the self-covariance function of a sample" "N=Len (alist) sum1=0 forIinchRange (nk): Sum1= Sum1 + (Alist[i]-np.mean (alist)) * (alist[i+k]-Np.mean (alist))returnsum1/NdefCalc_lamb (alist):" "yule-walker Estimation of error term" "N=Len (alist) error_sum=0 forJinchRange (n-1): Error_sum= Error_sum + alist[j+1]-p*Alist[j]returnError_sum forTime_leninchRange (50,250,50):#Time Series Length forPinchNp.arange (0,1,0.1):#let the P-value take 0,0.1,0.2 ... 0.9 of all results forLambinchNp.arange (0.2,1.4,0.4):#Lamb Value 0.2,0.6,1claim_time_series= []#simulation of the final 1000 sets of time series stored here forIinchRange (1000): One_case= List (range (Time_len))#One_case is a claim time seriesONE_CASE[0] = Int (lamb/(1-p)) forJinchRange (1, Time_len): One_case[j]= (Np.random.binomial (one_case[j-1],p,size=1) +Np.random.poisson (Lamb*np.random.gamma (shape=a,scale=1/a,size=1))) [0] Claim_time_series.append (one_case) p_hat= []#The estimated value of P estimates based on the sample will be stored where forJinchRange (1000): P_hat.append (Sample_cov (claim_time_series[j),1)/Sample_cov (claim_time_series[j],0)) P_array= Np.array (p_hat). Reshape (1000)#convert to an array for easy operationP_mse= SUM ((p_array-p*np.ones (1000)) **2)/1000#mean square errorLamb_hat= [] forIinchRange (1000): Lamb_hat.append (Calc_lamb (claim_time_series[i])/(time_len-1)) Lamb_array= Np.array (lamb_hat). Reshape (1000) Lamb_mse= SUM ((lamb_array-lamb*np.ones (1000)) **2)/1000F= Open ('/users/gaojiaxing/desktop/data.txt','a', encoding ='Utf-8') F.write (str (time_len)+' '+STR (P) +' '+str (Lamb) +' '+str (P_MSE) +' '+Str (LAMB_MSE)+' '+str (P_array[0]) +' '+str (p_array[1]) +' '+str (p_array[2]) +' '+str (lamb_array[0])+' '+str (lamb_array[1]) +' '+str (lamb_array[2]) +'\ n') F.close ()
Inar (1) computer implementation of model parameter estimation