Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has...

12
Sistema de Predicción basado en el Promediado Bayesiano de Modelos. Aplicaciones en finanzas. Autor: Carlos Balduz Bernal. Director de proyecto: Carlos Maté Jiménez. RESUMEN El objetivo de este proyecto de fin de carrera es el de desarrollar una aplicación que permita realizar predicciones de calidad en mercados financieros empleando el Promediado Bayesiano de Modelos. La aplicación permitirá al usuario elegir la compañía de la cuál quiere obtener una predicción, para posteriormente introducir todos los parámetros necesarios para realizar la predicción. Por pantalla se mostrará el resultado de la predicción, así como algunas medidas de error y otros parámetros de utilidad. La aplicación está programada en su mayor parte en Java, pero también utiliza MATLAB para realizar la mayoría de los cálculos. PALABRAS CLAVE Predicción Bayesiana, series temporales, mercados financieros, predicción. INTRODUCCIÓN Forecasting system based on Bayesian Model Averaging. Applications in Finance Carlos Balduz Bernal II

Transcript of Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has...

Page 1: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

Sistema de Predicción basado en elPromediado Bayesiano de Modelos.Aplicaciones en finanzas.

Autor: Carlos Balduz Bernal.Director de proyecto: Carlos Maté Jiménez.

RESUMEN

El objetivo de este proyecto de fin de carrera es el de desarrollar una aplicaciónque permita realizar predicciones de calidad en mercados financieros empleandoel Promediado Bayesiano de Modelos. La aplicación permitirá al usuario elegir lacompañía de la cuál quiere obtener una predicción, para posteriormente introducirtodos los parámetros necesarios para realizar la predicción. Por pantalla se mostrará elresultado de la predicción, así como algunas medidas de error y otros parámetros deutilidad. La aplicación está programada en su mayor parte en Java, pero también utilizaMATLAB para realizar la mayoría de los cálculos.

PALABRAS CLAVE

Predicción Bayesiana, series temporales, mercados financieros, predicción.

INTRODUCCIÓN

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

II

Page 2: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

RESUMEN

Los mercados financieros juegan un papel muy importante en la economía y en

nuestra sociedad. Por ello, ser capaz de obtener predicciones precisas es de vital

importancia al tratar con estos mercados. El procedimiento habitual para realizar estas

predicciones es analizar los datos disponibles para tratar de averiguar qué modelo

produce los mejores resultados. Sin embargo, este procedimiento tiene asociado un

nivel de incertidumbre que normalmente es ignorado. La incertidumbre acerca de la

validez de un modelo que conlleva el elegir dicho modelo descartando todos los demás

es ignorada. El objetivo del Promediado Bayesiano de Modelos es promediar una serie

de modelos teniendo en cuenta la incertidumbre que llevan asociada, produciendo una

importante mejora en la calidad de las predicciones realizadas.

Hoy en día no existe ninguna aplicación que permita a un usuario realizar un

Promediado Bayesiano de Modelos de forma sencilla utilizando datos de mercados

financieros. Por este motivo, se ha considerado necesario desarrollar una aplicación

que permita, mediante una interfaz intuitiva y fácil de usar, obtener predicciones a un

usuario no experimentado.

METODOLOGÍA

Este proyecto de fin de carrera combina una amplia carga teórica y un desarrollo

práctico, por lo que se ha dividido en dos fases.

La primera etapa consistió en realizar un estudio exhaustivo de los mercados

financieros y las técnicas empleadas para realizar predicciones. Los diferentes modelos

utilizados, como por ejemplo los modelos ARIMA, fueron estudiados para comprender

su funcionamiento. En esta etapa también se estudió en detalle la metodología Bayesiana,

prestando especial atención al Promediado Bayesiano de Modelos.

En la segunda fase se llevó a cabo el desarrollo de la aplicación, poniendo así en

práctica todo lo estudiado durante la primera etapa. En primer lugar se desarrolló la

interfaz de usuario en el lenguaje Java, y más adelante se implementaron en MATLAB

los algoritmos necesarios para realizar el Promediado Bayesiano de Modelos. Por

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

III

Page 3: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

RESUMEN

último, se realizaron numerosos tests para comprobar el correcto funcionamiento de laherramienta.

RESULTADOS

El resultado de este proyecto de fin de carrera ha sido la aplicación descritaanteriormente. A continuación se muestran algunas imágenes de la aplicación y seexplica su funcionamiento básico.

