1

I tried to use the MLE method to estimate the parameters of an actuarial model (the Vasicek model) which is similar to the GARCH model (similar in the fact that in both models there are 3 parameters whose value needs to be guessed using MLE).

I know how to find the optimal values of these parametres in Microsoft's Excel Solver, but unfortunately I am unable to solve this problem in Python nor in R.

I tried to use several articles in order to search iteratively to find those parameters in the model that maximize the object function using python, but they didn't help me.

I'll be happy if someone can explain me what I need to do in order to solve this maximization problem. Thanks in advance

import numpy as np
from numpy import random as rn
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
import scipy.stats as si
from scipy import stats
from scipy.stats import norm
from scipy.optimize import minimize

a = 0.2
b = 0.2
σ = 0.2

def NORMDIST(x , mean , sd):
NORMDIST = si.norm.pdf(x , mean , σ)
return(NORMDIST)

r = np.array([0.0025, 0.0025, 0.001 , 0.001 , 0.001 , 0.001 , 0.001 , 0.001,
0.001 , 0.001 , 0.001 , 0.001 , 0.001 , 0.001 , 0.001 , 0.001 ,
0.001 , 0.001 , 0.001 , 0.001 , 0.001 , 0.001 , 0.001 , 0.001 ,
0.001 , 0.001 , 0.0035, 0.0075, 0.0075, 0.0125, 0.02  , 0.02  ,
0.0275, 0.0325, 0.0325, 0.0375])

r1 = r
index = -1
r1 = np.delete(r1, index)
r1 = np.insert(r1,0,0)

dr = r-r1
index = 0
dr = np.delete(dr, index)

r1 = np.delete(r1, index)

mr = a*(b-r1)

dr_mr = dr - mr

pdf = NORMDIST(dr_mr , 0 , σ)

ln_pdf = np.log(pdf)

data = r1 + dr - mr 

def likelihood(params,data):
a, b, σ = params
return norm.logpdf(data,loc=0,scale=params[1]).sum()

def neglikelihood(params,data):
return -1*likelihood(params,data)

result = minimize(neglikelihood,[0.2,0.2,0.2],args=(data))
result

0 Answers0