<?xml version="1.0" encoding="UTF-8"?>
<gretl-functions>
<gretl-function-package name="nic_gig" minver="2020a">
<author email="">Mary Mertzanidou</author>
<version>1.0</version>
<date>2026-06-27</date>
<description>News Impact Curves for GARCH and GJR-GARCH</description>
<tags>ts finance volatility</tags>
<help>
nic_gig: News Impact Curves for GARCH(1,1) and GJR-GARCH(1,1)

Implements the analytical NIC formulas from:
  Engle, R.F. and Ng, V.K. (1993). Measuring and testing the impact
  of news on volatility. Journal of Finance, 48(5), 1749-1778.

Both models are estimated via the gig package.

This package provides one public function:

nic_plot_from_gig(mod_garch, mod_gjr)
  Takes two gig bundles (GARCH type 1 and GJR type 3) and plots
  both News Impact Curves on the same graph.

  NIC formulas (Engle and Ng, 1993):
    GARCH:     h(e) = A + alpha * e^2
    GJR (e &gt;= 0): h(e) = A + alpha * e^2
    GJR (e &lt; 0):  h(e) = A + (alpha + gamma) * e^2
    where A = omega + beta * hbar
    and hbar = omega / (1 - alpha - beta)

References:
  Engle, R.F. and Ng, V.K. (1993). Journal of Finance, 48(5), 1749-1778.
</help>

<gretl-function name="nic_plot_from_gig" type="void" private="0">
 <params count="2">
  <param name="mod_garch" type="bundle" const="true">
   <description>GARCH(1,1) bundle from gig (type 1)</description>
  </param>
  <param name="mod_gjr" type="bundle" const="true">
   <description>GJR-GARCH(1,1) bundle from gig (type 3)</description>
  </param>
 </params>
<code><![CDATA[
  # --- extract GARCH coefficients ---
  matrix cg   = mod_garch.coeff
  scalar g_omega = cg[3]
  scalar g_alpha = cg[4]
  scalar g_beta  = cg[6]
  scalar g_hbar  = g_omega / (1 - g_alpha - g_beta)
  scalar g_A     = g_omega + g_beta * g_hbar

  # --- extract GJR coefficients ---
  matrix cgjr    = mod_gjr.coeff
  scalar gjr_omega = cgjr[3]
  scalar gjr_alpha = cgjr[4]
  scalar gjr_gamma = cgjr[5]
  scalar gjr_beta  = cgjr[6]
  scalar gjr_hbar  = gjr_omega / (1 - gjr_alpha - gjr_beta)
  scalar gjr_A     = gjr_omega + gjr_beta * gjr_hbar

  # --- print for verification ---
  printf "\n--- GARCH(1,1) ---\n"
  printf "  omega = %.6e\n", g_omega
  printf "  alpha = %.6e\n", g_alpha
  printf "  beta  = %.6e\n", g_beta
  printf "  hbar  = %.6e\n", g_hbar
  printf "  A     = %.6e\n", g_A

  printf "\n--- GJR-GARCH(1,1) ---\n"
  printf "  omega = %.6e\n", gjr_omega
  printf "  alpha = %.6e\n", gjr_alpha
  printf "  gamma = %.6e\n", gjr_gamma
  printf "  beta  = %.6e\n", gjr_beta
  printf "  hbar  = %.6e\n", gjr_hbar
  printf "  A     = %.6e\n\n", gjr_A

  # --- plot ---
  string fname = sprintf("%snic_combined.gp", $dotdir)

  outfile @fname
  printf "set encoding utf8\n"
  printf "set linetype 1 lc rgb '#0072B2' lw 2.5\n"
  printf "set linetype 2 lc rgb '#D55E00' lw 2.5\n"
  printf "set title 'News Impact Curves - GARCH(1,1) vs GJR-GARCH(1,1)'\n"
  printf "set xlabel 'Standardised Residual (e_{t-1})'\n"
  printf "set ylabel 'Conditional Variance h_t'\n"
  printf "set xzeroaxis lt -1 lw 1 lc rgb '#808080'\n"
  printf "set border 15\n"
  printf "set grid\n"
  printf "set key left top\n"
  printf "set xrange [-3:3]\n\n"
  printf "garch_nic(x) = %g + %g*x**2\n", g_A, g_alpha
  printf "gjr_nic(x) = (x < 0) ? %g + %g*x**2 : %g + %g*x**2\n", gjr_A, gjr_alpha+gjr_gamma, gjr_A, gjr_alpha
  printf "plot garch_nic(x) title 'GARCH(1,1)' w lines lt 1, \\\n"
  printf "     gjr_nic(x)   title 'GJR-GARCH(1,1)' w lines lt 2\n"
  end outfile

  gnuplot --input=@fname --output=display
]]></code>
</gretl-function>

<sample-script>
include yahoo_get.gfn
include gig.gfn
include nic_gig.gfn

nulldata 11200
setobs 5 1985-02-01 --time-series

StockPrices = yahoo_price("^NDX", 0, 0)
Stock = interpol(StockPrices)
StockReturns = ldiff(Stock)
smpl +1 ;

bundle mod_g = gig_setup(StockReturns, 1, const, null, 1)
gig_estimate(&amp;mod_g, 0)

bundle mod_gjr = gig_setup(StockReturns, 3, const, null, 1)
gig_estimate(&amp;mod_gjr, 0)

# Plot NICs
nic_plot_from_gig(mod_g, mod_gjr)
</sample-script>
</gretl-function-package>
</gretl-functions>