Al ejecutar la aplicación, el usuario puede elegir de entre distintos Índices bursátilesla compañía con la que quiere trabajar. Una vez seleccionada, se muestra una gráficacon los precios de cierre de esa compañía, así como una tabla con informaciónacerca de dichos precios y algunas medidas estadísticas como la media, la moda ola mediana. Además, el usuario puede ver la función de autocorrelación o la función deautocorrelación parcial para el período que elija.

Figura 1. Pantalla principal de la aplicación

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

IV

Page 4: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

RESUMEN

Una vez seleccionada, se pulsa sobre el botón "Forecast"para introducir losparámetros necesarios para realizar la predicción. El usuario debe añadir los modelosque quiere promediar utilizando el Promediado Bayesiano de Modelos, indicando laprobabilidad a priori de cada uno de ellos y, en caso de ser un modelo que utilizavariables explicativas, el fichero en el que se encuentran almacenados los valores dedicha variable.

Posteriormente, la aplicación realiza los cálculos necesarios y presenta una pantallacon los resultados de la predicción en el periodo de prueba, como se puede ver en lasiguiente imagen:

Figura 2. Resultados durante el periodo de prueba

Por último, al pulsar sobre el botón “Continue", se muestran los resultados de lapredicción un periodo por delante. Además, en esta pantalla el usuario tiene la opción deguardar los pesos a posteriori obtenidos para utilizarlos como pesos a priori en futuraspredicciones.

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

V

Page 5: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

RESUMEN

Figura 3. Resultado de la predicción

CONCLUSIONES

Se ha conseguido el desarrollo de una aplicación que permite realizar prediccionesen mercados financieros utilizando el Promediado Bayesiano de Modelos a usuarios noexperimentados con una interfaz sencilla y bastante intuitiva. Además, se han realizadonumerosos tests para comprobar el correcto funcionamiento de la herramienta.

Gracias a la herramienta desarrollada en este proyecto, se ha podido comprobar cómoel Promediado Bayesiano de Modelos es capaz de mejorar las predicciones al emplearmodelos que utilizan variables explicativas. En cuanto a los modelos que no empleanvariables explicativas, como por ejemplo los modelos ARMA, se ha comprobado que laefectividad del Promediado Bayesiano de Modelos depende de los datos en sí, por loque no se puede afirmar en general si el Promediado Bayesiano de Modelos mejora oempeora las predicciones, ya que dependerá de cada caso.

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

VI

Page 6: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

RESUMEN

REFERENCIAS

[Fabo08] Svetlozar T. Rachev, John S. J. Hsu, Biliana S. Bagasheva, Frank

J. Fabozzi, Bayesian Methods in Finance, John Wiley & Sons, NewYork 2009.

[Makr98] Spyros Makridakis, Steven C. Wheelwright, Rob J. Hyndman,Forecasting. Methods and applications, John Wiley & Sons, New York1998.

[Masi08] Rumi Masiha, A. Mansurb, M. Masihb, Kilian Miec, Modeluncertainty and asset return predictability: an application of Bayesianmodel averaging, Applied Economics, iFirst, pp. 1-10, 2008.

[Maté09] Carlos Maté, The Bayesian approaches to combining forecasts. Somecomments for inflation forecasting, Conference at Lancaster University,2009.

[Rupp04] Rupp, A.A., Dey, D.K. and Zumbo, B.D., To Bayes or Not to Bayes,From Whether to When: Applications of Bayesian Methodology toModeling, Structural Equation Modeling: A Multidisciplinary Journal,11 (3), pp. 424-451, 2004.

[Tsay05] Ruey S. Tsay, Analysis of Financial Time Series, John Wiley & Sons,New York 2004.

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

VII

Page 7: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

Forecasting system based onBayesian Model Averaging.Applications in Finance.

Author: Carlos Balduz Bernal.Project director: Carlos Maté Jiménez.

ABSTRACT

The objective of this final degree project is to develop a software tool that allows theuser to make accurate forecasts in finantial markets using Bayesian Model Averaging.This tool will allow the user to choose the company to be forecasted and later introducethe required parameters to make the forecast. The forecast results will be displayed onscreen with other useful parameters such as accuracy measures. The tool is programmedin Java, but it also implements MATLAB algorithms to perform calculations.

KEY WORDS

Bayesian forecasting, financial time series, financial markets, forecasting.

INTRODUCTION

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

VIII

Page 8: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

ABSTRACT

