{'fraction_non_alphanumeric': 0.03703557312252964, 'fraction_numerical': 0.009960474308300396, 'mean_word_length': 4.382046373112104, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Analysis of stock index with a generalized BN-S model: an approach based on machine learning and fuzzy parameters

In this paper we implement a combination of data-science and fuzzy theory to improve the classical Barndorff-Nielsen and Shephard model, and implement this to analyze the S&P 500 index. We pre-process the index data based on fuzzy theory. After that, S&P 500 stock index data for the past ten years are analyzed, and a deterministic parameter is extracted using various machine and deep learning methods. The results show that the new model, where fuzzy parameters are incorporated, can incorporate the long-term dependence in the classical Barndorff-Nielsen and Shephard model. The modification is based on only a few changes compared to the classical model. At the same time, the resulting analysis effectively captures the stochastic dynamics of the stock index time series.


Introduction
Stock index, the most important indicator that reflects and predicts financial market fluctuations and global economic changes, is playing an increasingly important role in capital market. The total value and trading volume of global trading products of stock index are increasing year by year. It is often used as a benchmark to measure the performance of investment funds, the basis of passive management that replicates its performance, derivative instruments involved in transactions, benchmark indicators for financial contracts, and [7]) proposed a machine learning random algorithm, calculated the best trading strategy, and studied the sensitivity of the solution for various parameters in cross-platform complex transactions. Shoshi et al. (see [26]) proposed the volatility method and the duration method to capture the random behavior of the time series and analyzed the Bakken crude oil data through various machine learning and deep learning algorithms. Similar analysis for the yield data in commodity market is provided in [25]. Roberts et al. (see [18,19]) proposed a sequential hypothesis test that can detect the general jump size distribution. Their method was applicable to the crude oil price data set and improved the stochastic model using various machine and deep learning algorithms.
Fuzzy theory is a powerful tool to describe uncertain events (see [29]), and has a wide range of applications in management science, decision science, and intelligent control. There are many randomness and ambiguities in the financial market, which are mainly reflected in the uncertainty of market changes, the incomplete symmetry of the information of the parties involved in a transaction, and the real-time fluctuation of commodity transaction data. Some scholars have tried to apply fuzzy theory to the field of financial research and have achieved some effective results. For example, Hatami-Marbini et al. (see [11]) used fuzzy numbers to describe the indicators and factors of stock performance, and obtained fuzzy distances to optimize stock portfolios. The combination of fuzzy theory and deep learning is used to predict changes in high-frequency financial data (see [9]). Thavaneswaran et.al. (see [27]) implemented the fuzzy set theory to price binary options by using trapezoid, parabola, and adaptive fuzzy stock price maturity value. Zhang et. al. (see [30]) considered the clear probability mean of the fuzzy number, and obtained the clear probability mean option pricing formula in the jump diffusion model of fuzzy double index. The use of fuzzy theory has obvious advantages in financial data processing. Data processing involving fuzzy parameters can accurately describe the fuzzy changes of real market situation.
For this paper, we apply fuzzy sets and machine learning to the analysis of the stock index. In Section 2 we describe the BN-S model and its various modifications. We compare the different advantages of the classical and generalized BN-S models. The financial data processing problem under fuzzy random uncertainty is introduced in Section 3. In Section 4, we analyze the S&P 500 index data, with machine/deep learning and fuzzy theory. A brief conclusion is provided in Section 5.

