Wednesday, April 27, 2016

Fan Chart

Fan charts are a method of visualizing a distribution of economic forecasts, pioneered by the Bank of England for their quarterly inflation forecasts.

We are often asked if EViews can produce fan charts. At its heart, a fan chart is simply a type of area band chart. EViews has been able to produce area band charts for a number of previous versions. So whenever we have been asked if EViews can produce fan charts, we have said “yes”.

Recently, we decided to go one step further and replicate an official Bank of England fan chart in EViews, and this blog post will document the steps required to perform the replication.

We have decided to replicate a recent inflation report fan chart, specifically the November 2015 inflation fan chart available from the Bank of England.




At first glance, this fan chart is simple to re-produce in EViews. Simply obtain the historical inflation series, along with the median and quantile forecast series used to create the fans, then put those series in a group and create an area band chart from them. However it isn’t quite so easy, since the Bank of England does not provide the forecast quantile values, rather they only provide distribution parameters for the assumed distribution of the forecasts.

Nevertheless, the first step in the replication is to obtain the historical inflation numbers. We’ll create a new EViews workfile to hold the inflation data by clicking on File/New/Workfile, and select quarterly as the frequency with a start date of 2009 and end date of 2018, giving us enough room for a few years of forecasts.

To retrieve the historical data, use the handy GetQuandl add-in to fetch the data directly from the Quandl website. If you don’t have the GetQuandl add-in already installed, you can install directly from within EViews by using the Add-ins/Download Add-ins menu item, then select the GetQuandl add-in and follow the instructions to install.

Once installed, use the menu item Add-ins/Download Quandl Data to bring up the Quandl Add-in dialog. Next, enter the Quandl code for UK inflation, RATEINF/CPI_GBR, (which we found by performing a search on the Quandl.com website) in the top box, and then change the Import Choice option to be “Import into Page”.

Clicking on OK results in the data being brought into our workfile page as the series “value”.  Since the Bank of England fan charts deal with the annual growth rate of inflation, we will create a growth rate series by typing the command:

series cpig = @pcy(value)

We now have the required historical values.

To obtain the forecasts, first fetch the forecast distribution data from the Bank of England. The bank provides the data in an Excel file.

We can import this data directly into EViews by clicking on File/Import/Import from file and then enter the following URL into the File name box:

http://www.bankofengland.co.uk/publications/Documents/inflationreport/ir15novprob.xlsx

Once EViews has connected to the Bank of England's website, the Excel Read dialog box will guide you through the import process. All we need to do is check the box that instructs EViews to “Read series by row”, since the original data is in transposed format in Excel.

Since the data from either Bank of England or Quandl may change in the future, we have created a snapshot of the data used in this blog.

Now that we have the forecast mode, skewness and uncertainty, we can create the forecast quantiles for the fan chart. The calculations used to create the quantiles are a little complicated, so we wrote a simple EViews program to compute them for us.

The program generates the forecast quantiles as the series f01-f07. We will open the actual data along with the forecasts into a group by selecting the CPIQ series and the forecast series, right-click and select Open/As Group. Name this group by clicking on the Name button and enter “fgroup” as the name.

We are now ready to make our fan chart. With fgroup open, click View/Graph to bring up the Graph dialog, and then change the Graph type to Mixed. This allows us to then select the Mixed settings node of the pages tree to set the Mixed types properly. We assign the first series and last series to be Lines, and the rest to be “Area Band”. Click OK to produce the fan chart:



All that remains is to change some of the graph settings to have it match the Bank of England’s style. First, change the sample of the graph using the slider-bar to set the start date as 2011Q3 and the end as 2017Q3.

Next, the following customization options are made under the Graph Options dialog (available by double-clicking on the graph) and expanding (+) the different options.


  • Graph Elements/Fill Areas, change the first color to RGB(248,191,172), the second color to RGB(240,134,112), and the third color to RGB(234,76,73).
  • Graph Elements/Lines and Symbols, change the first and second lines’ color to RGB(228,5,31) and the width to 2pt.
  • Axes & Scaling/Data scaling, change all 8 series assignments to Right.
  • Axes & Scaling/Data scaling, change Right axis scale endpoints to User specified with values of (-3, 6)
  • Frame & Size/Color & Border, change Frame border Axes to the second option (i.e. a border on each side of the graph).


To finish the customization, we need to freeze the graph into its own graph object. We do this by clicking on the Freeze button, then the Name button and naming our graph "CPIGRAPH".

Next, we add some shading over the forecast period by right-clicking on our graph and clicking on Add lines & shading. We add a shaded area starting at 2015Q3 and ending in 2017Q3. Change the color of the shade to RGB(239,239,239).

Additionally, we add a horizontal line at the Bank’s 2% target by again right-clicking and selecting Add lines & shading, and adding a Horizontal – Right axis line (Orientation drop-down list) at a data value of 2. We set the line’s width to 2 pt and check-box "Draw the line on top".

Finally, we remove the legend from the graph by selecting legend and pressing the delete button.



Note: We have released a FanChart Add-in for creating Bank of England style fan charts. You can download it here.

19 comments:

  1. This is great and exciting. Thanks to Eviews team. Will share this with colleagues

    ReplyDelete
  2. Dear Prof., I would request you to add a Gregory-Hansen cointegration that (that accounts for structural break).

    Thank you

    ReplyDelete
    Replies
    1. Thanks for the suggestion. There is a user-written routine for it:
      http://forums.eviews.com/viewtopic.php?f=15&t=976

      Delete
  3. Dear Prof
    I did not get the series f01-f07. how can I get it. Im using eviews 8. also I have not see graph type "mixed". I have see only mixed with lines.

    ReplyDelete
  4. Hi,
    When i ran the program to generate forecast quantiles it shoes an error "SKEWNESS is not defined in "!SKEW = SKEWNESS(28)".

    Thank you.

    ReplyDelete
  5. Hello,
    Running the program I get an error:
    Log or square root of negative number in "SCALAR S2 = SIGMA / @SQRT(1 + G)".

    Thank you.

    ReplyDelete
    Replies
    1. Problems can occur because row values of uncertainty are zero; and/or skewness (absolute) values exceed 1.

      Delete
  6. Hello,

    Is it possible to run the fanchart addin from the command line? cpi.fanchart does not work...
    Thank you.

    ReplyDelete
    Replies
    1. cpi.fanchart does work (or {%0}.fanchart if "cpi" is renamed to some variable {%0}, for instance, "dependent" in the body of the fanchart.prg. Presets can be changed there as well.
      However, it is still unclear how to a)either suspend user dialog interface to run this programmatically on several {%0} variables, or b) whether a better specified command like dependent.fan([options]) would solve the problem.

      Delete
    2. No command line interface was added for this add-in. It should not be too tricky to add one if you wanted to.

      Delete
  7. I know mode, uncertainty and skewness variables are from the BoE website. But how exactly are they calculated from the historical cpiq series? is it possible to expose the formulae in this post? Many thanks

    ReplyDelete
    Replies
    1. You'll have to refer to the BoE documentation for information on that.

      Delete
  8. What should I do when I get the following message:

    Error in Sample: MODE is not defined in "SMPL IF MODE<>NA".

    Thnaks!

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. Estimado, Me pueden enseƱar a realizar un fan chart con el complemento que tiene eviews?, como realizar los calculos?

    ReplyDelete