<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>of continuous time portfolio with given properties</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Sergey G. Shorokhov</string-name>
          <email>shorokhov-sg@rudn.ru</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Peoples' Friendship University of Russia (RUDN University)</institution>
          ,
          <addr-line>6 Miklukho-Maklaya St, Moscow, 117198, Russian</addr-line>
        </aff>
      </contrib-group>
      <fpage>33</fpage>
      <lpage>44</lpage>
      <abstract>
        <p>A continuous-time version of portfolio management problem for a market with multiple stocks is under study. Asset allocation policy is determined implicitly as a solution to the system of ordinary diferential equations for asset quantities. Right-hand sides of equations are derived explicitly in closed form from given portfolio properties using techniques of construction of diferential equations by given integral manifold. Related issues of simulation for portfolio with desired properties are also addressed. We present the results of computer experiment for verification of specified portfolio property using constructed portfolio model in the form of the system of stochastic diferential equations.</p>
      </abstract>
      <kwd-group>
        <kwd>Markov decision process</kwd>
        <kwd>portfolio policy</kwd>
        <kwd>stochastic process</kwd>
        <kwd>SDE simulation</kwd>
        <kwd>OpenCL framework</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>Modeling with stochastic diferential equations is used extensively in many areas of modern
research [1]. Stochastic diferential equations (SDE) arise in modeling and simulation of various
random dynamical systems in physical [2], chemical [3], biological [4], financial [ 4] and other
sciences.</p>
      <p>Stochastic models based on SDE are an integral part of quantitative analysis of wireless
channels in communications [5]. Modeling of signals and interference in communications
requires construction of SDE with specified properties, such as given marginal probability
density function and autocovariance function. Applications of SDE in other areas usually also
imply construction of SDE with desired characteristics.</p>
      <p>We study asset allocation problem for a portfolio with specified properties using
continuoustime continuous-state Markov decision process, determined implicitly by a system of diferential
equations. Our goal is to derive right-hand sides of equations by known portfolio properties and
verify the required portfolio property in a computer experiment using simulation techniques.
Workshop on information technology and scientific computing in the framework of the XI International Conference
CEUR
Workshop
Proceedings
© 2021 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0).
2. Implicit Markov decision process for portfolio management
Markov decision process [6] is a widely used approach to decision making, including applications
in finance.</p>
      <p>Consider a market in which  no dividend stocks are traded continuously and transaction cost
and consumption are not taken into account. The stock price processes   ( ),  = 1,  generally
satisfy the system of SDE [7]:

=1
  =   (,  ) +</p>
      <p>∑   (,  )  ,  = 1, ,  ⩽ ,
where   (,  )are drift terms,   (,  )are volatility terms,  1, ...,   are independent standard
Wiener processes,  = ( 1, ...,   ).</p>
      <p>The initial stock prices at  =  0 are assumed to be known:</p>
      <p>Let   ( )be the quantity (in units) of the  -th stock in the portfolio at time  . We assume that
the quantity   ( )can be positive (long position), negative (short position) or zero (no position)
and can take fractional values.</p>
      <p>The value process of the stock portfolio  ( )at time  is determined by the formula
  ( 0)=  
(0) &gt; 0,  = 1, .

=1
 ( )= ∑   ( )   ( ).
  =   (, s, x),  =</p>
      <p>1, 
The share (weight)   ( )of the  -th stock in the portfolio  ( )is equal to
  ( )=
  ( )   ( )
 ( )
=

  ( )   ( )
∑
=1   ( )   ( )
,  = 1, .</p>
      <p>The weights   ( )are not all independent, because of the norming condition ∑</p>
      <p>The state of the stock portfolio can be determined either by prices s = ( 1, ...,   )and quantities
x = ( 1, ...,   ), or by prices s = ( 1, ...,   ), weights w = ( 1, ...,   )and total portfolio value  ( ).

=1   ( )= 1.</p>
      <p>We assume that the portfolio state is given by price-quantity pair (s, x).</p>
      <p>The portfolio state (s, x)varies because of changes in stock prices s due to market situation
or changes in stock quantities x due to policy (actions) of portfolio manager.</p>
      <p>Possible actions for the  -th stock in the portfolio are to hold the stock, to buy or to sell some
units of the stock.</p>
      <p>As a result of actions for the time period △ &gt; 0 change in the quantity of units of the  -th
stock in the portfolio is equal to △  =   ( + △ )−   ( ). If △  &gt; 0, then △  units of the stock
are purchased, if △  &lt; 0, then |△  | units of the stock are sold, if △  = 0, then   ( )units of the
stock are being held in the portfolio.</p>
      <p>
        Asset allocation policy x ( )may be explicit with quantities of stocks being functions of time
and/or stock prices, i.e. x = x (, s). We assume that asset allocation policy x ( )is determined
implicitly as a solution of the system of diferential equations
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
(
        <xref ref-type="bibr" rid="ref2">2</xref>
        )
(
        <xref ref-type="bibr" rid="ref3">3</xref>
        )
(
        <xref ref-type="bibr" rid="ref4">4</xref>
        )
