# A Test for the Presence of Jumps in Financial Markets using Neural Networks in R

Modelling of financial markets is usually undertaken using stochastic processes. Stochastic processes are collection of random variables indexed, for our purposes, by time. Examples of stochastic processes used in finance include GBM, OU, Heston Model and Jump Diffusion processes.  For a more mathematically detailed explanation of stochastic processes, diffusion and jump diffusion models, read this article. To get an intuitive feeling of how these different stochastic processes behave, visit the interactive web application that I worked on in conjunction with Turing Finance and Southern Ark.

As was witnessed during the recent financial crisis, stock markets exhibit jumps. That is, they exhibit large falls in value. Over the past couple of decades, the has been increasing interest in the modelling of these jumps. The classic model for modelling jumps in stochastic processes is the Merton Jump diffusion model.  This model says that the returns from an asset are driven by “normal” price vibrations (representing the continuous diffusion component) and “abnormal” price vibrations (representing the discontinuous jump component).  The SDE of the Merton Jump diffusion model  is given as:

$d X_t = X_t\mu dt+ X_t\sigma dW_t +X_t d(\sum_{i=0}^{N_t}(Y_i-1)).$

where $N_t$ is a Poisson process with rate $\lambda$ and $Y_i$ has a log normal distribution.

In practice, before we can proceed with fitting a jump diffusion model to data, we first have to establish if the data that we are fitting the model to has jumps. This requires us to statistically test for the presence of jumps in return data.

There are various tests that have been developed for testing for jumps in return data. Examples of  such tests include the bi-power variations test of Barndorff-Nielsen and Shepard (2006). This jump test compares the estimate of variance that is not robust to the presence of jumps, called realized variance, with an estimate of variance that is robust to the presence of jumps, called bi-power variation. This test was improved by Ait Sahalia and Jacod (2009). In their test, they compare the bi-power variations for returns sampled at different frequencies. Lee and Mykland (2008) also used insights from the test of Barndorff-Nielsen and Shepard (2006) by testing for the presence of jumps at each observed value of the process, while taking into account the volatility of the process at the time the observation was made. The test of Lee and Mykland (2008) has the added advantage that it not only indicates whether or not jumps have occurred, but also gives information as to what time the jumps occurred and their size.

In this blog post, I propose a test for the presence of jumps using Neural Networks. This test is then assessed using simulation compared to the Lee and Mykland (2008) test, then we look at how the Neural Network test fares on stocks on the JSE.

# The Neural Network Test

Neural Networks are a group of learning models which fall under machine learning. They were inspired by the biological neural networks.  For a detailed analysis of neural networks and the algorithm used to train neural networks, please refer to this article by Turing Finance.

As mentioned above, the test I am  proposing uses neural networks to test for jumps. This test establishes whether or not the whole series of returns has jumps. That is, the test has a binary outcome. This means that we can treat the testing for the presence of jumps as a classification problem. We want to classify a set of returns as belonging to on one of two categories, having jumps or not having jumps.

Given that neural networks can perform well in classification problems, such as in credit rating, it seems natural to try see how neural networks perform when trained to distinguish between a set of returns that has jumps and one that does not have jumps.

# Architecture of Neural Network

As the test uses neural networks, we need to carefully think about the architecture of the neural network. That is, we need to think of: what the inputs to the network are, what number of hidden layers (and associated number of neurons) we should have, and what the output layer should look like.

I have chosen the inputs into the neural network are: The first and second centered moments, skewness, kurtosis, the fifth, sixth, seventh and eighth centered moments. All of the moments used are sample moments. These particular variables were chosen as inputs to the neural network as the tests of Barndorff-Nielsen and Shepard (2006), Ait Sahalia and Jacod (2009) and Lee and Mykland (2008) use versions of these moments as their test statistics. So we believe that these moments should have strong predictive power. However, it should be noted that the moments are not necessarily independent and this could affect the performance of the neural network. Thus the inputs into the neural network still need further work. Let $X$ be a series of $n$ log returns. The moments inputs would then be given as:

$m_1= \frac{\sum X}{n}$

$m_2= \frac{(\sum X-m_1)^2}{n}$

$skweness= \frac{\frac{\sum (X-m_1)^3}{n}}{m_2^{3/2}}$

$kurtosis= \frac{\frac{\sum (X-m_1)^4}{n}}{m_2^{2}}$

