Euler–Maruyama method

In Itô calculus, the Euler–Maruyama method (also simply called the Euler method) is a method for the approximate numerical solution of a stochastic differential equation (SDE). It is an extension of the Euler method for ordinary differential equations to stochastic differential equations named after Leonhard Euler and Gisiro Maruyama. The same generalization cannot be done for any arbitrary deterministic method.[1]

Consider the stochastic differential equation (see Itô calculus)

with initial condition X0 = x0, where Wt denotes the Wiener process, and suppose that we wish to solve this SDE on some interval of time [0, T]. Then the Euler–Maruyama approximation to the true solution X is the Markov chain Y defined as follows:

  • Partition the interval [0, T] into N equal subintervals of width :
  • Set Y0 = x0
  • Recursively define Yn for 0 ≤ n ≤ N-1 by
where

The random variables ΔWn are independent and identically distributed normal random variables with expected value zero and variance Δt.

Example

Numerical simulation

Gene expression modelled as a stochastic process.

An area that has benefited significantly from SDEs is mathematical biology. As many biological processes are both stochastic and continuous in nature, numerical methods of solving SDEs are highly valuable in the field.

The graphic depicts a stochastic differential equation solved using the Euler-Maruyama method. The deterministic counterpart is shown in blue.

Computer implementation

The following Python code implements the Euler–Maruyama method and uses it to solve the Ornstein–Uhlenbeck process defined by

The random numbers for are generated using the NumPy mathematics package.

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt


class Model:
    """Stochastic model constants."""
    THETA = 0.7
    MU = 1.5
    SIGMA = 0.06


def mu(y: float, _t: float) -> float:
    """Implement the Ornstein–Uhlenbeck mu."""
    return Model.THETA * (Model.MU - y)


def sigma(_y: float, _t: float) -> float:
    """Implement the Ornstein–Uhlenbeck sigma."""
    return Model.SIGMA


def dW(delta_t: float) -> float:
    """Sample a random number at each call."""
    return np.random.normal(loc=0.0, scale=np.sqrt(delta_t))


def run_simulation():
    """ Return the result of one full simulation."""
    T_INIT = 3
    T_END = 7
    N = 1000  # Compute at 1000 grid points
    DT = float(T_END - T_INIT) / N
    TS = np.arange(T_INIT, T_END + DT, DT)
    assert TS.size == N + 1

    Y_INIT = 0

    ys = np.zeros(TS.size)
    ys[0] = Y_INIT
    for i in range(1, TS.size):
        t = T_INIT + (i - 1) * DT
        y = ys[i - 1]
        ys[i] = y + mu(y, t) * DT + sigma(y, t) * dW(DT)

    return TS, ys


def plot_simulations(num_sims: int):
    """ Plot several simulations in one image."""
    for _ in range(num_sims):
        plt.plot(*run_simulation())

    plt.xlabel("time")
    plt.ylabel("y")
    plt.show()


if __name__ == "__main__":
    NUM_SIMS = 5
    plot_simulations(NUM_SIMS)

Euler–Maruyama Example

The following is simply the translation of the above code into the MATLAB (R2019b) programming language:

%% Initialization and Utility
close all;
clear all;

numSims = 5;            % display five runs
tBounds = [3 7];        % The bounds of t
N       = 1000;         % Compute at 1000 grid points
dt      = (tBounds(2) - tBounds(1)) / N ;
y_init  = 0;            % Initial y condition 


% Initialize the probability distribution for our
% random variable with mean 0 and stdev of sqrt(dt)
pd = makedist('Normal',0,sqrt(dt));

c = [0.7, 1.5, 0.06];   % Theta, Mu, and Sigma, respectively

ts = linspace(tBounds(1), tBounds(2), N); % From t0-->t1 with N points
ys = zeros(1,N);     % 1xN Matrix of zeros

ys(1) = y_init;
%% Computing the Process
for j = 1:numSims
    for i = 2:numel(ts)
        t = tBounds(1) + (i-1) .* dt;
        y = ys(i-1);
        mu      = c(1) .* (c(2) - y);
        sigma   = c(3);
        dW      = random(pd);
        
        ys(i) = y + mu .* dt + sigma .* dW;
    end
    figure;
    hold on;
    plot(ts, ys, 'o')
end

See also

References

  1. ^ Kloeden, P.E. & Platen, E. (1992). Numerical Solution of Stochastic Differential Equations. Springer, Berlin. ISBN 3-540-54062-8.

Read other articles:

1993 Egyptian presidential confirmation referendum ← 1987 4 October 1993 1999 → Registered18,897,866Turnout84.16%   Candidate Hosni Mubarak Party NDP Popular vote 15,095,025 Percentage 96.28% President before election Hosni Mubarak NDP Elected President Hosni Mubarak NDP Politics of Egypt Member State of the African Union Member State of the Arab League Constitution (history) Government President (list) Abdel Fattah el-Sisi Prime Minister (list) Mostafa Madbouly C…