(
        <xref ref-type="bibr" rid="ref5">5</xref>
        )
with initial conditions (initial stock quantities)
 [  (, s ( ), x ( ))] = 0,  = 1, , ∀ ⩾  0,
      </p>
      <p>
        Actually, the system (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) should be treated as a system of SDE with zero difusion coeficients,
because right-hand sides of system (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) depend on stochastic stock price processes   ( ), following
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) with initial conditions (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ).
      </p>
      <p>
        When functions   (, s, x)in (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) are fixed, the portfolio management policy is fully determined
by equations (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) and (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) with initial conditions (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) and (
        <xref ref-type="bibr" rid="ref6">6</xref>
        ), the portfolio dynamics depends only
on the initial state of the portfolio (s(0), x(0)) at time  0 and is independent of the past ( &lt;  0).
      </p>
      <p>
        Thus, we determine the portfolio policy by choosing various functions   (, s, x) on the
right-hand side of equations (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) and receive Markov decision process for portfolio management.
3. Construction of portfolio with given properties
Construction of stock portfolio with desired characteristics and evaluation of its risk and
performance using simulation and optimization plays extremely important role in modern
ifnancial industry [ 8]. The desired properties of the portfolio can be a given rate of return, a
given risk metric (variance of return, value at risk, expected shortfall), given structural (country,
industry, rating) ratios, etc.
      </p>
      <p>As we will show below, portfolio management policy may be based on construction of
ordinary diferential equations (ODE) by a given integral manifold. Originally, construction of
ODE from a given integral curve was proposed by Yerugin [9] and later extended to dynamical
systems of general nature by Galiullin [10], Mukharlyamov [11] and many other authors [12].</p>
      <p>The method is widely used in investigations of controlled dynamical systems and allows
to construct equations of motion from given properties of trajectories taking into account
additional requirements, such as stability of the given manifold or optimality in some sense.
The problem of construction of equations in the class of Ito SDE by known properties of motion
was investigated by Tleubergenov [13, 14, 15].</p>
      <p>
        We assume that price dynamics of stocks in the portfolio is described by SDE (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) with initial
conditions (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) and quantities of stocks follow Markov portfolio policy, implicitly determined by
equations (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) with initial conditions (
        <xref ref-type="bibr" rid="ref6">6</xref>
        ). The functions on the right-hand sides of equations (
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
and (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) are assumed to be continuous in time  and Lipschitz in portfolio state variables s, x.
      </p>
      <p>We consider portfolio properties in the form of  equalities</p>
      <p>(, s, x)= 0,  = 1, ,  &lt; 
 ) is of maximum rank  .