$m_5= \frac{(\sum X-m_1)^5}{n}$

$m_6= \frac{(\sum X-m_1)^6}{n}$

$m_7= \frac{(\sum X-m_1)^7}{n}$

$m_8= \frac{(\sum X-m_1)^8}{n}.$

A single hidden layer with 10 neurons was chosen. This is mainly because we believe that the relationship between the inputs and the outputs is definitely non-linear, so at least one hidden layer was required, but we also wanted to keep the run-times within reason, so we chose only 10 neuron of this hidden layer.

Since we only want to classify a set of returns as having jumps or not, the output layer only has one neuron. This neuron can only take on the values 1 (if there is a jump) and 0 (if there is no jump).

Figure 1 gives us an example of the architecture of the neural network used in this blog post.

It is important note that this particular architecture was chosen just for illustrating how one would think about testing for jumps using neural networks. It is by no means necessarily the “best’ architecture. This is definitely an area for future work. We hope to cover this in later posts.

Having decided on the architecture of the neural network, we still needed to  train it. The neural network was trained on 3000 observations from a processes that has jumps (generated using the Merton Jump model) and a process which does not have jumps (generated using GBM).  The neural network was trained using the neuralnet package in R.

# Simulation study

Simulations were undertaken to assess how the neural network test performs against the Lee & Mykland Test (2008).  The underlying model being assumed is the basic Merton model discussed above.   Using simulations, we worked out the Probability of ACTUAL detection (the test being able to detect jumps in  a series that has jumps) and the probability of FALSE detection (the test incorrectly detecting jumps in a series of returns that doesn't have jumps) of each of the tests. The simulation was conducted at a daily frequency, using different combinations of the parameters. A more rigorous comparison would have to compare the two tests at different frequencies, and for large and small jumps.

We have summarized the results of the simulations conducted in the table below:

 Test Probability of ACTUAL detection Probability of FALSE detection Neural Network Test 0.994 0.021 Lee & Mykland Test 0.967 0.158

Based on the simulation results in the table above, the neural network test to perform better than the Lee & Mykland (2008) test. This is because the probability of actual detection for the neural network test is higher than for the Lee & Mykland (2008) test, and the probability of false detection is lower than that of the Lee & Mykland (2008) test.

Given that we have seen how the test performs on simulated data, we are now in a position to apply the test on data from the Johannesburg Stock Exchange.

# Applying the Test to JSE Data

After seeing how the neural network test for jumps performs in simulations, we applied the test to 217 stocks which are listed on the Johannesburg Stock Exchange (JSE). The various stocks used in this post, categorized by industry, are shown in the table below.

SASOL_LTD___

OMNIA____
HARMONY_GOLD_MINING_CO_LTD
IMPALA_PLATINUM_HOLDINGS_LTD_
AECI_LTD___
AFRICAN_RAINBOW_MINERALS_LTD_
ASSORE____
SIBANYE_GOLD___
ARCELORMITTAL_SOUTH_AFRICA__
ANGLO_AMERICAN_PLATINUM_LTD_
SAPPI_LIMITED___
NORTHAM_PLATINUM_LTD__
GOLD_FIELDS_LTD__
EXXARO_RESOURCES_LTD__
AQUARIUS_PLATINUM_LTD__
ROYAL_BAFOKENG_PLATINUM_LTD_
MERAFE_RESOURCES_LTD__
LONMIN_PLC___
BHP_BILLITON_PLC__
BRITISH_AMERICAN_TOBACCO_PLC_
PAN_AFRICAN_RESOURCES_PLC_
PALLINGHURST_RESOURCES_LTD__
KUMBA_IRON_ORE_LTD_
ANGLOGOLD_ASHANTI_LTD__
ANGLO_AMERICAN_PLC__
METMAR_LTD___
SABLE_METALS_AND_MINERALS_LT
SENTULA_MINING_LTD__
KEATON_ENERGY_HOLDINGS_LTD_
TRANS_HEX_GROUP_LTD_
WESIZWE_PLATINUM_LTD__
ATLATSA_RESOURCES_CORP__
BAUBA_PLATINUM_LTD__
WESCOAL_HOLDINGS_LTD__
GOLIATH_GOLD_MINING_LTD_
RANDGOLD__EXPLORATION_CO_
ZCI_LTD___
DRD_GOLD_LTD__
PETMIN_LTD___
COAL_OF_AFRICA_LTD_
ROLFES_HOLDINGS_LTD__

TRENCOR_LTD___
RAUBEX_GROUP_LTD__
GROUP_FIVE_LTD__
HOWDEN_AFRICA_HOLDINGS_LTD_
NAMPAK_LTD___
WILSON_BAYLY_HOLMES_OVCON_
PPC_LTD___
REUNERT_LTD___
BRAIT_SE___
MURRAY_ROBERTS_HOLDINGS__
AVENG_LTD___
MONDI_PLC___
ALLIED_ELECTRONICS_CORA_SHR_
KAP_INDUSTRIAL_HOLDINGS_LTD_
MPACT_LTD___
CONSOLIDATED_INFRASTRUCTURE___
AFRICAN_OXYGEN_LTD__
GRINDROD_LTD___
TONGAAT_HULETT_LTD__
ALLIED_ELECTRONICS_CON_SHRS_
HUDACO_INDUSTRIES_LTD__
REDEFINE_INTERNATIONAL_PLC__
TORRE_INDUSTRIES_LTD__
MAZOR_GROUP_LTD__
BUILDMAX_LTD___
JASCO_ELECTRONICS_HOLDINGS__
ESOR_LTD___
BOWLER_METCALF_LIMITED__
INTERWASTE_HOLDINGS_LTD__
MASTER_DRILLING_GROUP_LTD_
SANTOVA_LTD___
PUTPROP_LTD___
ARGENT_INDUSTRIAL_LTD__
SEPHAKU_HOLDINGS_LTD__
CROOKES_BROTHERS_LTD__
SACOIL_HOLDING_LTD__
ENX_GROUP_LTD__
ARB_HOLDINGS_LTD__
TRANSPACO_LTD___
CARGO_CARRIERS_LTD__
AMALGAMATED_ELECTRONIC_CORP__
ELB_GROUP_LTD__
BELL_EQUIPMENT_LTD__
ONELOGIX_GROUP_LTD__
SPANJAARD_LTD___
DELTA_EMD_LTD__
MARSHALL_MONTEAGLE_PLC__
WINHOLD_LTD___
YORK_TIMBER_HOLDINGS_LTD_
INSIMBI_REFRACTORY_AND_ALLOY_
PINNACLE_HOLDINGS_LTD__

RCLFOODS____
SABMILLER_PLC___
TIGER_BRANDS_LTD__
PIONEER_FOODS_LTD__
RHODES_FOOD_GROUP_PTY_LTD
CAPEVIN_HOLDINGS_LTD__
OCEANA_GROUP_LTD__
FAMOUS_BRANDS_LTD__
CLOVER_INDUSTRIES_LTD__
ASTRAL_FOODS_LTD__
DISTELL_GROUP_LTD__
ILLOVO_SUGAR_LTD__
AVI_LTD___
QUANTUM_FOODS_HOLDINGS_LTD_
SOVEREIGN_FOOD_INVESTMENTS__
NU_WORLD_HOLDINGS_LTD__
TASTE_HOLDINGS_LTD__

ASPEN_PHARMACARE_HOLDINGS_LTD_
MEDICLINIC_INTERNATIONAL_LTD__
NETCARE_LTD___
ASCENDIS_HEALTH_LTD__
LIFE_HEALTHCARE_GROUP_HOLDIN_

INVICTAS____
LEWIS____
CITY_LODGE_LODGE_HOTELS_LTD_
TRUWORTHS_INTERNATIONAL_LTD__
SPAR_GROUP_LIMITED__
FOSCHINI_FOSCHINI_GROUP_LTD_
SUN_INTERNATIONAL_LTD__
PICK_N_PAY_STORES_LTD
TSOGO_SUN_HOLDINGS_LTD_
SHOPRITE_HOLDINGS_LTD__
MR_PRICE_GROUP_LTD_
CURRO_HOLDINGS_LTD__
NOVUS_HOLDINGS_LTD__
FINANCIERE_RICHEMONT-DEP_REC__
EOH_HOLDINGS_LTD__
SPUR_CORP_LTD__
HOLDSPORT_LTD___
CLICKS_GROUP_LTD__
MIX_TELEMATICS_LTD__
AFRIMAT_LTD___
WOOLWORTHS_HOLDINGS_LTD__
NASPERS_LTD_SHS__
BARLOWORLD_LTD___
MASSMART_HOLDINGS_LTD__
STEINHOFF_INTL_HOLDINGS_LTD_
SUPER_GROUP_LTD__
BIDVEST_GROUP_LTD__
CASHBUILD_LTD___
CAXTON_AND_CTP_PUBLISHERS_
DISTRIBUTION__WAREHOUSING__
COMBINED_MOTOR_HOLDINGS_LTD_
COMAIR_LTD___
PHUMELELA_GAMING__LEISURE_
MORVEST_GROUP_LTD__
WILDERNESS_HOLDINGS_LTD__
EQSTRA_HOLDINGS_LTD__
VERIMARK_HOLDINGS_LTD__
NICTUS_LTD___
VALUE_GROUP_LTD__
AFRICAN_MEDIA_ENTERTAINMENT__
REX_TRUEFORM_CLOTHING_SHS_
PRIMESERV_GROUP_LTD__

TELKOM____
MTN_GROUP_LTD__
BLUE_LABEL_TELECOMS_LTD_
VODACOM_GROUP_LTD__

REDEFINE_PROPERTIES_LTD__
AFROCENTRIC_INVESTMENT_CORPO__
SANLAM_LTD___
BARCLAYS_AFRICA_GROUP_LTD_
STANDARD_BANK____
HOSKEN_CONS_INVESTMENTS_LTD_
INVESTEC_LTD___
RMI_HOLDINGS___
FIRSTRAND_LTD___
TRUSTCO_GROUP_HOLDINGS_LTD_
PSG_GROUP_LTD__
RMB_HOLDINGS_LTD__
HULAMIN_LTD___
NEDBANK_GROUP_LTD__
CAPITEC_BANK_HOLDINGS_LTD_
PEREGRINE_HOLDINGS_LTD__
REINET_INVESTMENTS_SA-DR__
CAPITAL_COUNTIES_PROPERTIE__
TRANSACTION_CAPITAL___
OCTODEC_INVESTMENTS_LTD__
DISCOVERY_LTD___
INVESTEC_PLC___
PSG_KONSULT_LTD__
ZEDER_INVESTMENTS_LTD__
REMGRO_LTD___
ALEXANDER_FORBES_GROUP_HOLDI_
MMI_HOLDINGS_LTD__
CLIENTELE_LTD___
OLD_MUTUAL_PLC__
CORONATION_FUND_MANAGERS_LTD_
LIBERTY_HOLDINGS_LTD__
SANTAM_LTD___
GROWTHPOINT_PROPERTIES_LTD__
SASFIN_HOLDINGS_LTD__
STELLAR_CAPITAL_PARTNERS_LTD_
PURPLE_GROUP_LTD__
PRESCIENT_LTD___
TREMATON_CAPITAL_INVESTMENT__
CONDUIT_CAPITAL_LTD__

DATATEC_LTD___
NET_UEPS_TECHNOLOGIES_INC_
DATACENTRIX_HOLDINGS_LTD__
DIGICORE_HOLDINGS_LTD__
MUSTEK_LTD___
COMPU_CLEARING_OUTSOURCING___
METROFILE_HOLDINGS_LTD__
COGNITION_HOLDINGS_LTD__

The result of the implementation of the Neural Network test on JSE stocks is presented in the table below. Note that only the stocks in each sector that had jumps are shown.

AFRICAN_RAINBOW_MINERALS_LTD_
ASSORE____
PAN_AFRICAN_RESOURCES_PLC_
ANGLOGOLD_ASHANTI_LTD__
METMAR_LTD___
SABLE_METALS_AND_MINERALS_LT
KEATON_ENERGY_HOLDINGS_LTD_
TRANS_HEX_GROUP_LTD_
WESIZWE_PLATINUM_LTD__
ATLATSA_RESOURCES_CORP__
BAUBA_PLATINUM_LTD__
GOLIATH_GOLD_MINING_LTD_
ZCI_LTD___
COAL_OF_AFRICA_LTD_

TRENCOR_LTD___
GROUP_FIVE_LTD__
NAMPAK_LTD___
BRAIT_SE___
AVENG_LTD___
MONDI_PLC___
ALLIED_ELECTRONICS_CORA_SHR_
CONSOLIDATED_INFRASTRUCTURE___
AFRICAN_OXYGEN_LTD__
TONGAAT_HULETT_LTD__
HUDACO_INDUSTRIES_LTD__
TORRE_INDUSTRIES_LTD__
BUILDMAX_LTD___
BOWLER_METCALF_LIMITED__
SACOIL_HOLDING_LTD__
ENX_GROUP_LTD__
CARGO_CARRIERS_LTD__
AMALGAMATED_ELECTRONIC_CORP__
ELB_GROUP_LTD__
SPANJAARD_LTD___
DELTA_EMD_LTD__
MARSHALL_MONTEAGLE_PLC__
WINHOLD_LTD___
YORK_TIMBER_HOLDINGS_LTD_
INSIMBI_REFRACTORY_AND_ALLOY_
PINNACLE_HOLDINGS_LTD__

RCLFOODS____
PIONEER_FOODS_LTD__
RHODES_FOOD_GROUP_PTY_LTD
OCEANA_GROUP_LTD__
FAMOUS_BRANDS_LTD__
ILLOVO_SUGAR_LTD__
QUANTUM_FOODS_HOLDINGS_LTD_
SOVEREIGN_FOOD_INVESTMENTS__
TASTE_HOLDINGS_LTD__

ASCENDIS_HEALTH_LTD__

CITY_LODGE_LODGE_HOTELS_LTD_
PICK_N_PAY_STORES_LTD
CURRO_HOLDINGS_LTD__
NOVUS_HOLDINGS_LTD__
EOH_HOLDINGS_LTD__
SPUR_CORP_LTD__
HOLDSPORT_LTD___
MIX_TELEMATICS_LTD__
AFRIMAT_LTD___
CAXTON_AND_CTP_PUBLISHERS_
MORVEST_GROUP_LTD__
WILDERNESS_HOLDINGS_LTD__
NICTUS_LTD___
REX_TRUEFORM_CLOTHING_SHS_
PRIMESERV_GROUP_LTD__

HOSKEN_CONS_INVESTMENTS_LTD_
TRUSTCO_GROUP_HOLDINGS_LTD
CAPITAL_COUNTIES_PROPERTIE__
OCTODEC_INVESTMENTS_LTD__
CORONATION_FUND_MANAGERS_LTD_
SASFIN_HOLDINGS_LTD__
STELLAR_CAPITAL_PARTNERS_LTD_

NET_UEPS_TECHNOLOGIES_INC_
DATACENTRIX_HOLDINGS_LTD__
DIGICORE_HOLDINGS_LTD__
MUSTEK_LTD___
COMPU_CLEARING_OUTSOURCING___
METROFILE_HOLDINGS_LTD__

A summary of the results of the jump test per sector are is presented in the table below:

 Basic Materials Indi Consumer Goods Health Care Consumer Services Fini Tech % 34% 54% 53% 14% 37% 20% 70%

The table suggests that the most "jumpy" sectors are the Technology, Consumer goods and Industrial sectors. A deeper analysis into each of these sectors should reveal some interesting conclusions. It should be noted that for some sectors, e.g. Oil and Gas, not enough data was collected. The results for such sectors should be treated with caution.

# Conclusion:

In this blog post, we looked at a possible test for the presence of jumps using neural networks. The neural network test performs well under simulations, but the architecture used in this blog post is not necessarily the most optimal. A more rigorous study of the different architectures would be useful. When the neural network test was applied to data on the JSE, it was found that the Technology sector is the most jumpy with 70% of stocks in the sector having jumps. However, more data for each sector on the JSE would be necessary to have more confidence in this result.

# Code Used

In this section we provide the R-Code that was used in this blog post.

## 9 Replies to “A Test for the Presence of Jumps in Financial Markets using Neural Networks in R”

1. Nice one Wilson! I really like this idea and the data you applied this test on is quite thorough. Keep up the good work 🙂

2. Hello,

Interesting work but isn't this an overkill? In addition, could this be misleading? How to you define a jump? If a return series falls withing 0.5% would you classify a 1.5% change as a jump?

You could just define a threshold and then count the return below it. Then to a critical value on the distribution determine how significant it is. What do you think about this simpler method?

• Hi Bill, thanks for the comment.

I would say that its not over kill if the aim is to come up with a robust way of identifying jumps in a set of returns.

A return is considered as a jump with reference to the other returns in its neighborhood. An even more difficult problem is determining if the return is a jump or an outlier.

I totally agree with your simpler method. Infact, the Lee and Mykland test uses extreme value theory to determine the distribution of the test statistic, and hence what the threshold/critical value should be.