Державний комітет телебачення і радіомовлення України (Держкомтелерадіо) Приміщення комітетуЗагальна інформаціяКраїна  УкраїнаДата створення 2003Керівне відомство Кабінет Міністрів УкраїниРічний бюджет 1 964 898 500 ₴[1]Голова Олег НаливайкоПідвідомчі орг…

Women's rugby league competition in the United Kingdom For the women's football league, see Women's Super League. Women's Super LeagueCurrent season, competition or edition: 2024 RFL Women's Super LeagueSportRugby leagueFounded2017; 7 years ago (2017)No. of teams8CountryEnglandMost recentchampion(s) York Valkyrie (1st title)Most titles Leeds Rhinos (2 titles)TV partner(s)Sky SportsLevel on pyramid1Relegation toRFL Women's ChampionshipDomestic cup(s)Women's Challenge CupOfficial…

此条目序言章节没有充分总结全文内容要点。 (2019年3月21日)请考虑扩充序言,清晰概述条目所有重點。请在条目的讨论页讨论此问题。 哈萨克斯坦總統哈薩克總統旗現任Қасым-Жомарт Кемелұлы Тоқаев卡瑟姆若马尔特·托卡耶夫自2019年3月20日在任任期7年首任努尔苏丹·纳扎尔巴耶夫设立1990年4月24日(哈薩克蘇維埃社會主義共和國總統) 哈萨克斯坦 哈萨克斯坦政府與…

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أبريل 2019)Learn how and when to remove this message توني جاردين   معلومات شخصية الميلاد 5 مارس 1952 (72 سنة)  مواطنة المملكة المتحدة  الحياة العملية المهنة مدرس،  وصحفي،  وناقد رأي&…

إكتابا الإحداثيات 32°19′31″N 35°03′11″E / 32.325372222222°N 35.053133333333°E / 32.325372222222; 35.053133333333   تقسيم إداري  البلد دولة فلسطين[1]  التقسيم الأعلى طولكرم  معلومات أخرى 327  رمز جيونيمز 283614  الموقع الرسمي الموقع الرسمي  تعديل مصدري - تعديل   حي إكتابا،[2] ه…

Member of the British royal family (born 2003) Lady Louise Mountbatten-WindsorLady Louise in 2017BornLouise Alice Elizabeth Mary Mountbatten-Windsor (2003-11-08) 8 November 2003 (age 20)Frimley Park Hospital, Frimley, Surrey, United KingdomEducationSt George's School, Windsor CastleSt Mary's School AscotAlma materUniversity of St Andrews (currently attending)ParentsPrince Edward, Duke of Edinburgh (father)Sophie Rhys-Jones (mother)FamilyHouse of Windsor Lady Louise Alice Elizabeth Mary…

الإسلام سؤال وجوابالشعارمعلومات عامةموقع الويب https://islamqa.infoتجاري؟ لانوع الموقع موقع ويب تاريخ الإطلاق 1996 (منذ 28 سنة)التأسيس 1997 الوضع الحالي نشطالجوانب التقنيةاللغة 16 لغة مختلفة العربية، الإنجليزية، الفرنسية، الأردية، الإسبانية، الأغورية، الألمانية، الإندونيسية، البرتغا…

State park in Oregon, United States Valley of the Rogue State ParkA campsite in the park in September 2005Show map of OregonShow map of the United StatesTypePublic, stateLocationJackson County, OregonNearest cityGrants PassCoordinates42°24′39″N 123°08′59″W / 42.4109546°N 123.1497741°W / 42.4109546; -123.1497741[1]Elevation1,050 ft.[2]Operated byOregon Parks and Recreation Department Valley of the Rogue State Park is a state park in we…

Writing system from Elam Linear ElamiteLinear Elamite characters inventoried by 1912.[1]Script type Semisyllabary [a] or logosyllabic[b]Time periodc. 2300–1850 BCEStatusExtinctDirectionLeft-to-right, right-to-left script LanguagesElamiteRelated scriptsParent systemsProto-writingProto-Elamite?Linear Elamite Linear Elamite was a writing system used in Elam during the Bronze Age between c. 2300 and 1850 BCE, and known mainly from a few extant monumental in…

Monastery Mount St Bernard AbbeyMount St Bernard AbbeyLocation within LeicestershireMonastery informationOrderTrappistsEstablished1835AbbotDom Peter Claver Craddy, OCSOSiteLocationNear Coalville, Leicestershire, EnglandCoordinates52°44′29″N 1°19′23″W / 52.741352°N 1.323072°W / 52.741352; -1.323072Public accessyes Mount St Bernard Abbey is a Roman Catholic monastery belonging to the Trappist Order, near Coalville, Leicestershire, England, founded in 1835 in the…

