Today, December 17th 2021, my first R package, JSUparameters, was published on CRAN. Before showcasing an example of my package in action, I think it is appropriate to consider some of the background of the package. This package was created as an extension of my Master's thesis; so, this blog post contains extracts from my thesis. Originally, the normal distribution was used to model stock market returns (L. Bachelor 1900). However, the existence of stock market crashes led to stock market returns having fatter tails than those of a normal distribution. This knowledge resulted in substantial academic interest in modelling stock market returns, with the primary target being to reduce the risk associated with the stock market (C. Eom et al., 2019). In as early as 1963, Mandelbrot (B. B. Mandelbrot, 1963) noted the distribution of stock returns were more peaked than a normal distribution and presented with fatter tails (C. Eom et al., 2019). In 2008, Choi & Nam (P. Choi & K. Nam, 2008) proposed using the Johnson SU distribution to model financial data, as this distribution would account for the non-normality features present in the data. This application of the Johnson SU distribution was successful in that their exceeding ratio tests indicated that the “SU-normal is superior to the normal and Student-t distributions, which consistently underestimate both the lower and upper extreme tails”. As with any statistical distribution, there are numerous ways in which a Johnson SU distribution can be fit to a dataset. In the past, two common methods of estimating the parameters of the Johnson SU distribution were the method of moments (I. D. Hill, 1976) and the method of maximum likelihood (D. M. Olsson, 1979). In 1988, Storer et al. (R. H. Storer et al., 1988) conducted a comparison of methods for fitting data using Johnson distributions. This involved comparing the method of moments, the method of maximum likelihood and several variations of the method of least squares (ordinary, weighted and diagonally weighted). The method of maximum likelihood performed well in many cases; however, in (R. H. Storer et al., 1988), they concluded that "while the case for the MLE appears fairly strong, further sampling is necessary . . . the MLE owes some of its superior performance to the knowledge of the parent distribution”. These two approaches were considered for estimation of the parameters of the best-fitting Johnson SU distribution. We discovered that the likelihood function of the Johnson SU distribution is unbounded. This means that it is impossible to solve the problem (correctly) using the method of maximum likelihood. The solution obtained is actually only a local maximum, as opposed to the global maximum, since the likelihood is unbounded. We then tried using the other methodology, the method of least squares. This alternative approach always obtained an optimum, which our exhaustive simulation suggests is unique. So, we developed our own algorithm to solve the problem of finding the best-fitting Johnson SU distribution for a given dataset via the method of least squares. This project used the Irish Stock Exchange Quotient (ISEQ) dataset, which consists of data recorded every Monday, from July 14th 1997 to May 31st 2021. This dataset was downloaded from Yahoo! Finance; Table 1.1 shows an extract of the dataset. Figure 1.2 displays a histogram of the weekly log returns. These data appear approximately bell-shaped, yet there is some asymmetry present, particularly regarding the few large negative returns. This is clear motivation for the decision to investigate the Johnson SU distribution, as the tails of this histogram are not well-captured by a normal distribution; more flexibility is required. The aim of this project was essentially to build an algorithm that returns the parameter estimates of the best-fitting Johnson SU distribution for a given dataset, optimising the problem via the least squares method. The algorithm solves the technical optimisation task that is central to this project. In addition, the limiting cases of the Johnson SU distribution were investigated and code was written to trap each of them and find their corresponding parameters, making the algorithm much more reliable and robust. Next, I will show an example of the package in action. I scraped the above-mentioned data from the Yahoo! Finance website, loaded it into my R workspace, selected only the closing price, converted it to a numeric object, interpolated the one missing observation and calculated the log returns. It is the log returns (pictured above in Figure 1.2) that we would like to accurately model. Using one line of code, I obtained the following results: The below figure displays the log returns along with the best-fitting normal distribution and best-fitting Johnson SU distribution (as found above). It is clear that the best-fitting Johnson SU distribution, found by the algorithm, is a far better fit to this set of data than the corresponding best-fitting normal distribution. This algorithm is likely to be useful within the financial sector when investors are modelling investment returns and trying to make predictions. The algorithm allows the user to fit their data to a Johnson SU distribution, finding the best fit out of the Johnson SU distribution and the distributions of its limiting cases. One particular application of this algorithm would be in banking, where the value at risk (how much money might be lost to a certain degree of confidence) is calculated for several thousand models on a daily basis. Clearly, this scenario requires the use of a reliable algorithm, as banks cannot afford for algorithms to suddenly stop working. This concept highlights the reliability that has been built into this algorithm. The concept of using sorted least squares to find the best-fitting Johnson SU distribution to a given dataset, also considering the limiting cases of the distribution, is not something that has been done before. Feel free to download the JSUparameters package and have a go yourself! If you have any comments or queries, feel free to post a comment or send me a message using the contact form.
0 Comments
|
CJ ClarkePhD Student ArchivesCategories |