The classical BN-S model and its generalizations
The Barndorff-Nielsen and Shephard (BN-S) model is a type of stochastic volatility model that is commonly used to describe the dynamic changes of asset prices. This is implemented to capture the response patterns of some stylized characteristics of financial asset time series in the financial market. The non-Gaussian Ornstein-Uhlenbeck (OU) process in the BN-S model is driven by an incremental Lévy process, which is a random process of positive mean recovery. Consider a frictionless financial market, where a stock, and a risk-free asset with a fixed rate of return r, are traded on the horizon date T . The BN-S model assumes that the price process of the stock (or, commodity), S = (S t ) t≥0 , defined in a filtered probability space (Ω, F, (F t ) 0≤t≤T , P ), is given by: (2.1) The log-return X t is governed by: where the parameters µ, β, ρ ∈ R, and ρ ≤ 0, and the variance process is given by: In (2.3), λ ∈ R, and λ > 0. For the probability measure P , W = (W t ) is the standard Brownian motion defined in the probability space. The process Z = (Z λt ) is a subordinator. This is also known as the background driving Lévy process (BDLP). It is assumed that the processes W and Z are independent, and (F t ) is a conventional augmentation of the filtering produced by (W, Z).
There are several issues in the application of the classical BN-S model. Both logarithmic return and volatility (or, variance) contain a single BDLP, which makes them completely dependent on each other, leading to inaccurate volatility simulations. This absolute correlation also implies that the model will fail in a longer time frame, that may span for just a few days. The model cannot consistently capture the basic characteristics of the relevant time series. For historical data, the jump in volatility is not completely synchronized with the jump in stock prices. The volatility σ t usually cannot immediately respond to sudden fluctuations in a stock (or, commodity) price. This is one of the reasons why the classical BN-S model fail to work.
Some of these issues are addressed in the generalized BN-S model (see [23]). The new model simulates option prices and volatility in an interrelated but different way. The generalized model assumes that Z t and Z * t are two independent Lévy subordinators with same (finite) variance. Then, there exists a Lévy subordinate d Z λt independent of W , which is given by: For the generalized model, the dynamics of S t is given by (2.1) and (2.2), where σ 2 t is given by: In (2.5), the OU processZ = (Z λt ) is correlated to the corresponding Z in (2.3) and is also independent of W subordination. The classical BN-S model, even with the above generalization, fails to accommodate long-range dependence. In a recent paper, some major refinements are made to the BN-S model. This model is implemented in [19,24,26]. For this refinement of the BN-S model, the log-return X t , on some appropriate risk-neutral filtered probability space, is considered to be driven by a convex combination of two subordinators Z and Z (b) . This is written as: where θ is a deterministic parameter, with θ ∈ [0, 1], λ > 0 is the proportional parameter at t, and Z and Z (b) are independent Lévy processes. We asssume that Z (b) corresponds to a subordinator with greater Lévy intensity in comparison to the subordinator Z. In addition, when the dynamics of X t is given by (2.6), the variance process is given by: Similar to the expression (2.5), θ ′ ∈ [0, 1] is deterministic, and the processes Z and Z (b) are independent Lévy processes. The sum of (1 − θ)Z λt and θZ λt is also a Lévy process and is positively correlated with Z and Z (b) .
The integral variance is given by σ 2 I = T t σ 2 s ds in the time period [t, T ]. Consequently, (2.7) provides: Consequently, the continuous realized variance in the interval [0, T ] is given by: We assume θ = θ ′ for the convenience for the rest of the paper. If J Z and J , t > s. (2.10) For the refined BN-S model the result becomes: 1 )). In (2.10), for a fixed s, as t increases Corr(X t , X s ) rapidly becomes small. It shows that the classical BN-S model is affected by time changes in the process of fitting random fluctuations, which leads to inaccurate volatility simulation. This rapid attenuation means that the model will be inaccurate in a longer time range. Consequently, the classical BN-S model is unable to accurately capture the basic characteristics of the relevant time series. However, due to the parameter θ, and the fact that t always has an upper limit, for a fixed s, Corr(X t , X s ) in (2.11) will never become "too small". Hence, compared to the classical model, the generalized BN-S model is more efficient in extracting a deterministic component from a stochastic financial process. The refined model improves the long-term dependence problem of the classical model with a few parameter changes. At the same time, it provides dynamic characteristics with obvious advantages for analysis of financial time series data.

