Financial Statistics and Econometrics: Homework 1

第一部分

  1. X_1,X_2,\cdots,X_n 为来自韦伯分布的独立同分布的随机样本,PDF 为:

f\left(x,\theta\right)=\left{\begin{array}{l}\frac\alpha\beta X^{\alpha-1}exp^{-X^\alpha/\beta},\;\;X\;>\;0\\0,\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;X\;\leq\;0\end{array}\right.

其中 \alpha\;>\;0,\;\beta\;>\;0 。假设 \alpha 已知,\beta 未知。

(a) 求 \beta 的极大似然估计量

极大似然函数为:
\mathrm L(\mathrm\theta\vert{\mathrm x}_1,{\mathrm x}_2,\cdots,{\mathrm x}_\mathrm n)=\prod_{\mathrm i=1}^\mathrm n\frac{\mathrm\alpha}{\mathrm\beta}{\mathrm X}_\mathrm i^{\mathrm\alpha-1}\mathrm e^{-\frac{\mathrm X^\mathrm\alpha}{\mathrm\beta}}
取极大似然函数的对数:
\mathrm{lnL}(\mathrm\theta\vert{\mathrm x}_1,{\mathrm x}_2,\cdots,{\mathrm x}_\mathrm n)=\mathrm{nln}\left(\mathrm\alpha\right)-\mathrm{nln}\left(\mathrm\beta\right)+\left(\mathrm\alpha-1\right)\sum_{\mathrm i=1}^\mathrm n\ln\left({\mathrm X}_\mathrm i\right)-\frac1{\mathrm\beta}\sum_{\mathrm i=1}^\mathrm n{\mathrm X}_\mathrm i^\mathrm\alpha
令:
\frac{\partial{\mathrm{lnL}(\mathrm\theta\vert{\mathrm x}_1,{\mathrm x}_2,\cdots,{\mathrm x}_\mathrm n)}}{\partial\mathrm\beta}=-\frac{\mathrm n}{\mathrm\beta}+\frac1{\mathrm\beta^2}\sum_{\mathrm i=1}^\mathrm n\mathrm X_\mathrm i^\mathrm\alpha=0

得:
\widehat{\mathrm\beta}=\frac1{\mathrm n}\sum_{\mathrm i=1}^\mathrm n\mathrm x_\mathrm i^\mathrm\alpha

(b) 上述极大似然估计量是无偏估计量吗?

\begin{array}{l}E(\widehat\beta)=E(\frac1n\sum_{i=1}^nX_i^\alpha)\\=\frac1n\sum_{i=1}^nE(X^\alpha)\\=\int_0^\infty X^\alpha\frac\alpha\beta X^{\alpha-1}e^{-\frac{X^\alpha}\beta}\operatorname dx\\=\frac\alpha\beta\int_0^\infty X^{2\alpha-1}\frac{-1}{\displaystyle\frac{\alpha X^{\alpha-1}}\beta}\operatorname de^{-\frac{X^\alpha}\beta}\\=-\int_0^\infty X^\alpha\operatorname de^{-\frac{X^\alpha}\beta}\\=-\left(\left[X^\alpha e^{-\frac{X^\alpha}\beta}\right]_0^\infty-\int_0^\infty e^{-\frac{X^\alpha}\beta}\operatorname dX^\alpha\right)\\=-\beta\int_0^\infty e^{-\frac{X^\alpha}\beta}\operatorname d\frac{-X^\alpha}\beta\\=-\beta\left[e^{-\frac{X^\alpha}\beta}\right]_0^\infty\\=\beta\\\end{array}

所以上述极大似然估计量是无偏估计量。

(c) 上述的极大似然估计量达到了 Cramer-Rao 下界了吗?

首先,计算该估计量的二阶矩:
\begin{array}{l}\begin{array}{l}E((\widehat\beta)^2)=E(\frac1{n^2}(\sum_{i=1}^nX_i^\alpha)^2)\\=\frac1{n^2}\sum_{i=1}^nE(X^{2\alpha})+{\textstyle\frac2{n^2}}(E(X^\alpha))^2\cdot(\frac{n(n+1)}2-n)\\=\frac1{n^2}\sum_{i=1}^nE(X^{2\alpha})+\frac{n-1}n\cdot(E(X^\alpha))^2\\=\frac1{n^2}\sum_{i=1}^nE(X^{2\alpha})+\frac{n-1}n\beta^2\\=\frac1n\int_0^\infty X^{2\alpha}\cdot\frac\alpha\beta\cdot X^{\alpha-1}\cdot e^{-\frac{X^\alpha}\beta}\operatorname dx+\frac{n-1}n\beta^2\\=\frac1n\int_0^\infty X^{3\alpha-1}\cdot\frac\alpha\beta\cdot\frac{-1}{\displaystyle\frac{\alpha X^{\alpha-1}}\beta}de^{-\frac{X^\alpha}\beta}+\frac{n-1}n\beta^2\\=-\frac1n\int_0^\infty X^{2\alpha}\operatorname de^{-\frac{X^\alpha}\beta}+\frac{n-1}n\beta^2\\=-\frac1n\left{\left[X^{2\alpha}\cdot e^{-\frac{X^\alpha}\beta}\right]_0^\infty-\int_0^\infty e^{-\frac{X^\alpha}\beta}\operatorname dX^{2\alpha}\right}+\frac{n-1}n\beta^2\\=\frac1n\int_0^\infty e^{-\frac{X^\alpha}\beta}\operatorname dX^{2\alpha}+\frac{n-1}n\beta^2\\=\frac2n\int_0^\infty X^\alpha\cdot e^{-\frac{X^\alpha}\beta}dX^\alpha+\frac{n-1}n\beta^2\end{array}\\=-\frac{2\beta^2}n\int_0^\infty\frac{X^\alpha}\beta de^{-\frac{X^\alpha}\beta}+\frac{n-1}n\beta^2\\=-\frac{2\beta^2}n\left{\left[\frac{X^\alpha}\beta\cdot e^{-\frac{X^\alpha}\beta}\right]_0^\infty-\int_0^\infty e^{-\frac{X^\alpha}\beta}\operatorname d\frac{X^\alpha}\beta\right}+\frac{n-1}n\beta^2\\=-\frac{2\beta^2}n+\frac{n-1}n\beta^2\\=\frac{(n+1)\beta^2}n\\\end{array}
其次,计算该估计量的方差:
\begin{array}{l}D(\widehat\beta)=E((\widehat\beta)^2)-(E(\widehat\beta))^2\\=\frac{(n+1)\beta^2}n-\beta^2\\=\frac{\beta^2}n\\\end{array}
然后,计算该估计量的方差的 *Cramer-Rao* 下界:
\begin{array}{l}\frac{\partial^2}{\partial\beta^2}\ln L\left(\left.\theta\right|X_1,X_2,\cdots,X_n\right)=\frac n{\beta^2}-\frac2{\beta^3}\sum_{i=1}^nX_i^\alpha\\E(\frac{\partial^2}{\partial\beta^2}\ln L\left(\left.\theta\right|X_1,X_2,\cdots,X_n\right))=\frac n{\beta^2}-\frac2{\beta^3}\cdot\sum_{i=1}^nE(X^\alpha)=-\frac n{\beta^2}\\-\frac1{nE(\frac{\partial^2}{\partial\beta^2}\ln L\left(\left.\theta\right|X_1,X_2,\cdots,X_n\right))}=-\frac1{n(-\frac n{\beta^2})}=\frac{\beta^2}{n^2}\end{array}
因为 D(\widehat\beta)>D(\widehat\beta)_{Cramer-Rao}

所以该极大似然估计量的方差未达到其 Cramer-Rao 下界。


  1. 一个有如下 PDF 随机变量:

f(X,\theta)=\frac1{\sqrt{2\pi}\sigma X}e^{-\frac{(\ln\left(X\right)-\mu)^2}{2\sigma^2}},\;0<\infty

称为对数正态 LN(\mu,\sigma^2) 随机变量,因为其对数 \ln\left(X\right) 服从正态分布。假设样本 X_1,X_2,\cdots,X_n 独立同分布来自上述分布,并且 \mu=0 ,其 \sigma^2 的估计量有两个:\widehat{\sigma^2}=n^{-1}\overset n{\underset{i=1}{\sum(}}\ln\left(X_i\right))^2S_n^2=(n-1)^{-1}\overset n{\underset{i=1}{\sum(}}\ln\left(X_i\right)-n^{-1}\sum_{i=1}^n\ln\left(X_i\right))^2 。请问上述两个估计量,哪一个更好,请给出推理过程。

答:我认为第一个估计量 \widehat{\sigma^2} 更好。推理过程如下:

(1) 首先证明 \widehat{\sigma^2}S_n^2 是否具有一致性。

对于 \widehat{\sigma^2}

根据切比雪夫不等式,对于任意 c>0 ,有:P(\left|\widehat{\sigma^2}-\sigma^2\right|\geq c)\leq\frac{Var(\widehat{\sigma^2})}{c^2}

因此,要证存在一个常数 c>0\lim_{n\rightarrow\infty}P(\left|\widehat{\sigma^2}-\sigma^2\right|\geq c)=0 , 只要证 \lim_{n\rightarrow\infty}D(\widehat{\sigma^2})=0
\begin{array}{l}\begin{array}{l}D(\widehat{\sigma^2})=E((\widehat{\sigma^2})^2)-(E(\widehat{\sigma^2}))^2\\=\frac1{n^2}E\left{\lbrack\sum_{i=1}^n(\ln\left(X_i\right))^2\rbrack^2\right}-\left{E\lbrack(\ln\left(X\right))^2\rbrack\right}^2\\=\frac1{n^2}\left{\sum_{i=1}^nE\lbrack(\ln\left(X\right))^4\rbrack+2\cdot\frac{n(n-1)}2\cdot\lbrack E((\ln\left(X\right))^2)\rbrack^2\right}-\left{E\lbrack(\ln\left(X\right))^2\rbrack\right}^2\\=\frac1nE\lbrack(\ln\left(X\right))^4\rbrack+\frac{n-1}n\cdot\lbrack E((\ln\left(X\right))^2)\rbrack^2-\left{E\lbrack(\ln\left(X\right))^2\rbrack\right}^2\\=\frac1nE\lbrack(\ln\left(X\right))^4\rbrack-\frac1n\left{E\lbrack(\ln\left(X\right))^2\rbrack\right}^2\end{array}\\=\frac1n\left(\mu^4+6\mu^2\sigma^2+3\sigma^4\right)-\frac1n\left(\sigma^2+\mu^2\right)^2\\=\frac2n\sigma^4+\frac4n\mu^2\sigma^2\end{array}

根据上述公式推导,可知 \lim_{n\rightarrow\infty}D(\widehat{\sigma^2})=0 , 所以 \widehat{\sigma^2}\sigma^2 的一致估计量。

对于 S_n^2

同样地,根据切比雪夫不等式,只要证 \lim_{n\rightarrow\infty}D(S_n^2)=0 即可。

根据题意,S_n^2 为修正样本方差。
\begin{array}{l}\because\;\frac{\left(n-1\right)S_n^2}{\sigma^2}\sim\chi²(n-1)\\\therefore\;D\left[\frac{\left(n-1\right)S_n^2}{\sigma^2}\right]=2(n-1)\\\because\;D\left[\frac{\left(n-1\right)S_n^2}{\sigma^2}\right]=\frac{\left(n-1\right)^2}{\sigma^4}D(S_n^2)\\\therefore D(S_n^2)=\frac{2\sigma^4}{n-1}\end{array}
根据上述公式推导,可知 \lim_{n\rightarrow\infty}D(S_n^2)=0 ,所以 S_n^2\sigma^2 的一致估计量。

(2) 下面证明 \widehat{\sigma^2}S_n^2 是否为 \sigma^2 的无偏估计量。

\begin{array}{l}\begin{array}{l}E(\widehat{\sigma^2})=E(\frac1n\sum_{i=1}^n((\ln\left(X_i\right))^2)\\=\frac1n\sum_{i=1}^nE((\ln\left(X\right))^2)\\=E((\ln\left(X\right))^2)\end{array}\\=\sigma^2+\mu^2\end{array}
因此,E(\widehat{\sigma^2})\neq\sigma^2 ,即 \widehat{\sigma^2} 不是 \sigma^2 的无偏估计量。
\begin{array}{l}\begin{array}{l}E(S_n^2)=E\lbrack(\frac1{n-1}\overset n{\underset{i=1}{\sum(}}\ln\left(X_i\right)-\frac1n\sum_{i=1}^n\ln\left(X_i\right))^2\rbrack\\=\frac1{n-1}\sum_{i=1}^n\cdot E\lbrack(\ln\left(X\right)-\frac1n\sum_{i=1}^n\ln\left(X_i\right))^2\rbrack\\=\frac n{n-1}E\lbrack(\ln\left(X\right))^2-2\ln\left(X\right)\frac1n\sum_{i=1}^n\ln\left(X_i\right)+\frac1{n^2}(\sum_{i=1}^n\ln\left(X_i\right))^2\rbrack\\=\frac n{n-1}\left{\mu^2+\sigma^2-\frac2n\left[(n-1)\mu^2+\mu^2+\sigma^2\right]+\frac1{n^2}\left[E(\sum_{i=1}^n\ln\left(X_i\right))\right]^2+\frac1{n^2}D(\sum_{i=1}^n\ln\left(X_i\right))\right}\end{array}\\=\frac n{n-1}\left[\mu^2+\sigma^2-\frac2n(n\mu^2+\sigma^2)+\frac1{n^2}(n\mu)^2+\frac1{n^2}n\sigma^2\right]\\=\frac n{n-1}\left[(1-\frac1n)\sigma^2\right]\\=\sigma^2\end{array}
因此, E(S_n^2)=\sigma^2 ,即 S_n^2\sigma^2 的无偏估计量。

(3) 分别判断 \widehat{\sigma^2}S_n^2 的有效性。
\begin{array}{l}D(\widehat{\sigma^2})-D(S_n^2)=\frac2n\sigma^4+\frac4n\mu^2\sigma^2-\frac2{n-1}\sigma^4=-\frac2{n(n-1)}\sigma^4+\frac4n\mu^2\sigma^2\end{array}
题目告知 \mu=0 ,所以 \begin{array}{l}D(\widehat{\sigma^2})-D(S_n^2)=-\frac2{n(n-1)}\sigma^4<0\end{array} ,即 \begin{array}{l}D(\widehat{\sigma^2})
\begin{array}{l}MSE(\widehat{\sigma^2})=E\lbrack(\widehat{\sigma^2}-\sigma^2)^2\rbrack\\=VAR(\widehat{\sigma^2})+\lbrack E(\widehat{\sigma^2})-\sigma^2\rbrack^2\\=\frac2n\sigma^4+\frac4n\mu^2\sigma^2+\mu^4\end{array}

\begin{array}{l}\begin{array}{l}MSE(S_n^2)=E\lbrack(S_n^2-\sigma^2)^2\rbrack\\=VAR(S_n^2)+\lbrack E(S_n^2)-\sigma^2\rbrack^2\end{array}\\=\frac2{n-1}\sigma^4\end{array}

MSE(\widehat{\sigma^2})-MSE(S_n^2)=-\frac2{n(n-1)}\sigma^4+\frac4n\mu^2\sigma^2+\mu^4

题目告知 \mu=0 ,所以 MSE(\widehat{\sigma^2})-MSE(S_n^2)=-\frac2{n(n-1)}\sigma^4<0 ,即 MSE(\widehat{\sigma^2})

综上所述,我认为第一个估计量 \begin{array}{l}\widehat{\sigma^2}\\\end{array} 更好。


第二部分

  1. Entering the follow into Python ,assigning each to a unique variable name.

(a) 4

(b) 3.1415

(c) 1.0

(d) 2+4j

(e) ‘hello’

(f) ‘world’

Program:

# -*- coding: utf-8 -*-
"""
Created on Sun Sep 16 18:17:44 2018
@author: Wengsway
"""
IntNumber = 4
FloatNumber_1 = 3.1415
FloatNumber_2 = 1.0
ComplexNumber = 2 + 4j
Str_1 = 'Hello'
Str_2 = 'World'
print('a =',IntNumber)
print('b =',FloatNumber_1)
print('c =',FloatNumber_2)
print('c =',ComplexNumber)
print('e =',Str_1)
print('f =',Str_2)

Answer:

In [46]: runfile('E:/Documents/HUST/Classes/20180913 - Financial_Statistics_and_Econometrics/20180916 -
Python Scripts/Homework_1_Part 2_1.py', wdir='E:/Documents/HUST/Classes/
20180913 - Financial_Statistics_and_Econometrics/20180916 - Python Scripts')
a = 4
b = 3.1415
c = 1.0
c = (2+4j)
e = Hello
f = World
In [47]:

  1. (a) Input the following mathematical expressions into Python as both arrays and matrices.

    • \begin{array}{l}u\;=\;\begin{pmatrix}1&1&2&3&5&8\end{pmatrix}\\\\\end{array}
    • \begin{array}{l}v\;=\begin{pmatrix}1\\1\\2\\3\\5\\8\end{pmatrix}\;\\\\\end{array}
    • \begin{array}{l}x\;=\;\begin{pmatrix}1&0\\0&1\end{pmatrix}\\\\\end{array}
    • \begin{array}{l}y\;=\;\begin{pmatrix}1&2\\3&4\end{pmatrix}\\\\\end{array}
    • \begin{array}{l}z\;=\;\begin{pmatrix}1&2&1&2\\3&4&3&4\\1&2&1&2\end{pmatrix}\\\\\end{array}
    • \begin{array}{l}w\;=\;\begin{pmatrix}x&x\\y&y\end{pmatrix}\\\\\end{array}

(b) Please calculate the transpose of u, and the inverse of x.

(c) What command would select x from w ?

(d) What command would select \begin{array}{l}\lbrack x’,y’\rbrack’\\\\\end{array} from w ? what command would select y from z ?

(e) Please calculate the term \begin{array}{l}(x’x)^{-1}x’y\\\\\end{array}

Program:

# -*- coding: utf-8 -*-
"""
Created on Sun Sep 16 18:40:25 2018

@author: Wengsway

"""

import numpy as np
import statsmodels.api as sm 

# The Answer of (a)
# Generate the array of u 
Array_u = np.array([1,1,2,3,5,8])
# Generate the array of v
Array_v = Array_u.reshape(-1,1)
# Generate a two-dimensional unit matrix and name it Matrix_x
Matrix_x = np.mat(np.eye(2,2,dtype=int))
# Generate a two-dimensional matrix and name it Matrix_y
Matrix_y = np.mat(np.arange(1,5).reshape(2,2),dtype=int)
# Generate a Matrix_z by combining two Matrix_y and a 1*4 matrix
Matrix_z = np.vstack((np.hstack((Matrix_y,Matrix_y)),np.mat((1,2,1,2))))
# Generate a matrix_w by combining the matrix_x and the matrix y
Matrix_w = np.tile(np.vstack((Matrix_x,Matrix_y)),2)
print('u =',"\n",Array_u)
print('v =',"\n",Array_v)
print('x =',"\n",Matrix_x)
print('y =',"\n",Matrix_y)
print('z =',"\n",Matrix_z)
print('w =',"\n",Matrix_w)

# The Answer of (b)
# Generate the transpose of u
Transpose_u = Array_u.reshape(6,1)
# Generate the inverse of Matrix_x
Inverse_x = (Matrix_x.I).astype(int)
print('Transpose of u =',"\n",Transpose_u)
print('Inverse of x =',"\n",Inverse_x)

# The Answer of (c)
# Selecting Matrix_x from Matrix_w 
Select_x = Matrix_w[0:2,0:2]
print('The x selected from w =',"\n",Select_x)

# The Answer of (d)
# Selecting [x',y']' from Matrix_w and name it comtranspose
Select_y_from_w = Matrix_w[2:,0:2]
Select_comtranspose = (np.hstack((Select_x.T,Select_y_from_w.T))).T
# Selecting Matrix_y from Matrix_z
Select_y_from_z = Matrix_z[0:2,0:2]
print('Select_comtranspose =',"\n",Select_comtranspose)
print('The y selected from z =',"\n",Select_y_from_z)

# The Answer of (e)
# Calculating the term (x'x)^(-1)x'y and name it Calculate_term
model = sm.OLS(Matrix_y,Matrix_x).fit()
print('Calculate_term =',"\n",model.params.astype(int))

Answer:

runfile('E:/Documents/HUST/Classes/20180913 - Financial_Statistics_and_Econometrics/20180916 - Homework/Homework 1/Homework_1_Part 2_2.py', wdir='E:/Documents/HUST/Classes/20180913 - Financial_Statistics_and_Econometrics/20180916 - Homework/Homework 1')
u = 
 [1 1 2 3 5 8]
v = 
 [[1]
 [1]
 [2]
 [3]
 [5]
 [8]]
x = 
 [[1 0]
 [0 1]]
y = 
 [[1 2]
 [3 4]]
z = 
 [[1 2 1 2]
 [3 4 3 4]
 [1 2 1 2]]
w = 
 [[1 0 1 0]
 [0 1 0 1]
 [1 2 1 2]
 [3 4 3 4]]
Transpose of u = 
 [[1]
 [1]
 [2]
 [3]
 [5]
 [8]]
Inverse of x = 
 [[1 0]
 [0 1]]
The x selected from w = 
 [[1 0]
 [0 1]]
Select_comtranspose = 
 [[1 0]
 [0 1]
 [1 2]
 [3 4]]
The y selected from z = 
 [[1 2]
 [3 4]]
Calculate_term = 
 [[1 2]
 [3 4]]

  1. 请下载最近一个月上证指数的数据,并输入至 Python 中,请算出其均值和方差。如果你可以的话,请画出其分布图。

Program:

# -*- coding: utf-8 -*-
"""
Created on Sun Sep 16 20:46:41 2018

@author: Wengsway

"""

# Tushare can get the data of SHIndex
import tushare as ts
import matplotlib.pyplot as plt
from matplotlib.pylab import datestr2num

# Get the data of '000001' in the most recent month 
df = ts.get_hist_data('sh',start='2018-08-13',end='2018-09-26')
# Turn data into ascending order
SHIndex = df.sort_index(axis = 0,ascending = True)
# Find the mean of the index
Mean_Index = SHIndex['close'].mean()
# Find the var of the index
Var_Index = SHIndex['close'].var()

# Produce a map of the index
x = range(len(df))
x_date = [datestr2num(i) for i in SHIndex.index]
plt.figure(figsize=(10,5))
plt.title('Shanghai Stock Exchange Index trend in the most recent month')
plt.xlabel('Time')
plt.ylabel('Index')
plt.plot_date(x_date,SHIndex['close'],'-',label = '000001' )
plt.hlines(2724.4306,'2018-08-13','2018-09-26',colors = 'r',linestyles = 'dashed')
plt.legend(labels = ['00001'],loc = 'best')
plt.show()

# Print some results
print('SHIndex_close =',"\n",SHIndex['close'])
print('Mean_Index =',round(Mean_Index,4))
print('Var_Index =',round(Var_Index,4))

Answer:

runfile('E:/Documents/HUST/Classes/20180913 - Financial_Statistics_and_Econometrics/20180916 - Homework/Homework 1/Homework_1_Part 2_3.py', wdir='E:/Documents/HUST/Classes/20180913 - Financial_Statistics_and_Econometrics/20180916 - Homework/Homework 1')

SHIndex_close = 
 date
2018-08-13    2785.87
2018-08-14    2780.96
2018-08-15    2723.26
2018-08-16    2705.19
2018-08-17    2668.97
2018-08-20    2698.47
2018-08-21    2733.83
2018-08-22    2714.61
2018-08-23    2724.62
2018-08-24    2729.43
2018-08-27    2780.90
2018-08-28    2777.98
2018-08-29    2769.29
2018-08-30    2737.74
2018-08-31    2725.25
2018-09-03    2720.73
2018-09-04    2750.58
2018-09-05    2704.34
2018-09-06    2691.59
2018-09-07    2702.30
2018-09-10    2669.48
2018-09-11    2664.80
2018-09-12    2656.11
2018-09-13    2686.58
2018-09-14    2681.64
2018-09-17    2651.79
2018-09-18    2699.95
2018-09-19    2730.85
2018-09-20    2729.24
2018-09-21    2797.48
2018-09-25    2781.14
2018-09-26    2806.81
Name: close, dtype: float64
Mean_Index = 2724.4306
Var_Index = 1871.068

![SHIndex Distribution Map](https://raw.githubusercontent.com/wengsway/Graphbed/master/img/SHIndex Distribution Map.png)

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*