where Jacobian  ×  -matrix ( x</p>
      <p>
        Basically, the stochasticity of stock prices driven by SDE (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) leads to violation of equalities
(
        <xref ref-type="bibr" rid="ref7">7</xref>
        ), so our goal is to find a portfolio policy of the form (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ), which ensures that equalities (
        <xref ref-type="bibr" rid="ref7">7</xref>
        ) are
satisfied on ensemble average, i.e.
(
        <xref ref-type="bibr" rid="ref6">6</xref>
        )
(
        <xref ref-type="bibr" rid="ref7">7</xref>
        )
(
        <xref ref-type="bibr" rid="ref8">8</xref>
        )
where
      </p>
      <p>(,  )is the probability density function of  ( )at time  .</p>
      <p>
        This statement of the problem difers from common approach to construction of stochastic
diferential equations by given integral manifold [ 13], when properties (
        <xref ref-type="bibr" rid="ref7">7</xref>
        ) are supposed to
be satisfied exactly. But in portfolio management problem this implies restrictions on price
equations (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ), which is not relevant for financial market models.
      </p>
      <p>Stochastic diferentials of   can be calculated using the multidimensional Ito’s formula [17]
  = (

  + ∑
  
=1  
  
=1  
  + ∑
  +</p>
      <p>1 ∑
2 =1 =1 ℎ=1
∑
∑  ℎ  ℎ
 2  ) +
   
 
+ ∑
∑  ℎ</p>
      <p>ℎ,  = 1, .</p>
      <p>
        Arbitrary (unknown) functions   in (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) can be chosen in such a way that the following
equalities hold true

  + ∑
  
=1  
  + ∑
  
=1  
  +
      </p>
      <p>1 ∑
2 =1 =1 ℎ=1
∑
∑  ℎ  ℎ</p>
      <p>2  = − ∑     ,  = 1, ,
=1
where</p>
      <p>
        (, s, x)are arbitrary functions. Equations (
        <xref ref-type="bibr" rid="ref11">11</xref>
        ) can be regarded as a system of  linear
algebraic equations for  unknown functions   :
where
  
∑
=1  

 = −  ,  = 1, ,

=1
  = ∑     +

  + ∑
  
=1  
  +
      </p>
      <p>1 ∑
2 =1 =1 ℎ=1
∑
∑  ℎ  ℎ
 2 
   
.</p>
      <p>
        Applying the methodology of Moore–Penrose pseudoinverse matrices [18] to system (
        <xref ref-type="bibr" rid="ref12">12</xref>
        ),
we obtain the solution of (
        <xref ref-type="bibr" rid="ref12">12</xref>
        ) in the following matrix form:
where  denotes expected value (ensemble average) [16] and for a stochastic process  ( )
+∞
−∞
 [ ( )] = ∫   (,  ),
f = − (

 x
      </p>
      <p>+
 ) + [  − (
 x
 )
+  ] , (
 x
 x</p>
      <p>+
 ) =
 
 x
(
 x  x
   −1
) ,
where  =</p>
      <p>
        ( 1, ...,   ) ,   is the identity  ×  -matrix, = (Φ1, ..., Φ ) is a vector of arbitrary
functions. The pseudoinverse matrix (
of (
        <xref ref-type="bibr" rid="ref12">12</xref>
        ) in the following final form
highest rank  . Substituting the corresponding expression from (
        <xref ref-type="bibr" rid="ref12">12</xref>
        ) for  , we obtain the solution
 )
 x
+
exists, because the Jacobian matrix   x
has the
f = − (
 x
      </p>
      <p>+
 ) [Λ  +


+</p>
      <p>+

 s
2
1 tr (   2
 x2  )] + [  − (
 x
 )
+  ] ,</p>
      <p>x
33–44</p>
      <p>
        (
        <xref ref-type="bibr" rid="ref9">9</xref>
        )
(
        <xref ref-type="bibr" rid="ref10">10</xref>
        )
(
        <xref ref-type="bibr" rid="ref11">11</xref>
        )
(
        <xref ref-type="bibr" rid="ref12">12</xref>
        )
(
        <xref ref-type="bibr" rid="ref13">13</xref>
        )
(
        <xref ref-type="bibr" rid="ref14">14</xref>
        )
where Λ = (  ), tr is matrix trace operation.
      </p>
      <p>We additionally assume that for any ,  =
receive that</p>
      <p>
        1,  the random variables   and   are
independent, then, averaging the equalities (
        <xref ref-type="bibr" rid="ref10">10</xref>
        ) along ensemble of trajectories under the policy (
        <xref ref-type="bibr" rid="ref14">14</xref>
        ), we
 [  ]
      </p>
      <p>
        =1
= − ∑  [  ]  [  ] ,  = 1, .
(
        <xref ref-type="bibr" rid="ref15">15</xref>
        )
4. Modeling self-financing portfolio with given structure
We consider a self-financing portfolio with cash account and two risky assets (stocks), driven
by geometric Brownian motion, and assume that the portfolio management policy is given in
The system of ODE (
        <xref ref-type="bibr" rid="ref15">15</xref>
        ) admits the trivial solution  [  ] = 0,  =
1,  , which implies that
the portfolio with stock dynamics (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) and portfolio policy (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) admits portfolio properties (
        <xref ref-type="bibr" rid="ref8">8</xref>
        ).
      </p>
      <p>Thus, we receive the following statement on Markov portfolio policies with given portfolio
properties.</p>
      <p>
        Markov asset allocation policy (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) with right-hand sides given by (
        <xref ref-type="bibr" rid="ref14">14</xref>
        ) admits the specified
portfolio properties (
        <xref ref-type="bibr" rid="ref8">8</xref>
        ), provided that Λ = (  (, s, x))is an arbitrary  ×  -matrix such that the
random variables   (, s ( ), x ( ))and   (, s ( ), x ( ))are independent, (, s, x)is an arbitrary
column vector.
      </p>
      <p>
        Portfolio asset allocation policy (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) with right-hand sides given by (
        <xref ref-type="bibr" rid="ref14">14</xref>
        ) can be applied to
portfolios containing stocks, currencies and commodities. By choosing arbitrary functions  
and Φ it is possible to ensure the stability of portfolio policy or to find an optimal policy for
given reward function and discount factor.
      </p>
      <p>Asset portfolio can include cash account, be self-financing, and incorporate other additional
features. The value of portfolio with cash account and  risky assets is equal to
 ( )=  0 ( )+ ∑   ( )   ( ),
where  0 ( )denotes the balance of cash account at time  .</p>
      <p>
        The portfolio is self-financing [ 17], if no external inflow or outflow of cash and stocks takes
place and the purchase of a stock must be financed by cash on cash account or by sale of some
stocks from the portfolio. The portfolio with cash account is self-financing, if [ 17]
where  &gt; 0 is the fixed interest rate of cash account. This implies that the balance of cash
account  0 satisfies the following equation [ 19]
where functions   from (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ) determine the portfolio policy.

=1

=1
 0 = (  0 − ∑     ) ,
implicit form (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ). The portfolio dynamics is determined by the following system of SDE:
⎧  1 =  1  1  +  1  1  1,
⎪⎪  2 =  2  2  +  2  2  2,
      </p>
      <p>0 = (  0 −  1 1 (, s, x)−  2 2 (, s, x)),
⎨
⎪ 1 =  1 (, s, x),
⎪
⎩ 2 =  2 (, s, x).</p>
      <p>Here  1,  2 are the stock prices,  0 is the balance of cash account,  1,  2 are the quantities of
stocks in the portfolio, s = ( 1,  2), x = ( 0,  1,  2),  1,  2 are the instantaneous rates of return,
 1,  2 are the volatilities of stocks,  1,  2 are independent standard Wiener processes,  is the
interest rate of cash account.</p>
      <p>We assume that the desired portfolio property is the condition that 80% of the portfolio assets
is invested in risky assets (stocks).</p>
      <p>The value of the portfolio under consideration is equal to  =  0 +  1 1 +  2 2, and weights
of cash and stocks are equal to
 0 =</p>
      <p>0
 0 +  1 1 +  2 2
,  1 =</p>
      <p>1 1
 0 +  1 1 +  2 2
,  2 =</p>
      <p>2 2
 0 +  1 1 +  2 2
.</p>
      <p>The desired portfolio property can be expressed as the following relation between the stock
weights  1 and  2:
 1 +  2 =</p>
      <p>
        1 1 +  2 2
 0 +  1 1 +  2 2
= 0.8,
which can be transformed into the equality
33–44
(
        <xref ref-type="bibr" rid="ref16">16</xref>
        )
(
        <xref ref-type="bibr" rid="ref17">17</xref>
        )
(
        <xref ref-type="bibr" rid="ref18">18</xref>
        )
(
        <xref ref-type="bibr" rid="ref19">19</xref>
        )
(
        <xref ref-type="bibr" rid="ref20">20</xref>
        )
 ≡ −4 0 +  1 1 +  2 2 = 0.
      </p>
      <p>
        Our goal is to determine the unknown functions  1,  2 in (
        <xref ref-type="bibr" rid="ref16">16</xref>
        ) to guarantee the portfolio
property (
        <xref ref-type="bibr" rid="ref17">17</xref>
        ) on ensemble average.
      </p>
      <p>According to Ito’s lemma the stochastic diferential of  is equal to
 =
(−4  0 +  1 1 1 +  2 2 2 + 5 1 1 + 5 2 2) + 
1 12 1 +  2 22 2.</p>
      <p>We set the unknown functions  1,  2 so, that the drift term at  is equal to − ,  ∈ ℝ :
− 4  0 +  1 1 1 +  2 2 2 + 5 1 1 + 5 2 2 = −.</p>
      <p>
        Equality (
        <xref ref-type="bibr" rid="ref19">19</xref>
        ) is the linear algebraic equation for the determination of unknown functions
 1,  2, and the general solution of equation (
        <xref ref-type="bibr" rid="ref19">19</xref>
        ) is:
      </p>
      <p>1 = −  12 +1  22  +  2 ,  2 = −  12 +2  22  −  1 ,
where  = 0.2 − 0.8</p>
      <p>0 + 0.2 1 1 1 + 0.2 2 2 2,  ∈ ℝ ,  is an arbitrary function of , s, x.</p>
      <p>
        Thus, SDE system (
        <xref ref-type="bibr" rid="ref16">16</xref>
        ) for modeling prices and quantities of the portfolio with given property
(
        <xref ref-type="bibr" rid="ref17">17</xref>
        ) takes the following form with an arbitrary constant  ∈ ℝ and an arbitrary function  :
⎧
⎪
⎪
⎪
⎪
⎪
      </p>
      <p>1 =  1  1   + 
⎪   2 =  2  2   +</p>
      <p>0 = (  + 0.2 
⎨  1 = (− 12 +  22
⎪</p>
      <p>⎪  2 = (− 12 +  22</p>
      <p>
        ⎩
,
,
5. Simulation of self-financing portfolio with given structure
version of SDE (
        <xref ref-type="bibr" rid="ref21">21</xref>
        ).
      </p>
      <p>
        To verify that the portfolio model (
        <xref ref-type="bibr" rid="ref21">21</xref>
        ) satisfies the portfolio property (
        <xref ref-type="bibr" rid="ref17">17</xref>
        ) we simulate the
trajectories of system (
        <xref ref-type="bibr" rid="ref21">21</xref>
        ) for the time segment [ 0,  ].
      </p>
      <p>So we divide the segment [ 0,  ] into  equal parts of length ℎ =  − 0 and simulate a discretized</p>
      <p>
        There exists a number of discretization schemes available, such as Milstein scheme [20] and
stochastic version of Runge-Kutta methods [21, 22], but the most intuitive, easy to implement
and common is Euler-Maruyama scheme [23]. Euler-Maruyama discretization of (
        <xref ref-type="bibr" rid="ref21">21</xref>
        ) gives us
the following equations:
⎪
⎪
⎪
⎪
⎩
⎨⎪ 1,+1 =  1, −
⎪ 2,+1 =  2, −
⎧  1,+1 =  1, +  1  1, ℎ +  1  1, √ℎ 1, ,
⎪  2,+1 =  2, +  2  2, ℎ +  2  2, √ℎ 2, ,
⎪ 0,+1 =  0, + (   + 0.2  0, + 0.2 1 1,  1, + 0.2 2 2,  2, )ℎ,
0.2   − 0.8  0, + 0.2 1 1,  1, + 0.2 2 2,  2,
0.2   − 0.8  0, + 0.2 1 1,  1, + 0.2 2 2,  2,
2
2
 1, +  2,
 1, +  2,
2
2
 1, ℎ +  2,  ℎ,
 2, ℎ −  1,  ℎ,
where  ,
=   (
 ),  ,
=   (
      </p>
      <p>
        ),   =  0 + ℎ ,   = −4 0, +  1,  1, +  2,  2, ,  , are i.i.d. random
variables with standard normal distribution, i.e.  ,
∼ 
(
        <xref ref-type="bibr" rid="ref1">0, 1</xref>
        ).
      </p>
      <p>Basically, simulation of SDE is a resource-intensive application, so to speed up the simulation
one has to enable GPU acceleration. PyOpenCL [24] is a programming environment for access
to OpenCL parallel computation framework [25] from Python language.</p>
      <p>
        To apply PyOpenCL environment for portfolio simulation, one has to follow the typical
sequence of steps:
1. Import the OpenCL API, obtain an OpenCL platform and a GPU device id:
import pyopencl as cl
plat = cl.get_platforms()[0]
dev = plat.get_devices()[2]
33–44
(
        <xref ref-type="bibr" rid="ref21">21</xref>
        )
(
        <xref ref-type="bibr" rid="ref22">22</xref>
        )
2. Initialize a context for the selected GPU device, create a Queue object (with profiling
enabled to track computation time), create memory bufers on GPU for input and output
data (here p, q and s_gpu are NumPy arrays):
opencl_context = cl.Context(devices=[dev])
command_queue = cl.CommandQueue(opencl_context,
      </p>
      <p>properties=cl.command_queue_properties.PROFILING_ENABLE)
p_buffer = cl.Buffer(opencl_context,</p>
      <p>cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR, hostbuf=p)
q_buffer = cl.Buffer(opencl_context,</p>
      <p>cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR, hostbuf=q)
s_buffer = cl.Buffer(opencl_context,</p>
      <p>
        cl.mem_flags.WRITE_ONLY, s_gpu.nbytes)
3. Store the source code of C functions for GPU execution in Python strings (sde_step_src
contains source code of one step of SDE simulation according to (
        <xref ref-type="bibr" rid="ref22">22</xref>
        ), simulate_sde_src
contains source code of main kernel function, being called from Python):
sde_step_src = """
// One step of SDE simulation
static void sde_step(__global double *p, double *x, double W)
{
double s1n, s2n, x0n, x1n, x2n;
x[5] = -0.8*x[2] + 0.2*x[3]*x[0] + 0.2*x[4]*x[1]; // omega
s1n = p[P_M1]*x[0]*p[P_DT] + p[P_S1]*x[0]*p[P_SQRDT]*W;
s2n = p[P_M2]*x[1]*p[P_DT] + p[P_S2]*x[1]*p[P_SQRDT]*W;
x0n = (p[P_A]*x[5] + 0.2*p[P_R]*x[2] + 0.2*p[P_M1]*x[3]*x[0] +
0.2*p[P_M2]*x[4]*x[1])*p[P_DT];
x1n = -x[0]*(p[P_A]*x[5] - 0.8*p[P_R]*x[2] + 0.2*p[P_M1]*x[3]*x[0] +
0.2*p[P_M2]*x[4]*x[1])*p[P_DT]/(x[0]*x[0]+x[1]*x[1]);
x2n = -x[1]*(p[P_A]*x[5] - 0.8*p[P_R]*x[2] + 0.2*p[P_M1]*x[3]*x[0] +
0.2*p[P_M2]*x[4]*x[1])*p[P_DT]/(x[0]*x[0]+x[1]*x[1]);
x[0] += s1n; x[1] += s2n; x[2] += x0n; x[3] += x1n; x[4] += x2n;
}"""
simulate_sde_src = """
// GPU kernel function to simulate trajectories of SDE
__kernel void simulate_sde(__global double *p, __global int *q,
__global double *s)
{
// Indexing the current element (trajectory) to process
int i = get_global_id(0);
// Pointer to the i'th row of s (output)
__global double *s_i = &amp;s[i*6]; // 6 values in output
// Simultaneous calculation of SDE trajectories within OpenCL kernel
double x[6]; // placeholders for s1,s2,x0,x1,x2,omega
int q_i = (int) q[i], *seed = &amp;q_i;
const double r4_pi = 3.141592653589793;
double v1,v2;
for (int j = 0; j &lt; 5; j++) { x[j] = p[P_S10+j]; }
for (int j = 0; j &lt; (int) p[P_N]/2.; j++) { // 2 steps of SDE
v1 = r8_uniform_01 ( seed );
v2 = r8_uniform_01 ( seed );
sde_step( p, x, sqrt(-2.0*log(v1))*cos(2.0*r4_pi*v2) );
sde_step( p, x, sqrt(-2.0*log(v1))*sin(2.0*r4_pi*v2) );
}
for (int j = 0; j &lt; 6; j++) { s_i[j] = x[j]; }
}"""
4. Compile the GPU C program from source:
opencl_program = cl.Program(opencl_context,
      </p>
      <p>sde_hdr_src+sde_rng_src+sde_step_src+simulate_sde_src).build()
5. Enqueue the SDE simulation program on the GPU device and wait until the program
completion:
event = opencl_program.simulate_sde(command_queue, s_gpu.shape, None,
p_buffer, q_buffer, s_buffer)
event.wait()
6. Get back the output data from GPU memory into NumPy array s_gpu:</p>
      <p>cl.enqueue_copy(command_queue, s_gpu, s_buffer).wait()</p>
      <p>Function r8_uniform_01 is an implementation of uniform random number generator [26],
C++ versions of other random number generators may be found in [27]. Standard normally
distributed random variables  , are implemented with Box–Muller transform [28].</p>
      <p>
        Simulation of discretized equations (
        <xref ref-type="bibr" rid="ref22">22</xref>
        ) is performed using computer program in Python
with the following parameters:
 1,0 = 0.9,  2,0 = 1.1,  1 = 0.3,  1 = 0.4,  2 = −0.1,  2 = 0.3,  0 = 0.,  = 1.
      </p>
      <p>0,0 = 90.,  1,0 = 110.,  2,0 = 100.,  = 0.05,  = 1.,  ≡ 0,  = 100.</p>
      <p>The results of the computer experiment are shown in Fig. 1. Green line on the last plot with
stock weights shows that the total share of stocks  1 +  2 tends to the value of 0.8, which is the
target property of the portfolio under consideration.</p>
      <p>
        Thus, constructed equations (
        <xref ref-type="bibr" rid="ref22">22</xref>
        ) generate trajectories with empirical portfolio property close
to the given property (
        <xref ref-type="bibr" rid="ref17">17</xref>
        ).
      </p>
    </sec>
    <sec id="sec-2">
      <title>Acknowledgments</title>
      <p>The research was funded by RFBR, grant No. 19-08-00261.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>E.</given-names>
            <surname>Allen</surname>
          </string-name>
          ,
          <article-title>Modeling with Itô Stochastic Diferential Equations</article-title>
          ,
          <source>Mathematical Modelling: Theory and Applications</source>
          , Springer Netherlands,
          <year>2007</year>
          . doi:
          <volume>10</volume>
          .1007/978-1-
          <fpage>4020</fpage>
          -5953-7.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>N. V.</given-names>
            <surname>Kampen</surname>
          </string-name>
          , Stochastic diferential equations,
          <source>Physics Reports</source>
          <volume>24</volume>
          (
          <year>1976</year>
          )
          <fpage>171</fpage>
          -
          <lpage>228</lpage>
          . doi:
          <volume>10</volume>
          .1016/
          <fpage>0370</fpage>
          -
          <lpage>1573</lpage>
          (
          <issue>76</issue>
          )
          <fpage>90029</fpage>
          -
          <lpage>6</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>R. P.</given-names>
            <surname>King</surname>
          </string-name>
          ,
          <article-title>Applications of stochastic diferential equations to chemical-engineering problems: An introductory review</article-title>
          ,
          <source>Chemical Engineering Communications</source>
          <volume>1</volume>
          (
          <year>1974</year>
          )
          <fpage>221</fpage>
          -
          <lpage>237</lpage>
          . doi:
          <volume>10</volume>
          .1080/00986447408960433.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>C. A.</given-names>
            <surname>Braumann</surname>
          </string-name>
          ,
          <article-title>Introduction to Stochastic Diferential Equations with Applications to Modelling in Biology</article-title>
          and Finance, Wiley,
          <year>2019</year>
          . doi:
          <volume>10</volume>
          .1002/9781119166092.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>S.</given-names>
            <surname>Primak</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Kontorovich</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Lyandres</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Stochastic</given-names>
            <surname>Methods</surname>
          </string-name>
          and Their Applications to Communications, Wiley,
          <year>2004</year>
          . doi:
          <volume>10</volume>
          .1002/0470021187.
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>R.</given-names>
            <surname>Bellman</surname>
          </string-name>
          ,
          <article-title>A markovian decision process</article-title>
          ,
          <source>Journal of Mathematics and Mechanics</source>
          <volume>6</volume>
          (
          <year>1957</year>
          )
          <fpage>679</fpage>
          -
          <lpage>684</lpage>
          . doi:
          <volume>10</volume>
          .1512/iumj.
          <year>1957</year>
          .
          <volume>6</volume>
          .56038.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>X. Y.</given-names>
            <surname>Zhou</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. G.</given-names>
            <surname>Yin</surname>
          </string-name>
          ,
          <article-title>Markowitz's mean-variance portfolio selection with regime switching: A continuous-time model</article-title>
          ,
          <source>SIAM J. Control. Optim</source>
          .
          <volume>42</volume>
          (
          <year>2003</year>
          )
          <fpage>1466</fpage>
          -
          <lpage>1482</lpage>
          . doi:
          <volume>10</volume>
          .1137/ S0363012902405583.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>D. A.</given-names>
            <surname>Pachamanova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F. J.</given-names>
            <surname>Fabozzi</surname>
          </string-name>
          ,
          <source>Portfolio Construction and Analytics</source>
          , John Wiley &amp; Sons, Inc,
          <year>2016</year>
          . doi:
          <volume>10</volume>
          .1002/9781118656747.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>N.</given-names>
            <surname>Erugin</surname>
          </string-name>
          ,
          <article-title>Construction to all set of diferential systems having a given invariant curve</article-title>
          ,
          <source>Prikladnaia matematica i mehanika 16</source>
          (
          <year>1952</year>
          )
          <fpage>659</fpage>
          -
          <lpage>670</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>A. S.</given-names>
            <surname>Galiullin</surname>
          </string-name>
          ,
          <article-title>Certain problems in the design of programmed-motion systems</article-title>
          ,
          <source>in: Symposia on Theoretical Physics and Mathematics 8</source>
          ,
          <string-name>
            <surname>Springer</surname>
            <given-names>US</given-names>
          </string-name>
          ,
          <year>1968</year>
          , pp.
          <fpage>185</fpage>
          -
          <lpage>192</lpage>
          . doi:
          <volume>10</volume>
          .1007/978-1-
          <fpage>4684</fpage>
          -7721-4_
          <fpage>16</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>R. G.</given-names>
            <surname>Mukharlyamov</surname>
          </string-name>
          ,
          <article-title>On the construction of diferential equations of motion of constrained mechanical systems</article-title>
          ,
          <source>Diferential Equations</source>
          <volume>39</volume>
          (
          <year>2003</year>
          )
          <fpage>369</fpage>
          -
          <lpage>380</lpage>
          . doi:
          <volume>10</volume>
          .1023/a:
          <fpage>1026021701825</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>R. G.</given-names>
            <surname>Mukharlyamov</surname>
          </string-name>
          ,
          <string-name>
            <surname>M. I. Tleubergenov</surname>
          </string-name>
          ,
          <article-title>Control of system dynamics and constraints stabilization</article-title>
          ,
          <source>in: Communications in Computer and Information Science</source>
          , Springer International Publishing,
          <year>2017</year>
          , pp.
          <fpage>431</fpage>
          -
          <lpage>442</lpage>
          . doi:
          <volume>10</volume>
          .1007/978-3-
          <fpage>319</fpage>
          -66836-9_
          <fpage>36</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <surname>M. I. Tleubergenov</surname>
          </string-name>
          ,
          <article-title>An inverse problem for stochastic diferential systems</article-title>
          ,
          <source>Diferential Equations</source>
          <volume>37</volume>
          (
          <year>2001</year>
          )
          <fpage>751</fpage>
          -
          <lpage>753</lpage>
          . doi:
          <volume>10</volume>
          .1023/a:
          <fpage>1019285119532</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <surname>M. I. Tleubergenov</surname>
          </string-name>
          ,
          <article-title>On the inverse stochastic reconstruction problem</article-title>
          ,
          <source>Diferential Equations</source>
          <volume>50</volume>
          (
          <year>2014</year>
          )
          <fpage>274</fpage>
          -
          <lpage>278</lpage>
          . doi:
          <volume>10</volume>
          .1134/s0012266114020165.
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>M.</given-names>
            <surname>Tleubergenov</surname>
          </string-name>
          , and
          <string-name>
            <given-names>G.T.</given-names>
            <surname>Ibraeva</surname>
          </string-name>
          and,
          <article-title>On inverse problem of closure of diferential systems with degenerate difusion</article-title>
          ,
          <source>Eurasian Mathematical Journal</source>
          <volume>10</volume>
          (
          <year>2019</year>
          )
          <fpage>93</fpage>
          -
          <lpage>102</lpage>
          . doi:
          <volume>10</volume>
          .32523/2077-9879-2019-10-2-
          <fpage>93</fpage>
          -102.
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <given-names>O. C.</given-names>
            <surname>Ibe</surname>
          </string-name>
          ,
          <article-title>Markov Processes for Stochastic Modeling</article-title>
          , 2nd edition ed.,
          <source>Elsevier</source>
          ,
          <year>2013</year>
          . doi:
          <volume>10</volume>
          .1016/c2012-0-06106-6.
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <given-names>T.</given-names>
            <surname>Björk</surname>
          </string-name>
          , Arbitrage Theory in Continuous Time, 4th edition ed., Oxford University Press,
          <year>2019</year>
          . doi:
          <volume>10</volume>
          .1093/oso/9780198851615.001.0001.
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <given-names>G.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wei</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Qiao</surname>
          </string-name>
          ,
          <source>Generalized Inverses: Theory and Computations</source>
          , Springer Singapore,
          <year>2018</year>
          . doi:
          <volume>10</volume>
          .1007/
          <fpage>978</fpage>
          -981-13-0146-9.
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [19]
          <string-name>
            <given-names>S.</given-names>
            <surname>Shorokhov</surname>
          </string-name>
          , Management of Financial Asset Portfolios, RUDN University,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          [20]
          <string-name>
            <surname>G. N.</surname>
          </string-name>
          <article-title>Mil'shtejn, Approximate integration of stochastic diferential equations</article-title>
          ,
          <source>Theory of Probability &amp; Its Applications</source>
          <volume>19</volume>
          (
          <year>1975</year>
          )
          <fpage>557</fpage>
          -
          <lpage>562</lpage>
          . doi:
          <volume>10</volume>
          .1137/1119062.
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          [21]
          <string-name>
            <given-names>P. E.</given-names>
            <surname>Kloeden</surname>
          </string-name>
          , E. Platen, Numerical Solution of Stochastic Diferential Equations, Springer Berlin Heidelberg,
          <year>1992</year>
          . doi:
          <volume>10</volume>
          .1007/978-3-
          <fpage>662</fpage>
          -12616-5.
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          [22]
          <string-name>
            <given-names>M. N.</given-names>
            <surname>Gevorkyan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T. R.</given-names>
            <surname>Velieva</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. V.</given-names>
            <surname>Korolkova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D. S.</given-names>
            <surname>Kulyabov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L. A.</given-names>
            <surname>Sevastyanov</surname>
          </string-name>
          ,
          <article-title>Stochastic Runge-Kutta software package for stochastic diferential equations</article-title>
          ,
          <source>in: Dependability Engineering and Complex Systems</source>
          , Springer International Publishing,
          <year>2016</year>
          , pp.
          <fpage>169</fpage>
          -
          <lpage>179</lpage>
          . doi:
          <volume>10</volume>
          .1007/978-3-
          <fpage>319</fpage>
          -39639-2_
          <fpage>15</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          [23]
          <string-name>
            <given-names>G.</given-names>
            <surname>Maruyama</surname>
          </string-name>
          ,
          <article-title>Continuous markov processes and stochastic equations</article-title>
          ,
          <source>Rendiconti del Circolo Matematico di Palermo</source>
          <volume>4</volume>
          (
          <year>1955</year>
          )
          <fpage>48</fpage>
          -
          <lpage>90</lpage>
          . doi:
          <volume>10</volume>
          .1007/bf02846028.
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          [24]
          <string-name>
            <given-names>A.</given-names>
            <surname>Klöckner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Pinto</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Lee</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Catanzaro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Ivanov</surname>
          </string-name>
          ,
          <string-name>
            <surname>A</surname>
          </string-name>
          . Fasih,
          <article-title>PyCUDA and PyOpenCL: A scripting-based approach to GPU run-time code generation</article-title>
          ,
          <source>Parallel Computing</source>
          <volume>38</volume>
          (
          <year>2012</year>
          )
          <fpage>157</fpage>
          -
          <lpage>174</lpage>
          . URL: https://doi.org/10.1016%2Fj.parco.
          <year>2011</year>
          .
          <volume>09</volume>
          .001. doi:
          <volume>10</volume>
          .1016/j.parco.
          <year>2011</year>
          .
          <volume>09</volume>
          .001.
        </mixed-citation>
      </ref>
      <ref id="ref25">
        <mixed-citation>
          [25]
          <string-name>
            <given-names>B.</given-names>
            <surname>Gaster</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Howes</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D. R.</given-names>
            <surname>Kaeli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Mistry</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Schaa</surname>
          </string-name>
          , Heterogeneous Computing with OpenCL, Elsevier,
          <year>2012</year>
          . doi:
          <volume>10</volume>
          .1016/c2011- 0- 69669- 3.
        </mixed-citation>
      </ref>
      <ref id="ref26">
        <mixed-citation>
          [26]
          <string-name>
            <given-names>J.</given-names>
            <surname>Burkardt</surname>
          </string-name>
          , UNIFORM
          <article-title>- a uniform random number generator (RNG</article-title>
          ),
          <year>2019</year>
          . URL: https: //people.sc.fsu.edu/~jburkardt/c_src/uniform/uniform.html.
        </mixed-citation>
      </ref>
      <ref id="ref27">
        <mixed-citation>
          [27]
          <string-name>
            <given-names>M. N.</given-names>
            <surname>Gevorkyan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. V.</given-names>
            <surname>Demidova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. V.</given-names>
            <surname>Korolkova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D. S.</given-names>
            <surname>Kulyabov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L. A.</given-names>
            <surname>Sevastianov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>I. M.</given-names>
            <surname>Gostev</surname>
          </string-name>
          ,
          <article-title>Pseudo-random number generator based on neural network</article-title>
          ,
          <source>in: CEUR Workshop Proceedings</source>
          , volume
          <volume>2267</volume>
          ,
          <year>2018</year>
          , pp.
          <fpage>568</fpage>
          -
          <lpage>572</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref28">
        <mixed-citation>
          [28]
          <string-name>
            <given-names>G. E. P.</given-names>
            <surname>Box</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. E.</given-names>
            <surname>Muller</surname>
          </string-name>
          ,
          <article-title>A note on the generation of random normal deviates</article-title>
          ,
          <source>The Annals of Mathematical Statistics</source>
          <volume>29</volume>
          (
          <year>1958</year>
          )
          <fpage>610</fpage>
          -
          <lpage>611</lpage>
          . doi:
          <volume>10</volume>
          .1214/aoms/1177706645.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>