=Paper= {{Paper |id=Vol-2588/paper23 |storemode=property |title=Forecasting Stock Prices and Accounting for Stock Market on Multicore Computers |pdfUrl=https://ceur-ws.org/Vol-2588/paper23.pdf |volume=Vol-2588 |authors=Lesia Mochurad,Nataliya Boyko,Natalia Stanasiuk |dblpUrl=https://dblp.org/rec/conf/cmigin/MochuradBS19 }} ==Forecasting Stock Prices and Accounting for Stock Market on Multicore Computers== https://ceur-ws.org/Vol-2588/paper23.pdf
      Forecasting Stock Prices and Accounting for Stock
               Market on Multicore Computers

           Lesia Mochurad1[0000-0002-4957-1512], Nataliya Boyko1[0000-0002-6962-9363],

                               Natalia Stanasiuk [0000-0002-6885-9431]

                Lviv Polytechnic National University, Lviv79013, Ukraine
          lesia.i.mochurad@lpnu.ua, nataliya.i.boyko@lpnu.ua,
                        nataliya.s.stanasiuk@lpnu.ua



         Abstract. The paper proposes an approach to solving multidimensional systems
         of nonlinear equations based on the use of the OpenMP parallelization mecha-
         nism and the multicore architecture of modern computers. The software prod-
         uct, which performs the main function - the parallelization of the numerical so-
         lution of multidimensional SNE by the Newton method, is developed. The pa-
         per introduces the algorithm of parallelization of the Black-Scholes algorithm
         based on OpenMP technology for prediction of the option on the European
         market is proposed. The analysis of the speed and efficiency of calculations
         with different number of processor cores is carried out. As a result, appropriate
         estimates of the acceleration and efficiency coefficients were obtained. The
         proposed method is easily scaled to a different number of processor cores. A
         number of numerical experiments were conducted. The obtained results also in-
         dicate the possibility of further optimization of the computational process by
         developing the multi-core architecture of modern computers.

         Keywords: Forecasted Option, Black-Scholes Method, Paralleling, Multi-
         threading.


     1        Introduction

In a modern economic society it is impossible to do without forecasting. One of the
approaches is to use the Black-Scholes method for prediction the behavior of the
stock on the stock market for a certain time. The purpose of this work is to create a
program that will allow you to quickly and effectively use the Black-Scholes method
algorithm in practice. The paper introduces the algorithm of parallelization of the
Black-Scholes algorithm based on OpenMP technology for prediction of the option on
the European market is proposed. For implementation were used the Microsoft Visual
Studio 2017 programming environment, the C ++ programming technology, and
OpenMP standard (Open Multi-Processing).
   Black-Scholes method requires fast execution of the program. One of the best ways
to speed up the work of a software product is to use the directives of parallelization of

    Copyright © 2020 for this paper by its authors. Use permitted under Creative Commons License Attrib-
ution 4.0 International (CC BY 4.0) CMiGIN-2019: International Workshop on Conflict Management in
Global Information Networks.
modern OpenMP technology. It allows to compare the results obtained and to analyze
the speed and efficiency of the program with different streams and the corresponding
multi-core architecture of modern computers. The object of the study is a parallel
algorithm for forecasting options in the European market. The object of the research
is the use of OpenMP technology in the process of parallelizing the Black-Scholes
method.


    2       Review of the Literature

Known [1-4], that the market for derivatives, derivatives of securities can perform its
functions and stabilize the economy only under condition of reliable forecasting of
prices for options.The problems of mathematical modeling of processes in economics
and finances paid attention many Ukrainian scientists, among them Alekseev A.,
Besedin V., Veliky A., Vitlinsky V., Heyets V., Yeleyko Ya., Kostina N., Lukinov I.,
Sergienko I . Modern science has developed a fairly reliable apparatus for determin-
ing the fair price of an option. In the study of this problem, the contribution of domes-
tic (Leonenko M., Mishura Yu., Parkhomenko V., Yadrenko M.) and foreign (Merton
R., Bryan JO, Shiryaev A.) scientists is significant. World-famous is the Black-
Scholes model.
    The Black-Scholes method is one of the most effective stock market actions in
predicted behavior [5]. Thanks to it, buyers / sellers of shares can get an estimate of
the option price for the future and know whether they need to buy / sell their underly-
ing assets.
    When using the Black-Scholes method, you should be prepared for the next:

1. The method requires a large amount of input data.
2. The method requires a powerful computer to quickly process and process these da-
   ta.
3. The method has minimal error and risk.

Option requirements, the value of which can be determined by the Black-Scholes
method, limit its use for real options. So, using the method involves the assumption
that there is a fixed date of option execution or decision making. Therefore, as a rule,
this method is only suitable for options related to the scale of the project, in particular
the expansion options, and can not be used for options related to the duration of the
project and the reduction or refusal of the project. In fact, the limitation on the appli-
cation of the Black-Scholes method naturally arises because the method itself was
created to determine the value of financial options, for which a fixed date is mandato-
ry. For real options related to the term of execution, reduction or refusal of the pro-
ject, it is worth using the binomial method [6].
      3       Statement of the problem

To successfully solve current tasks of current management of socio-economic pro-
cesses, it is necessary to carry out a thorough quantitative analysis of these processes
in order to forecast them. In our society a lot of things need to be predicted. Every day
we see or hear the weather forecast, the forecast of currency growth, the forecast of
changes in oil and gas prices, and others. For great precision, any method of forecast-
ing requires the processing of a large amount of data. The study of the theoretical
price for European options is also very important. You can do this by using the Black-
Scholes Options pricing method [7].
    This model is widely used in practice, among other things, can be used to evaluate
all derivatives, including converting securities, and even to assess the equity of finan-
cially dependent firms.
    According to the Black-Scholes model, the key element in determining the value of
an option is the expected volatility of the underlying asset. Depending on the fluctua-
tion of the asset, the price increases or decreases, which directly affects the cost of the
option. Thus, if the value of the option is known, then it is possible to determine the
level of volatility expected by the market [1-3].
    The task is to develop a parallel algorithm for forecasting options in the European
market based on the Black-Scholes method and the modern OpenMP parallel pro-
gramming technology [8, 9]. And also create a software product that could be used
effectively in practice. To perform the above task you need:

 Analyze the subject area, available input and output data;
 Get acquainted with possible ways to solve the problem and choose the best one;
 Thoroughly examine the algorithm of the method and evaluate the implementation
  methods;
 Create ways to store data;
 Organize the Black-Scholes method;
 Enable the possibility of parallel execution of the program

3.1       Black-Scholes model for option evaluation
An option is a contract concluded between two investors, one of which writes out
(sells) an option, and the other one buys it and acquires the right (but not obligation)
in the term specified in the option term or to purchase a fixed asset at a fixed price ( in
its composition may include, for example, futures contracts) of the person that the
option, or sell him the asset.
    In this regard, the following options are distinguished [10]:

 Call option – the right of the buyer of the option (and not his obligation) to obtain
  from the seller the option of a certain property value (equity, loan, etc.) at a fixed
  price, or to make a calculation, in the agreed time.
 Put option – the right to sell property value at a fixed price, or make a settlement at
  a certain future time point.
 Currently, the terms "call" and "put" are used as standard notation for options,
  regardless of their basis. Stock exchange sometimes introduce option-to-double op-
  tions - they contain the seller's right to realize a double amount of value (commodi-
  ty, security, security), which is the basis of the option, - Put-to-more Option, or
  buyer's right to purchase a double amount these values - Call-of-more Option.

  The owner (buyer) of the option pays the seller a kind of commission - the premi-
um per unit of the underlying asset, which is called the price, or the full value of the
option (like the price of the insurance policy).
  The size of the bonus affects a whole set of factors:

 the ratio between the current (market and contract prices);
 term of the option;
 stability of the course of the underlying asset.

   The buyer's risk in the options deal is within the premium paid to them; the seller's
risk is not limited and the latter's income is based on premiums. The buyer's payment
of the premium is obligatory and is made on the stock exchange through the payment.
   The price of the underlying asset (its unit), agreed in the option contract, is called
the exercise price (exercise) of the option, or the contract price.
   Here it should be emphasized that there are three types of different options within
the options for buying (calling) and selling (put) shares, each of which has its own
peculiarities.
   These include:

 Internal options - have a strike price below the current market price for the put
  option. This means that the buyer of such an option can immediately exercise his
  right and earn a net income. However, given that each participant in options trad-
  ing is interested in profitable transactions, then, as a rule, the premium on internal
  options always covers the specified price difference. With respect to such options,
  there is a notion of intrinsic price. It is always equal to the difference between the
  market price and the execution price.
 Market options - have an exercise price equal to or very close to the price of the
  underlying stock at the time of the option sale.
 External Options - characterized by the fact that their exercise prices are well
  above the base stock price under call options and significantly lower for put op-
  tions.

Thus, from these types of options we can see the relationship between the contract
price and the risk [11]. Therefore, the premium increases from the first kind to the
last.
   Our program will use the classic options, they are based on the fact that the options
that were the subject of the agreement from the beginning, firmly fixed the future
price of the basis (or the value of the calculated indicator). In conventional classic
options, the principle of constant price applies throughout the life of the contract.
   In 1973, F. Black and M. Scholes published an article, The Pricing of Options and
Corporate Liabilities, in the Journal of Political Economy. The model proposed in this
article has radically changed the approach to the analysis of options and other securi-
ties. To determine the value of the option, the authors proposed a formula whose start-
ing elements are known except one, and even this single element can be estimated in a
reasonable approximation [5, 9].
   Black and Scholes made a number of baseline assumptions that many researchers
are working to validate. Among these tenets are:
1. You can estimate the fluctuations (standard deviation) of the stock return.
2. There is a constant interest rate on risk-free investments over time.
3. There is no cost to conclude the agreement; when concluding agreements without
coverage for a term (transactions with a short position), the seller receives money
immediately.
4. Taxes do not matter.
5. No dividends.
6. The share price is a random value; the price for period t has a log-normal distribu-
tion.
7. Trading is carried out continuously.

    Obviously, this assumption is an idealization of real market power. Therefore, they
should not be considered as joining people designed to use these models.
    The model's conclusion is based on the concept of risk-free hedging. By buying
stocks and at the same time selling call options on these stocks, an investor can con-
struct a risk-free position where earnings on the shares will accurately offset losses on
the options, and vice versa [17].
    The risk-free hedged position should yield a profit at a rate equal to the risk-free
interest rate, otherwise there would be an opportunity to remove the arbitrage income
and investors, trying to take advantage of this opportunity, would bring the option
price to the equilibrium level determined by the model.
    The Black-Scholes model is based on the assumption that future stock returns have
a log-normal distribution with constant root mean square deviation - and that's all that
is said about common stock returns. The expected return on them in this model affects
the price of the option only indirectly, because of the stock price.

3.2    Black-Scholes algorithm
The option cost is calculated using the Black-Scholes formula developed to evaluate
financial options [12]:

                              F  SN ( d )  S  N ( d ) ,                           (1)
                                               1     0        2

  Where

                                           S
                                      ln        (  0.5 2 )  T
                                           S
                          d       
                                             0                     ,                 (2)
                              1                    T
                                      S
                                 ln        (  0.5 2 )  T
                                      S
                     d       
                                        0                      d  T ,              (3)
                         2                    T                 1

   Here, N (x ) the probability that the deviation will be less under the conditions of
the standard normal distribution (thus, and limit the range of values for the function of
the standard normal distribution);
    S - the current market value of the shares;
      S - the price of execution;
       0
  T -the expiration time of the option in years;
   - standard annual deviation of the stock price.
  From the analysis of this formula, it follows that the option price is then higher
when:

 the current market price of the stock is high (S);
 more time before the expiration of the option (T);
 greater risk.

   Therefore, to increase the investment attractiveness of the project, it is more appro-
priate for companies to focus on increasing revenues rather than reducing costs.
   The main difficulties that may arise when applying this model are related to obtain-
ing reliable source data required for the calculation (time to implementation of the
projected capabilities, values of variance and others).

3.3        The parallelization algorithm of the Black-Scholes method
At each iteration of the Black-Scholes algorithm, the following operations are per-
formed:
   1. A pricing vector is created based on market price, risk, volatility, and time
        step.
   1.1. We create an array of normally distributed random variables.
   1.2. We calculate the estimated price at a given step.
   1.3. Write down the value in the array of possible stock values.
   1.4. We find the average of the array of all possible values at this step. This is an
        average value and will be our predicted price at some point.
   In order to parallel this algorithm, we propose to use OpenMP concurrent pro-
gramming technology, which can be considered as a high-level add-on over Pthreads
(or similar thread libraries). OpenMP implements multi-threaded computations, in
which the master thread creates a set of slave threads and the task is shared between
them. It is assumed that threads run in parallel on a machine with multiple processors
(the number of processors need not be greater than or equal to the number of threads)
[13-17].
   The tasks that flow in parallel, as well as the data needed to perform these tasks,
are described using the specific preprocessor directives of the respective language -
pragm. The number of streams created can be controlled by the program itself, by
calling library procedures and externally, using environment variables [12,14].
   Advantages of this technology:

 with the idea of "incremental parallelization", OpenMP is ideal for developers
  seeking to quickly parallel their computing programs with large, parallel cycles.
  The developer does not create a new concurrent program, but simply sequentially
  adds OpenMP directives to the program text;
 OpenMP is a rather flexible mechanism, which gives the developer great control
  over the behavior of the parallel program;
 it is envisaged that the OpenMP program on a single-processor platform can be
  used as a serial program, ie there is no need to support serial and parallel versions.
  OpenMP directives are simply ignored by a serial compiler, and stubs can be in-
  voked to call OpenMP procedures;
 support for the so-called "orphan" (detached) directives, that is, directives for syn-
  chronization and division of labor may not be directly within the lexical context of
   a parallel domain.


     4       Numerical experiments

The first step is to create the file ml_data.csv, which records the input data required
for our method. Namely: 180 numbers, which in percentage show the behavior of the
stock in the European market for 180 minutes. The data is written in one line, without
spaces, but through commas.




Fig. 1. The contents of the ml_data.csv file.

   The program has the following basic functions:

 calcVolatility(calculates volatility);
 find2DMean(finds the average value in the stock data array);
 randGen(generates an array of random numbers based on the normal distribution);
 runBlackScholesModel(designs the Black-Scholes model).

  The result of the program execution is written to the opt.scv file, which will have
180 data describing the behavior of the price at each time step as a percentage.
Fig. 1. The output from the file opt.csv (1).




Fig. 2. The output from the file opt.csv (2).

   calcVolatility(float spotPrice, int timesteps): a function that calculates volatility
based on stock input.
   Stages of execution:
 Reading the file.
 The data in the file is recorded in a single tape. We read the tape, close the file.
 We turn a string into a stream.
 Extract values read from a file and write them to an array.
 We find the average value of the calculated prices in one minute.
 Calculation of market volatility as standard deviation.
 The function returns volatility as a percentage.




  find2DMean(float **matrix, int numLoops, int timesteps):a function that finds the
mean of the 2D array through the first index inLoops.
  Stages of execution:

 A private copy of the 'sum' variable is created for each thread.
 At the end of the run, all private copies of the variable that are written to the global
  variable are available
 We calculate the average value by columns
 Return the mean
   randGen(float mean, float stdDev):randGen function Creates a random number
based on the standard distribution of the mean of 0.0 and standard deviation of 1.0.




runBlackScholesModel (float spotPrice, int timesteps, float riskRate, float volatility):
a function that designs the Black-Scholes model.
  Stages of execution:
  1. Create an array of normally distributed random variables, an array of stock
      prices at each time interval.
  2.   We put a stock price at the beginning of data processing equal to the market
       price.
  3.   Fill the array with random normal values.
  4.   We force the Black-Scholes method to calculate the stock price for the next pe-
       riod of time.

                                       2 
                    С  S  exp r                  rand   ,                 (5)
                                       2 
                                          
  where:
  С - predicted value;
  S - market price;
  r - risk (0.001);
   - volatile;
     1/ t ;
   rand – normally distributed random variable.




     5       Analysis of results

In Fig. 4. Black-Scholes option forecasting schedule for the next 180 minutes is pre-
sented.




Fig. 3. Increase in shares for the next 180 minutes.

   In the experimental study, Black-Shouse stock prediction was performed in parallel
with one, two, four and eight threads on eight nuclear processors using OpenMP tech-
nology. In the Table 1 shows the results of numerical experiments.
                         Table 1. Parallel algorithm execution time.
     Flows                          1                  2           4             8
     Temporary review, s            3367               1673        883           526

   Analyzing the results, we can conclude that with the increase in the number of
flows, the time during which the algorithm of the program finds forecasting the option
price in the European market is almost halved.
   The acceleration coefficient according to the formula is calculated in the paper. In
the Table 2 shows the value of the coefficient when the number of threads varies. The
graph of acceleration change depending on the number of threads on the octa-core
processor is presented in Fig. 5.

                      Table 2. The value of the acceleration coefficient.
         Flows                                   Acceleration
         1                                       1
         2                                       2,01
         4                                       3,813
         8                                       6,401




Fig. 4. Acceleration of algorithm execution depending on the number of threads

   The results shown in Fig. 5, show that the developed parallel algorithm provides
normal scalability, that is, the task execution time decreases proportionally as the
number of threads increases. The highest acceleration is achieved by using 8 threads
on an eight-core processor.
   The coefficient of efficiency is calculated by the formula E p  S p / p . In the Ta-
ble 3 shows the value of the coefficient when the number of threads varies. A graph of
performance changes depending on the number of threads on an octa-core processor
is presented in Fig. 6.

                          Table 3. The value of the efficiency ratio
        Threads                                 Efficiency
        1                                       1
        2                                       1,005
        4                                       0,95
        8                                       0,8001




Fig. 5. Performance of the algorithm, depending on the number of threads


    6       Conclusion

The subject area is analyzed in detail. The most universal method of finding effective
investment solutions - the Black-Scholes method, has been studied and evaluated. Has
been developed a program that enables the calculation of options forecasts in the Eu-
ropean market over a given time. To speed up the forecast, the timing of the algo-
rithm's performance has been significantly improved through the use of OpenMP
concurrent programming technology and its many-stream properties. In doing so, we
were able to compare the speed of program execution with varying the number of
threads on the octa-core computer architecture.


        References
 1. Krste, Asanovic and all.: The Landscape of Parallel Computing Reseach: A View from
    Berkeley. University of California, Berkeley. Technical Report № UCB/EECS-2006-183,
    56 p. (2006).
 2. Yakovlev, M.F., Gerasymova, T.O., Nesterenko, A.N.: Characteristic feature of the solv-
    ing both of non-linear systems and systems of ordinary differential equations on parallel
    computer. In Proceedings of international symposium “Optimization problems of compu-
    tations” (OPC - XXXV). Kyiv: V.M. Glushkov Institute of cybernetics of NAS of Ukraine,
    2009. Kyiv: Vol. 2. P. 435-439. (2009).
 3. Yakovlev, MV.F., Nesterenko, A.N., Brusnikin, V.N. Problems of the efficient solving of
    non-linear systems on multi-processor MIMD-architecture computers. Mathematical ma-
    chines and systems. (4). P. 12-17. (2014).
 4. Shakhovska, N., Boyko, N., Pukach, P.: The information model of cloud data warehouses.
    In the International conference on computer science and information technologies
    “Advances in Intelligent Systems and Computing” (AISC), Vol. 871, pp. 182–191, CSIT
    2018, Lviv, Ukraine (2018)
 5. Khymych, A.N., Molchanov, Y.N., Popov, A.V. other: Parallel algorithms for solving
    problems of computational mathematics. Kiev: Scientific Opinion, 248 pp. (2008).
 6. Autar, Kaw: NONLINEAR EQUATIONS - Newton-Raphson Method-More Examples,
    Civil Engineering. August 7, 4 pp. (2009)
 7. Boyko, N., Shakhovska, K.: Information system of catering selection by using clustering
    analysis. In 2018 IEEE Ukraine Student, Young Professional and Women in Engineering
    Congress (UKRSYW), pp.7-13, October 2 – 6, 2018, Kyiv, Ukraine (2018)
 8. Autar, Kaw: NONLINEAR EQUATIONS - Newton-Raphson Method-More Examples,
    Electrical Engineering. August 7, 4 pp. (2009)
 9. Autar, Kaw. NONLINEAR EQUATIONS - Newton-Raphson Method-More Examples,
    Mechanical Engineering. August 7, 3 pp. (2009).
10. Kakhaner, D., Mouler, K., Nэsh, S.: Numerical methods and software. «Mir» publishing
    house, 575 pp., (1998).
11. Mochurad, L.I. Method of reduction model for calculation of electrostatic fields of elec-
    tronic fields of electronic optics systems. Science journal Radioelektronіka, informatics,
    management, 1(48), pp. 29-40 (2019). (In Ukrainian)
12. Voss, M.: OpenMP Share Memory Parallel programming. Toronto, Kanada (2003).
13. Chapman, B., Jost, G., Ruud van der Pas: Using OpenMP: portable shared memory paral-
    lel programming (Scientific and Engineering Computation). Cambridge, Massachusetts:
    The MIT Press (2008).
14. Chandra, R., Menon, R., Dagum, L., Kohr, D., Maydan, D., McDonald, J.: Parallel Pro-
    gramming in OpenMP. Morgan Kaufinann Publishers (2000).
15. Ananth, Grama, Anshul, Gupta, George, Karypis, Vipin, Kumar: «Introduction to Parallel
    Computing» Addison Wesley, ISBN- 0-201-64865-2, 856 p. (2003).
16. Boyko, N.: Advanced technologies of big data research in distributed information systems.
    Radio Electronics, Computer Science, Control, vol. 4, pp. 66-77, Zaporizhzhya: Za-
    porizhzhya National Technical University (2017)
17. Mochurad, L., Nataliya, Boyko.: Solving Systems of Nonlinear Equations on Multi-core
    Processors. In the International Conference on Computer Science and Information
    Technologies Advances in Intelligent Systems and Computing IV, pр. 90-106, CSIT 2019,
    September 17–20, 2019, Lviv, Ukraine. DOI: 10.1007/978-3-030-33695-0 (2019)