Financial markets play a very important economic and social role in our society.Therefore, being able to produce more accurate forecasts is of vital importancewhen dealing with these markets. The usual procedure to make these forecasts isto analyze the given data and find out which model works best. However, these aspectsinvolve some degree of uncertainty that is usually ignored. The objective of BayesianModel Averaging is to average a given set of models taking into account uncertaintysurrounding the validity of each model, producing more accurate forecasts.

Nowadays there is no software tool that allows the user to make a BMA easily usingdata from financial markets. For this reason, the objective of this project is to develop atool with an interface as user-friendly as possible that allows a user with no previousknowledge to make forecasts using BMA.

METHODOLOGY

This project is divided into two stages, being the first one the exhaustive researchof the methods that are used throughout the project. In this first stage, the first stepwas the familiarization with financial markets and the different existing models tomake forecasts, such as ARIMA models. Secondly, a thorough study of the Bayesianmethodology to understand its basics, focusing on Bayesian Model Averaging.

The second stage was the development of the software tool, which was divided intothree steps. The first one was the design of the user interface in Java. The next step wasprogramming the algorithms in MATLAB to perform the calculations. Finally, the laststep was testing the software.

RESULTS

The result of this final degree project is the tool described earlier.

Once the BMAFM.jar file has been executed, the main window where the usercan select the data is displayed. From this window, the user can select an index anda company from that index to load the data. Once the company has been selected,

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

IX

Page 9: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

ABSTRACT

information such as close prices or the volume for a given date is displayed in a

table. Moreover, summary statistics for the selected company are also calculated. The

autocorrelation function or partial autocorrelation function for a given time period can

also be calculated.

Figure 4. BMA main screen

Once the company the user wants to work with has been selected, the next step is to

set up the configuration for the forecast. Clicking the Forecast button will display a new

window where the user must choose the models he wants to work with, the benchmark

model and other parameters needed to make the forecast. The user must add the models

that will be averaged using BMA, indicating the prior probability for each of them and,

in case the selected model uses explanatory variables, the file where the values for the

variable are stored.

When the Forecast button is pressed, a new window showing the results in the

testing set is displayed:

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

X

Page 10: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

ABSTRACT

Figure 5. Results in the testing set

Finally, a window with the results for a one-step ahead forecast is shown. In thiswindow, the user can save the posterior probabilities by pressing the Save config button.

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

XI

Page 11: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

ABSTRACT

Figure 6. Forecast result

CONCLUSIONS

The development of a software tool that allows user with no previous knowledge tomake forecasts in financial markets using Bayesian Model Averaging has been achieved.Moreover, several tests have been carried out to check that the tool works correctly.

With the tool developed in this project, it has been proved that Bayesian ModelAveraging improves the accuracy of forecasts when averaging models that useexplanatory variables. As for models that do not use explanatory variables, suchas ARMA models, it has been proved that the efficiency of Bayesian Model Averagingdepends entirely on the data.

REFERENCES

[Fabo08] Svetlozar T. Rachev, John S. J. Hsu, Biliana S. Bagasheva, Frank

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

XII

Page 12: Sistema de Predicción basado en el Promediado Bayesiano de ... · Once the BMAFM.jar file has been executed, the main window where the user ... window where the user must choose

MEMORY

J. Fabozzi, Bayesian Methods in Finance, John Wiley & Sons, New

York 2009.

[Makr98] Spyros Makridakis, Steven C. Wheelwright, Rob J. Hyndman,

Forecasting. Methods and applications, John Wiley & Sons, New York

1998.

[Masi08] Rumi Masiha, A. Mansurb, M. Masihb, Kilian Miec, Modeluncertainty and asset return predictability: an application of Bayesianmodel averaging, Applied Economics, iFirst, pp. 1-10, 2008.

[Maté09] Carlos Maté, The Bayesian approaches to combining forecasts. Somecomments for inflation forecasting, Conference at Lancaster University,

2009.

[Rupp04] Rupp, A.A., Dey, D.K. and Zumbo, B.D., To Bayes or Not to Bayes,From Whether to When: Applications of Bayesian Methodology toModeling, Structural Equation Modeling: A Multidisciplinary Journal,

11 (3), pp. 424-451, 2004.

[Tsay05] Ruey S. Tsay, Analysis of Financial Time Series, John Wiley & Sons,

New York 2004.

Forecasting system based on Bayesian Model Averaging. Applications in FinanceCarlos Balduz Bernal

XIII