2-factor model

Estimates the model parameters of the 2-factor model presented in Schwartz-Smith (2000) paper(Short-Term Variations and Long-Term 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 sub-sample 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 Ornstein-Uhlenbeck model to be used as a benchmark. The Schwartz-Smith 2-factor model is then compared to the two one factor model by Log-L scores, LR test with p-values, 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/lup/publication/3809118