Price representation based on fuzzy theory
There are many uncertainties in the financial market. The advantage of treating the daily price of stock index as a fuzzy parameter is that it can accurately describe the range of daily price fluctuations. It can bypass the errors caused by some unreasonable data in the empirical data-set, and increase the accuracy and operability of the yield and risk quantification process. Fuzzy numbers are often used to describe uncertain information. The definition of a fuzzy set requires two components: a universe of discourse or domain, and a function. The function is called the membership function, which defines the "degree" to which a particular element of the domain belongs to the set. Fuzzy sets are sets whose elements have degrees of membership.
Let S be the a universe of discourse or domain. We assume that S is is a subset of R. We consider a fuzzy set A ⊂ S. There is a membership function µ A : S → [0, 1] corresponding to each x ∈ S. The value of µ A (x) represents degree of membership, that quantifies the grade of membership of the element in S to the fuzzy set A. We form fuzzy parameters by associating µ A (x) with real data to realize the quantification of the fuzzy environment in the financial market. For l < m < r, the general representation of the membership function µ can be written as: In the above expression, L(x) is a right continuous increasing function, and 0 ≤ L(x) ≤ 1; R(x) is a left continuous decreasing function, and 0 ≤ R(x) ≤ 1. The value of membership (also know as "'confidence") α ∈ [0, 1] is usually expressed as: Aα = {x : µ A (x) > α}, the α level of fuzzy set A constitutes the set of all elements whose membership of A is greater than or equal to α in the complete set.
As an example, triangular fuzzy number is one of the classical expressions of fuzzy number. This is widely used in fuzzy evaluation system. The membership function µ A (x) is used to show the degree to which the element x belongs to the fuzzy set A. As shown in Figure 1, the triangular fuzzy number is a continuous convex function, composed of linear non-decreasing parts and non-increasing parts. Generally, the membership function of the triangular fuzzy number A = (a l , a m , a u ), where 0 ≤ a l ≤ a m ≤ a u ≤ 1, is expressed as follows: Here a l and a u are called the left-most and right-most values of fuzzy set A, respectively. They describe the lower and upper limits of the triangular fuzzy number A. Their difference indicates the fuzzy degree of fuzzy set A. The number a m is called the kernel of A and it represents the most likely value of the triangular fuzzy number A. In particular, if a l = a m = a u , then the fuzzy number degenerates into a real number. In addition (see [28]), The value of λ depends on the importance of the influence of the fuzzy boundary.
In order to improve the volatility structure in the BN-S model, and to address the issue that some input parameters in the model are difficult to accurately estimate, we consider the daily closing price, daily highest price, and daily lowest price of a stock index. We use triangular fuzzy numbers to describe the fuzzy daily price. With the help of fuzzy theory, for the daily price variables of stock index, we can obtain the price S = (s l , s m , s u ) in fuzzy form. The new fuzzy daily price is composed of three real numbers, which correspond to the lowest (s l ), closing (s m ) and highest (s u ) price of the empirical data on a particular date. From the empirical data of stock index price, we can get the triangular fuzzy number S = (s l , s m , s u ), that represents corresponding fuzzy price. The three parameters in the fuzzy set correspond to the daily lowest, closing, and highest price, respectively. Consequently, we define the value of λ to get fuzzy price expectation where S = (Price min , Price close , Price max ). This will be used as an indicator of the daily fuzzy price for the next analysis.
4 Numerical analysis based on machine/deep learning 4