البابا بيوس الحادي عشر عرف في مرسومه البابوي الذي دعا فيه إلى اعتماد الأخلاق المسيحية في الاقتصاد. هناك مجموعة متنوعة من وجهات النظر المسيحية حول الفقر والغنى. وفقا لإحدى وجهات النظر، تعتبر الثروة والمادية شرًا يجب تجنبه وحتى مكافحته. على الجانب الآخر، هناك وجهة نظر تعتبر ا…

Major League Baseball team season 2005 Oakland AthleticsLeagueAmerican LeagueDivisionWestBallparkMcAfee ColiseumCityOakland, CaliforniaRecord88–74 (.543)Divisional place2ndOwnersLewis WolffGeneral managersBilly BeaneManagersKen MachaTelevisionKICU-TVFSN Bay Area(Ray Fosse, Tim Roye, Hank Greenwald, Glen Kuiper)RadioKFRC(Bill King, Ken Korach)KZSF(Fernando Arias, Julio Gonzalez) ← 2004 Seasons 2006 → The Oakland Athletics' 2005 season was their 37th in Oakland, Califo…

Australian rules footballer Australian rules footballer Andrew Boston Boston in August 2018Personal informationFull name Andrew BostonDate of birth (1994-03-23) 23 March 1994 (age 30)Place of birth Gold Coast, Queensland, AustraliaOriginal team(s) Broadbeach (NEAFL)Draft No. 55, 2013 Rookie Draft, Gold CoastHeight 180 cm (5 ft 11 in)Weight 79 kg (174 lb)Position(s) Small forward, MidfielderPlaying career1Years Club Games (Goals)2013–2015 Gold Coast 16 (10) 1 …

Writing medium, especially for writing in cuneiform List of the victories of Rimush, king of Akkad, upon Abalgamash, king of Marhashi, and upon Emahsini, King of Elam, c. 2270 BCE. In the Ancient Near East, clay tablets (Akkadian ṭuppu(m) 𒁾)[1] were used as a writing medium, especially for writing in cuneiform, throughout the Bronze Age and well into the Iron Age. Cuneiform characters were imprinted on a wet clay tablet with a stylus often made of reed (reed pen). Once written…

2015 UK local government election 2015 Gravesham Borough Council election[1] ← 2011 7 May 2015 2019 → All 44 seats in the Gravesham Borough Council23 seats needed for a majority   First party Second party   Party Conservative Labour Last election 19 seats, 50.4% 25 seats, 45.1% Seats won 23 21 Seat change 4 4 Popular vote 20,763 16,901 Percentage 42.2% 34.3% Swing 8.2% 10.8% Map of the results of the 2015 Gravesham council election. Lab…

العلاقات السعودية الكينية   كينيا   السعودية تعديل مصدري - تعديل   العلاقات السعودية الكينية هي العلاقات الثنائية بين كينيا و المملكة العربية السعودية. التاريخ العلاقات بين السعودية وكينيا علاقات ودية. زار الرئيس دانيال اراب موي المملكة العربية السعودية في عام…

Continent For other uses, see Africa (disambiguation). AfricaShow national bordersHide national bordersArea30,370,000 km2 (11,730,000 sq mi)  (2nd)Population1,393,676,444[1][2] (2021; 2nd)Population density46.1/km2 (119.4/sq mi) (2021)GDP (PPP)$8.05 trillion (2022 est; 4th)[3]GDP (nominal)$2.96 trillion (2022 est; 5th)[4]GDP per capita$2,180 (Nominal; 2022 est; 6th)[5]ReligionsChristianity (49%)Islam (42%)Traditional fait…

新美 南吉(にいみ なんきち) 誕生 渡邊 正八1913年7月30日 日本・愛知県知多郡半田町(現・半田市)別名 新美 正八(本名)死没 (1943-03-22) 1943年3月22日(29歳没) 日本・愛知県半田市墓地 愛知県半田市北谷墓地職業 作家、教師国籍 日本活動期間 1931年 - 1943年ジャンル 児童文学、童謡代表作 『ごん狐』(1932年)『デンデンムシノカナシミ』(1935年)『おぢいさんのラン…

Russian physician and psychoanalyst (1885–1942) Sabina SpielreinBornSheyve (Elisheva) Naftulovna Spielrein(1885-11-07)7 November 1885 OSRostov-on-Don, Russian EmpireDied11 August 1942(1942-08-11) (aged 56)Zmievskaya Balka, Rostov-on-Don, Soviet UnionNationalityRussianAlma materUniversity of Zurich (M.D., 1911)Known fordeath instinctchild psychotherapypsycholinguisticsSpouse Pavel Nahumovich Sheftel ​ ​(m. 1912; died 1936)​Scientifi…