Giter Club home page Giter Club logo

varfxi's Introduction

VaR-Rule for FX Interventions

Link to the Python notebook: https://github.com/romainlafarguette/VaR-FX-Interventions/blob/master/notebooks/VaR-FX%20Interventions.ipynb

The Python notebook replicates the tables and the charts of the IMF WP on "Foreign Exchange Interventions Rules for Central Banks: A Risk-Based Framework"

IMPORTANT: BECAUSE OF AN UPDATE OF THE ARCH PACKAGE AFTER 4.19, and in particular the random number generator, the way the random seed is managed has changed. Some results are therefore slightly different (e.g. the pdf plot) by a few pips as in the IMF WP, but are qualitatively similar. The journal version will reflect the new version

The paper uses a Python package that I have written, DistGARCH, also available in this Github folder, with the public FX intervention data from the Banco Mexico. DistGARCH is based on the ARCH package of Kevin Sheppard.

You can use the code for non-commercial applications, providing that you cite the IMF Working Paper Lafarguette, R. and Veyrune, R. (2020) "Foreign Exchange Interventions Rules for Central Banks: A Risk-Based Framework", IMF Working Paper

The folder is organized as follows:

  • mxn_estimation.py is the pure Python file with the core estimation and robustness analysis
  • VaR-FX Interventions.ipynb is a Jupyter notebook, which illustrates the approach
  • modules/ contains the modules for this project, in particular distGARCH which infers a conditional distribution from a GARCH model
  • data/ contains public data files, with FX rate and FX interventions from Banco Mexico website
  • img/ contains some images to illustrate the Jupyter Notebook

Reuse of this tool and IMF data does not imply any endorsement of the research and/or product. Any research presented should not be reported as representing the views of the IMF, its Executive Board, or member governments.

Note that the Github repo contains only publicly available data.

Author: Romain Lafarguette, August 2020

If you have any question, please contact me via Github or rlafarguette "at" imf "dot" org

varfxi's People

Contributors

romainlafarguette avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

matyasfarkas

varfxi's Issues

# Todo

  1. Refactor the actual E-GARCH code as a framework for volatility estimation
    a. distribution estimation
    b. train and test in and out of sample
    c. plot the distribution
    d. estimate the Value at Risk and derive the intervention rule

  2. Add the other modules
    a. MCMC Bayesian Estimation
    b. Quantile regression
    c. Separate Estimation of various degrees of moments

Forecast function is not executable

Hello! When trying to reproduce the code in the notebook, I encountered several issues. The main one is with the forecast function.

In the cell with the title Baseline GARCH Model: Fit and Forecast, there is a line dgfor = dgf.forecast('2020-01-01', horizon=1). If you try to run it, the following error turns up:

TypeError                                 Traceback (most recent call last)
<ipython-input-12-22a2564d592f> in <module>
     16 
     17 # Forecast 2020
---> 18 dgfor = dgf.forecast('2020-01-01', horizon=1)
     19 

~\Desktop\education\test\varfxi\modules\distGARCH.py in forecast(self, start_date, horizon, fmethod, sample_size)
    328     def forecast(self, start_date, horizon=1, fmethod='analytic',
    329                  sample_size=10000):
--> 330         return(DistGARCHForecast(self, start_date, horizon, fmethod,
    331                                  sample_size))
    332 

~\Desktop\education\test\varfxi\modules\distGARCH.py in __init__(self, DistGARCHFit, start_date, horizon, fmethod, sample_size)
    672 
    673         # Run the forecasts from the arch package
--> 674         self.forecasts = self.res.forecast(horizon=self.horizon, 
    675                                            start=self.start_date,
    676                                            method=self.fmethod)

c:\users\oleg\appdata\local\programs\python\python38\lib\site-packages\arch\univariate\base.py in forecast(self, params, horizon, start, align, method, simulations, rng, random_state, reindex, x)
   1504         if not isinstance(horizon, (int, np.integer)) or horizon < 1:
   1505             raise ValueError("horizon must be an integer >= 1.")
-> 1506         return self.model.forecast(
   1507             params,
   1508             horizon,

c:\users\oleg\appdata\local\programs\python\python38\lib\site-packages\arch\univariate\mean.py in forecast(self, params, horizon, start, align, method, simulations, rng, random_state, reindex, x)
    946         constant = arp[0] if self.constant else 0.0
    947         dynp = arp[int(self.constant) :]
--> 948         expected_x = self._reformat_forecast_x(x, horizon, start_index)
    949         mean_fcast = _ar_forecast(
    950             self._y, horizon, start_index, constant, dynp, expected_x, exog_p

c:\users\oleg\appdata\local\programs\python\python38\lib\site-packages\arch\univariate\mean.py in _reformat_forecast_x(self, x, horizon, start)
    799                 return np.empty(0)
    800             else:
--> 801                 raise TypeError(
    802                     "x is None but the model contains exogenous variables. You must "
    803                     "provide expected values to use for the exogenous variables to "

TypeError: x is None but the model contains exogenous variables. You must provide expected values to use for the exogenous variables to construct forecasts.

It looks like there is a problem with parameters, but I can't figure out how to solve it. As a consequence, many cells after this one cannot be run.

Would appreciate any help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.