.1 Data description and fuzzy parameters
In this section, we provide numerical examples to find the value of θ in the refined BN-S model (2.6). We consider the S&P 500 data set from November 1, 2010, to October 31, 2020, which contains 2518 data-points (Data source: https://finance.yahoo.com/). Some statistics of the empirical data set over the given time-period are shown in Table 1.
The daily closing price data, can be an indicator for the daily rise and fall of the S&P 500 stock index. Figure 2 shows the annual plot of the close price, daily rise and fall, and volatility of the empirical data-set. Affected by many factors inside and outside the financial market, the price of stock index fluctuates many times within a day. In the process of looking for the deterministic component (θ) in the stochastic time series, we hope to find a suitable daily price parameter to describe the fluctuation, which has both randomness and ambiguity. Data preprocessing using fuzzy parameters can describe the fuzzy situation of the range of price changes more accurately. We adjust the value of λ in the triangular fuzzy number, so that the fuzzy price accurately describes different risk preferences, different market trends, and different investment objectives. For investors with different risk preferences, the value of λ is different. Risk-averse investors are more likely to be affected by the lower limit of the fuzzy price boundary. Consequently, we assume that the degree of risk aversion of investors is inversely proportional to the value of λ. It is natural to assume that the λ corresponding to a riskneutral investor is 0.5, and the aggressive risk pursuer corresponds to a higher value of λ. The value of λ is also affected by the market environment. For example, in a bull market, the overall operating trend of a long market is upward, and the upper limit of the fuzzy boundary is more important. In that case, the value of λ is typically larger than that in a bear market. Different values of λ can also describe different investment objectives.
For example, in the case of a put option, investors pay more attention to the falling price of the underlying asset (especially the lowest price). So λ in the fuzzy price describing the volatility of the put option is generally between 0 and 0.5. With the price drop, the value of λ tends to 0. On the other hand, a call option is just the opposite. It is important in investment decisions to estimate the price increase (especially the highest price) of the underlying asset. So λ in the fuzzy price describing the volatility of the call option is  Generally, the daily closing price is the volume-weighted average price of all transactions one minute before the last transaction on that day. The daily highest price and daily lowest price describe the degree of price change. In this paper, we use triangular fuzzy numbers to calculate the daily fuzzy price of the stock index option based on three variables: daily lowest price, daily highest price, and daily closing price. In Table 2, we list the feature estimators of fuzzy price data when λ takes different values. Figure 3 provides a time series chart of the fuzzy price of S&P 500 stock index. We take λ = 0.5 for machine learning and deep learning on the empirical data in the following section.

Machine learning and deep learning
We index the available fuzzy price data by date. Based on the attributes of the data set, we construct a machine learning classification problem and provide quantitative decision support for estimating the value of θ with reasonable accuracy. Specific steps are as follows: Step 1 : From the available data, we arrange the preprocessed fuzzy price data in the order of date (from November 1, 2010 to October 31, 2020).  Step 2 : Explore the trend and distribution of fuzzy price changes over time, and visualize the data structure by month and year. Figure 4 provides moving averages of fuzzy prices in various time periods (5 days, 42 days, and 252 days) to show the trend of S&P 500 index price. Figures 5 and 6 show the dispersion and distribution of annualized data through box plots and histograms, respectively. In Figure 7, we show the bar graph of monthly data.
Step 3 : Based on Step 2, we calculate the daily changes of fuzzy prices and list these changes. Figures 8 and 9 are histograms of the daily change and daily change percentage of fuzzy price, respectively.
Step 4 : We continue to quantify price volatility. Based on Step 2, we calculate the realized volatility and the realized volatility return of the fuzzy price sequence. Figure 10 and Figure 13 provide the heat map and line graph of the realized volatility, respectively. Figures 11 and 12 show the heat map and line diagram of the realized volatility return, respectively.
Step 5 : We define the threshold value of the fuzzy price change percentage as C. We look for the date(s) when the fluctuation is lower than the previous day's C-value. We denote those dates as the dates with "big jump" of the fuzzy price. (For example, if C = 1, the date when the fuzzy price is 1% lower than the previous business day is a "big jump" day).
Step 6 : Referring to the figures and tables in the above steps, we summarize the fluctuation characteristics of the data set and divide the empirical data. This step is aimed at creating a new data structure from the existing data set. We take the fuzzy price change percentage for 10 consecutive days as an array with 10 elements in one row. After that, we augment the next row with the corresponding values for the next 10-days, and so on. The matrix will be:       a 1 , a 2 , a 3 , · · · · · · , a 10 a 2 , a 3 , a 4 , · · · · · · , a 11 a 3 , a 4 , a 5 , · · · · · · , a 12 · · · · · · a 2509 , a 2510 , a 2511 , · · · · · · , a 2518 Step 7 : We add a new target column θ to the new data frame. If there are at least two "big jumps" in the next 10 days, we set θ = 1. Otherwise, we set θ = 0.
Step 8 : We run various machine learning and deep learning algorithms to classify the new matrix data. The input is the daily change percentage of the fuzzy price for 10 consecutive days, and the output is the θ value (0 or 1) in the target column.
It is worth noting that we can improve the result by adjusting the value of C in Step 5. In addition, adjusting the data division in Step 6, we can also improve the validity of the results. The various machine learning and deep learning models involved in Step 8 provide θ values between 0 and 1. By implementing the above steps, we can find θ with reasonable accuracy and apply it to the refined BN-S model. The specific algorithm and calculation results in Step 8 are are summarized below: (A) Logistic regression: Logistic regression is a well-known method in machine learning.
It is often used for two-result classification.
(B) Decision tree: As a supervised classification algorithm, decision tree is a process of generating decision results (or tree diagram) based on historical experience (or training set). We perform attribute selection on fuzzy price data, measure and determine the topological structure between each characteristic attribute, construct a decision tree, and then find the value of θ through the overall optimal decision result.   Heatmap for the realized volatility return in percentage over the ten years for the fuzzy price (C) Random Forest: Random forest is a classifier in machine learning that contains many decision trees and can be effectively run on large data sets. Its output is determined by the mode of the category output by the individual tree. We divide the fuzzy price data set into a training set and a testing set, instantiate the model, and use the standardized data to fit the model. After that, we measure the accuracy of the model through the training data, and then estimate the θ value.
(D) Neural network: Neural network is the basic algorithm of deep learning. It performs distributed and parallel information processing by constructing multiple "neurons" to form a multilayer network. We build a neural network with two hidden layers and an output layer to estimate θ.
(E) Long and short-term memory neural network (LSTM): LSTM is a special recurrent neural network (RNN) that has the characteristics of maintaining long-term memory of information. We put the implementation of LSTM in the LstmLayer class, use the forward method to achieve forward calculation, and use the backward method to achieve back propagation. The activation function of the gate is the sigmoid function, and the output activation function is tanh.
(F) Batch normalizer (BN) in LSTM network: Batch normalizer solves the problem of vanishing-gradient or gradient-explosion by adjusting the input of the activation function. It also helps to improve the training speed of the LSTM network.
In the result tables (Tables 3 to 12), we provide classification reports based on the above algorithms. Some of the times, the results of machine learning are not completely accurate. In order to observe the feasibility of each algorithm, we use "precision" to represent the accuracy of all (i.e., θ = 1 and θ = 0) estimation results. This can be specifically quantified as the ratio of the number of accurately predicted θ = 1 (or θ = 0) to the number of all θ = 1 (or, θ = 0) prediction results. "Recall" is used to describe the efficiency of θ = 1 (or, θ = 0) being accurately predicted. It can be specifically quantified as the ratio of the number of accurately predicted θ = 1 (or, θ = 0) to the actual number of θ = 1 (or, θ = 0). The values of "precision" and "recall" are positively correlated with the accuracy of the algorithm's prediction. We compute "f 1-score" (the harmonic mean of "precision" and "recall") to evaluate the prediction effect of each algorithm. In the following tables, "support" means the number of samples in the calculation.
In these tables (Tables 3 to 12), we show the dynamic estimation results of the value of θ. Different algorithms have different prediction effects on the same data set. But different combinations of results and accuracy provide more decision support indicators for us to determine the value of θ. According to the fuzzy data of stock index during different time spans, machine learning and deep learning algorithms can update the predicted value of θ in real time, and increase the accuracy of the prediction. It helps us find the deterministic component in the stochastic dynamics of stock index. Once θ is determined, we can apply it to the refined BN-S model introduced in Section 2.

Conclusions
The refined BN-S model inherits many advantages of the classical BN-S model in analyzing financial price fluctuations. In addition, it efficiently addresses some issues with the classical BN-S model. For example the refined model incorporates long-term dependence. This paper considers an application of the refined BN-S model in the context of stock index. Based on machine learning algorithms and fuzzy theory, deterministic component θ is extracted from completely random time series fluctuations of a financial stock index. Data preprocessing involving fuzzy parameters can more accurately describe the range of fuzzy changes in market prices. Fuzzy prices containing different risk preferences, different market trends, and different investment objectives help us find a more suitable θ. Machine and deep learning algorithms are shown to help extract the effective information hidden in financial data. We apply various data-science-based techniques to identify θ. Through the analysis of fuzzy price data, the fitting of random fluctuations is realized. The analysis is shown to be helpful to determine appropriate value of θ.        The development and application of stochastic model introduced in this paper can optimize the function of traditional model, realize accurate dynamic fluctuation analysis, and enrich the theoretical basis of financial risk management. Future research will continue to focus on the application of the refined BN-S model in financial market analysis.