Estimates the model parameters of the 2factor model presented in SchwartzSmith(2000) paper(ShortTerm Variations and LongTerm Dynamics in Commodity Prices) using MLE and the Kalman filter. Basted on the estimated parameters the two factors are then generated.
This code allow the user to easy select different data frequency based on supplied daily data, estimate the model on a subsample of the supplied total dataset, add or remove some of the future contracts from the supplied dataset in the estimation, select initial guesses for the parameters and initial sates.
This code also runs the estimation for a geometric Brownian motion model and a OrnsteinUhlenbeck model to be used as a benchmark. The SchwartzSmith 2factor model is then compared to the two one factor model by LogL scores, LR test with pvalues, and statistics of the errors between the generated future curve and the observed one (mean error, mean absolute error, standard deviation of error).
The two state variables are the finally presented in a graph (see the screen shot).
This code was written to enable the study in my Masters Degree Thesis: http://www.lunduniversity.lu.se/o.o.i.s?id=24965&postid=3809118
Approximately the same Crude Oil
data as used in SchwartzSmith(2000) is supplied.
