In [1]:
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
In [2]:
import antipackage
import github.ellisonbg.misc.vizarray as va
Downloading: https://raw.githubusercontent.com/ellisonbg/misc/master/vizarray.py
Using existing version: github.ellisonbg.misc.vizarray
Here is a function that produces standard Brownian motion using NumPy. This is also known as a Wiener Process.
In [13]:
def brownian(maxt, n):
"""Return one realization of a Brownian (Wiener) process with n steps and a max time of t."""
t = np.linspace(0.0,maxt,n)
h = t[1]-t[0]
Z = np.random.normal(0.0,1.0,n-1)
dW = np.sqrt(h)*Z
W = np.zeros(n)
W[1:] = dW.cumsum()
return t, W
Call the brownian function to simulate a Wiener process with 1000 steps and max time of 1.0. Save the results as two arrays t and W.
In [9]:
brownian(1.0,1000)
Out[9]:
(array([ 0. , 0.001001 , 0.002002 , 0.003003 , 0.004004 ,
0.00500501, 0.00600601, 0.00700701, 0.00800801, 0.00900901,
0.01001001, 0.01101101, 0.01201201, 0.01301301, 0.01401401,
0.01501502, 0.01601602, 0.01701702, 0.01801802, 0.01901902,
0.02002002, 0.02102102, 0.02202202, 0.02302302, 0.02402402,
0.02502503, 0.02602603, 0.02702703, 0.02802803, 0.02902903,
0.03003003, 0.03103103, 0.03203203, 0.03303303, 0.03403403,
0.03503504, 0.03603604, 0.03703704, 0.03803804, 0.03903904,
0.04004004, 0.04104104, 0.04204204, 0.04304304, 0.04404404,
0.04504505, 0.04604605, 0.04704705, 0.04804805, 0.04904905,
0.05005005, 0.05105105, 0.05205205, 0.05305305, 0.05405405,
0.05505506, 0.05605606, 0.05705706, 0.05805806, 0.05905906,
0.06006006, 0.06106106, 0.06206206, 0.06306306, 0.06406406,
0.06506507, 0.06606607, 0.06706707, 0.06806807, 0.06906907,
0.07007007, 0.07107107, 0.07207207, 0.07307307, 0.07407407,
0.07507508, 0.07607608, 0.07707708, 0.07807808, 0.07907908,
0.08008008, 0.08108108, 0.08208208, 0.08308308, 0.08408408,
0.08508509, 0.08608609, 0.08708709, 0.08808809, 0.08908909,
0.09009009, 0.09109109, 0.09209209, 0.09309309, 0.09409409,
0.0950951 , 0.0960961 , 0.0970971 , 0.0980981 , 0.0990991 ,
0.1001001 , 0.1011011 , 0.1021021 , 0.1031031 , 0.1041041 ,
0.10510511, 0.10610611, 0.10710711, 0.10810811, 0.10910911,
0.11011011, 0.11111111, 0.11211211, 0.11311311, 0.11411411,
0.11511512, 0.11611612, 0.11711712, 0.11811812, 0.11911912,
0.12012012, 0.12112112, 0.12212212, 0.12312312, 0.12412412,
0.12512513, 0.12612613, 0.12712713, 0.12812813, 0.12912913,
0.13013013, 0.13113113, 0.13213213, 0.13313313, 0.13413413,
0.13513514, 0.13613614, 0.13713714, 0.13813814, 0.13913914,
0.14014014, 0.14114114, 0.14214214, 0.14314314, 0.14414414,
0.14514515, 0.14614615, 0.14714715, 0.14814815, 0.14914915,
0.15015015, 0.15115115, 0.15215215, 0.15315315, 0.15415415,
0.15515516, 0.15615616, 0.15715716, 0.15815816, 0.15915916,
0.16016016, 0.16116116, 0.16216216, 0.16316316, 0.16416416,
0.16516517, 0.16616617, 0.16716717, 0.16816817, 0.16916917,
0.17017017, 0.17117117, 0.17217217, 0.17317317, 0.17417417,
0.17517518, 0.17617618, 0.17717718, 0.17817818, 0.17917918,
0.18018018, 0.18118118, 0.18218218, 0.18318318, 0.18418418,
0.18518519, 0.18618619, 0.18718719, 0.18818819, 0.18918919,
0.19019019, 0.19119119, 0.19219219, 0.19319319, 0.19419419,
0.1951952 , 0.1961962 , 0.1971972 , 0.1981982 , 0.1991992 ,
0.2002002 , 0.2012012 , 0.2022022 , 0.2032032 , 0.2042042 ,
0.20520521, 0.20620621, 0.20720721, 0.20820821, 0.20920921,
0.21021021, 0.21121121, 0.21221221, 0.21321321, 0.21421421,
0.21521522, 0.21621622, 0.21721722, 0.21821822, 0.21921922,
0.22022022, 0.22122122, 0.22222222, 0.22322322, 0.22422422,
0.22522523, 0.22622623, 0.22722723, 0.22822823, 0.22922923,
0.23023023, 0.23123123, 0.23223223, 0.23323323, 0.23423423,
0.23523524, 0.23623624, 0.23723724, 0.23823824, 0.23923924,
0.24024024, 0.24124124, 0.24224224, 0.24324324, 0.24424424,
0.24524525, 0.24624625, 0.24724725, 0.24824825, 0.24924925,
0.25025025, 0.25125125, 0.25225225, 0.25325325, 0.25425425,
0.25525526, 0.25625626, 0.25725726, 0.25825826, 0.25925926,
0.26026026, 0.26126126, 0.26226226, 0.26326326, 0.26426426,
0.26526527, 0.26626627, 0.26726727, 0.26826827, 0.26926927,
0.27027027, 0.27127127, 0.27227227, 0.27327327, 0.27427427,
0.27527528, 0.27627628, 0.27727728, 0.27827828, 0.27927928,
0.28028028, 0.28128128, 0.28228228, 0.28328328, 0.28428428,
0.28528529, 0.28628629, 0.28728729, 0.28828829, 0.28928929,
0.29029029, 0.29129129, 0.29229229, 0.29329329, 0.29429429,
0.2952953 , 0.2962963 , 0.2972973 , 0.2982983 , 0.2992993 ,
0.3003003 , 0.3013013 , 0.3023023 , 0.3033033 , 0.3043043 ,
0.30530531, 0.30630631, 0.30730731, 0.30830831, 0.30930931,
0.31031031, 0.31131131, 0.31231231, 0.31331331, 0.31431431,
0.31531532, 0.31631632, 0.31731732, 0.31831832, 0.31931932,
0.32032032, 0.32132132, 0.32232232, 0.32332332, 0.32432432,
0.32532533, 0.32632633, 0.32732733, 0.32832833, 0.32932933,
0.33033033, 0.33133133, 0.33233233, 0.33333333, 0.33433433,
0.33533534, 0.33633634, 0.33733734, 0.33833834, 0.33933934,
0.34034034, 0.34134134, 0.34234234, 0.34334334, 0.34434434,
0.34534535, 0.34634635, 0.34734735, 0.34834835, 0.34934935,
0.35035035, 0.35135135, 0.35235235, 0.35335335, 0.35435435,
0.35535536, 0.35635636, 0.35735736, 0.35835836, 0.35935936,
0.36036036, 0.36136136, 0.36236236, 0.36336336, 0.36436436,
0.36536537, 0.36636637, 0.36736737, 0.36836837, 0.36936937,
0.37037037, 0.37137137, 0.37237237, 0.37337337, 0.37437437,
0.37537538, 0.37637638, 0.37737738, 0.37837838, 0.37937938,
0.38038038, 0.38138138, 0.38238238, 0.38338338, 0.38438438,
0.38538539, 0.38638639, 0.38738739, 0.38838839, 0.38938939,
0.39039039, 0.39139139, 0.39239239, 0.39339339, 0.39439439,
0.3953954 , 0.3963964 , 0.3973974 , 0.3983984 , 0.3993994 ,
0.4004004 , 0.4014014 , 0.4024024 , 0.4034034 , 0.4044044 ,
0.40540541, 0.40640641, 0.40740741, 0.40840841, 0.40940941,
0.41041041, 0.41141141, 0.41241241, 0.41341341, 0.41441441,
0.41541542, 0.41641642, 0.41741742, 0.41841842, 0.41941942,
0.42042042, 0.42142142, 0.42242242, 0.42342342, 0.42442442,
0.42542543, 0.42642643, 0.42742743, 0.42842843, 0.42942943,
0.43043043, 0.43143143, 0.43243243, 0.43343343, 0.43443443,
0.43543544, 0.43643644, 0.43743744, 0.43843844, 0.43943944,
0.44044044, 0.44144144, 0.44244244, 0.44344344, 0.44444444,
0.44544545, 0.44644645, 0.44744745, 0.44844845, 0.44944945,
0.45045045, 0.45145145, 0.45245245, 0.45345345, 0.45445445,
0.45545546, 0.45645646, 0.45745746, 0.45845846, 0.45945946,
0.46046046, 0.46146146, 0.46246246, 0.46346346, 0.46446446,
0.46546547, 0.46646647, 0.46746747, 0.46846847, 0.46946947,
0.47047047, 0.47147147, 0.47247247, 0.47347347, 0.47447447,
0.47547548, 0.47647648, 0.47747748, 0.47847848, 0.47947948,
0.48048048, 0.48148148, 0.48248248, 0.48348348, 0.48448448,
0.48548549, 0.48648649, 0.48748749, 0.48848849, 0.48948949,
0.49049049, 0.49149149, 0.49249249, 0.49349349, 0.49449449,
0.4954955 , 0.4964965 , 0.4974975 , 0.4984985 , 0.4994995 ,
0.5005005 , 0.5015015 , 0.5025025 , 0.5035035 , 0.5045045 ,
0.50550551, 0.50650651, 0.50750751, 0.50850851, 0.50950951,
0.51051051, 0.51151151, 0.51251251, 0.51351351, 0.51451451,
0.51551552, 0.51651652, 0.51751752, 0.51851852, 0.51951952,
0.52052052, 0.52152152, 0.52252252, 0.52352352, 0.52452452,
0.52552553, 0.52652653, 0.52752753, 0.52852853, 0.52952953,
0.53053053, 0.53153153, 0.53253253, 0.53353353, 0.53453453,
0.53553554, 0.53653654, 0.53753754, 0.53853854, 0.53953954,
0.54054054, 0.54154154, 0.54254254, 0.54354354, 0.54454454,
0.54554555, 0.54654655, 0.54754755, 0.54854855, 0.54954955,
0.55055055, 0.55155155, 0.55255255, 0.55355355, 0.55455455,
0.55555556, 0.55655656, 0.55755756, 0.55855856, 0.55955956,
0.56056056, 0.56156156, 0.56256256, 0.56356356, 0.56456456,
0.56556557, 0.56656657, 0.56756757, 0.56856857, 0.56956957,
0.57057057, 0.57157157, 0.57257257, 0.57357357, 0.57457457,
0.57557558, 0.57657658, 0.57757758, 0.57857858, 0.57957958,
0.58058058, 0.58158158, 0.58258258, 0.58358358, 0.58458458,
0.58558559, 0.58658659, 0.58758759, 0.58858859, 0.58958959,
0.59059059, 0.59159159, 0.59259259, 0.59359359, 0.59459459,
0.5955956 , 0.5965966 , 0.5975976 , 0.5985986 , 0.5995996 ,
0.6006006 , 0.6016016 , 0.6026026 , 0.6036036 , 0.6046046 ,
0.60560561, 0.60660661, 0.60760761, 0.60860861, 0.60960961,
0.61061061, 0.61161161, 0.61261261, 0.61361361, 0.61461461,
0.61561562, 0.61661662, 0.61761762, 0.61861862, 0.61961962,
0.62062062, 0.62162162, 0.62262262, 0.62362362, 0.62462462,
0.62562563, 0.62662663, 0.62762763, 0.62862863, 0.62962963,
0.63063063, 0.63163163, 0.63263263, 0.63363363, 0.63463463,
0.63563564, 0.63663664, 0.63763764, 0.63863864, 0.63963964,
0.64064064, 0.64164164, 0.64264264, 0.64364364, 0.64464464,
0.64564565, 0.64664665, 0.64764765, 0.64864865, 0.64964965,
0.65065065, 0.65165165, 0.65265265, 0.65365365, 0.65465465,
0.65565566, 0.65665666, 0.65765766, 0.65865866, 0.65965966,
0.66066066, 0.66166166, 0.66266266, 0.66366366, 0.66466466,
0.66566567, 0.66666667, 0.66766767, 0.66866867, 0.66966967,
0.67067067, 0.67167167, 0.67267267, 0.67367367, 0.67467467,
0.67567568, 0.67667668, 0.67767768, 0.67867868, 0.67967968,
0.68068068, 0.68168168, 0.68268268, 0.68368368, 0.68468468,
0.68568569, 0.68668669, 0.68768769, 0.68868869, 0.68968969,
0.69069069, 0.69169169, 0.69269269, 0.69369369, 0.69469469,
0.6956957 , 0.6966967 , 0.6976977 , 0.6986987 , 0.6996997 ,
0.7007007 , 0.7017017 , 0.7027027 , 0.7037037 , 0.7047047 ,
0.70570571, 0.70670671, 0.70770771, 0.70870871, 0.70970971,
0.71071071, 0.71171171, 0.71271271, 0.71371371, 0.71471471,
0.71571572, 0.71671672, 0.71771772, 0.71871872, 0.71971972,
0.72072072, 0.72172172, 0.72272272, 0.72372372, 0.72472472,
0.72572573, 0.72672673, 0.72772773, 0.72872873, 0.72972973,
0.73073073, 0.73173173, 0.73273273, 0.73373373, 0.73473473,
0.73573574, 0.73673674, 0.73773774, 0.73873874, 0.73973974,
0.74074074, 0.74174174, 0.74274274, 0.74374374, 0.74474474,
0.74574575, 0.74674675, 0.74774775, 0.74874875, 0.74974975,
0.75075075, 0.75175175, 0.75275275, 0.75375375, 0.75475475,
0.75575576, 0.75675676, 0.75775776, 0.75875876, 0.75975976,
0.76076076, 0.76176176, 0.76276276, 0.76376376, 0.76476476,
0.76576577, 0.76676677, 0.76776777, 0.76876877, 0.76976977,
0.77077077, 0.77177177, 0.77277277, 0.77377377, 0.77477477,
0.77577578, 0.77677678, 0.77777778, 0.77877878, 0.77977978,
0.78078078, 0.78178178, 0.78278278, 0.78378378, 0.78478478,
0.78578579, 0.78678679, 0.78778779, 0.78878879, 0.78978979,
0.79079079, 0.79179179, 0.79279279, 0.79379379, 0.79479479,
0.7957958 , 0.7967968 , 0.7977978 , 0.7987988 , 0.7997998 ,
0.8008008 , 0.8018018 , 0.8028028 , 0.8038038 , 0.8048048 ,
0.80580581, 0.80680681, 0.80780781, 0.80880881, 0.80980981,
0.81081081, 0.81181181, 0.81281281, 0.81381381, 0.81481481,
0.81581582, 0.81681682, 0.81781782, 0.81881882, 0.81981982,
0.82082082, 0.82182182, 0.82282282, 0.82382382, 0.82482482,
0.82582583, 0.82682683, 0.82782783, 0.82882883, 0.82982983,
0.83083083, 0.83183183, 0.83283283, 0.83383383, 0.83483483,
0.83583584, 0.83683684, 0.83783784, 0.83883884, 0.83983984,
0.84084084, 0.84184184, 0.84284284, 0.84384384, 0.84484484,
0.84584585, 0.84684685, 0.84784785, 0.84884885, 0.84984985,
0.85085085, 0.85185185, 0.85285285, 0.85385385, 0.85485485,
0.85585586, 0.85685686, 0.85785786, 0.85885886, 0.85985986,
0.86086086, 0.86186186, 0.86286286, 0.86386386, 0.86486486,
0.86586587, 0.86686687, 0.86786787, 0.86886887, 0.86986987,
0.87087087, 0.87187187, 0.87287287, 0.87387387, 0.87487487,
0.87587588, 0.87687688, 0.87787788, 0.87887888, 0.87987988,
0.88088088, 0.88188188, 0.88288288, 0.88388388, 0.88488488,
0.88588589, 0.88688689, 0.88788789, 0.88888889, 0.88988989,
0.89089089, 0.89189189, 0.89289289, 0.89389389, 0.89489489,
0.8958959 , 0.8968969 , 0.8978979 , 0.8988989 , 0.8998999 ,
0.9009009 , 0.9019019 , 0.9029029 , 0.9039039 , 0.9049049 ,
0.90590591, 0.90690691, 0.90790791, 0.90890891, 0.90990991,
0.91091091, 0.91191191, 0.91291291, 0.91391391, 0.91491491,
0.91591592, 0.91691692, 0.91791792, 0.91891892, 0.91991992,
0.92092092, 0.92192192, 0.92292292, 0.92392392, 0.92492492,
0.92592593, 0.92692693, 0.92792793, 0.92892893, 0.92992993,
0.93093093, 0.93193193, 0.93293293, 0.93393393, 0.93493493,
0.93593594, 0.93693694, 0.93793794, 0.93893894, 0.93993994,
0.94094094, 0.94194194, 0.94294294, 0.94394394, 0.94494494,
0.94594595, 0.94694695, 0.94794795, 0.94894895, 0.94994995,
0.95095095, 0.95195195, 0.95295295, 0.95395395, 0.95495495,
0.95595596, 0.95695696, 0.95795796, 0.95895896, 0.95995996,
0.96096096, 0.96196196, 0.96296296, 0.96396396, 0.96496496,
0.96596597, 0.96696697, 0.96796797, 0.96896897, 0.96996997,
0.97097097, 0.97197197, 0.97297297, 0.97397397, 0.97497497,
0.97597598, 0.97697698, 0.97797798, 0.97897898, 0.97997998,
0.98098098, 0.98198198, 0.98298298, 0.98398398, 0.98498498,
0.98598599, 0.98698699, 0.98798799, 0.98898899, 0.98998999,
0.99099099, 0.99199199, 0.99299299, 0.99399399, 0.99499499,
0.995996 , 0.996997 , 0.997998 , 0.998999 , 1. ]),
array([ 0. , -0.03832051, -0.06881164, -0.03285791, -0.07344235,
-0.01421415, -0.03023905, -0.00613886, -0.00320638, 0.03900757,
0.04165517, 0.01459812, 0.05593224, 0.04206129, 0.03985201,
0.04733064, 0.00592429, 0.00637504, -0.00855554, -0.01737591,
0.02018721, -0.01657211, -0.03309821, -0.05122858, -0.077696 ,
-0.07615461, -0.05452471, -0.06909004, 0.00317116, 0.00830735,
0.00571429, 0.08442794, 0.1050608 , 0.07439092, 0.11290616,
0.16274355, 0.16591478, 0.18694263, 0.22014455, 0.2364443 ,
0.23646344, 0.2131828 , 0.14712155, 0.16964155, 0.15239147,
0.14915273, 0.1718172 , 0.15994312, 0.12703979, 0.15185183,
0.20198136, 0.27571658, 0.28073407, 0.2376575 , 0.22446468,
0.22501717, 0.21484451, 0.2615964 , 0.27529333, 0.26443312,
0.26215171, 0.28638829, 0.31080787, 0.31257022, 0.31995177,
0.27533111, 0.30792911, 0.27539062, 0.27109185, 0.30346985,
0.30223475, 0.30047118, 0.3258351 , 0.30980824, 0.34962578,
0.35958892, 0.40101652, 0.34064867, 0.34042635, 0.26770867,
0.26297951, 0.25522908, 0.27622885, 0.2959025 , 0.34589974,
0.34949067, 0.34761606, 0.31182259, 0.26911804, 0.2627572 ,
0.24401803, 0.22691193, 0.1859618 , 0.2098578 , 0.23608947,
0.22439927, 0.21300398, 0.15262901, 0.17581435, 0.14861725,
0.17032599, 0.11190836, 0.1425216 , 0.1193928 , 0.07935506,
0.06303006, 0.0477225 , 0.02531302, 0.08919992, 0.13358564,
0.15802004, 0.17547887, 0.18559757, 0.19241626, 0.16978095,
0.16281896, 0.1715162 , 0.2098279 , 0.25244498, 0.23216083,
0.26227677, 0.28036538, 0.35641598, 0.42820141, 0.45749543,
0.47203254, 0.49582981, 0.51870713, 0.49458919, 0.46760409,
0.48045143, 0.45475418, 0.47829398, 0.47474316, 0.42752585,
0.43363388, 0.40163888, 0.4289523 , 0.39687835, 0.36888667,
0.34963059, 0.26667228, 0.32451816, 0.33942314, 0.36904192,
0.38148061, 0.38541555, 0.40568807, 0.39594529, 0.44104696,
0.50813014, 0.53712894, 0.51703225, 0.47954204, 0.42737856,
0.44298797, 0.49108463, 0.46138033, 0.47472441, 0.47687041,
0.48287381, 0.51592444, 0.57657189, 0.58675302, 0.63035889,
0.66638091, 0.58380972, 0.55161205, 0.52597207, 0.557153 ,
0.51877606, 0.45694384, 0.47576442, 0.5042841 , 0.50979213,
0.47313784, 0.45269168, 0.39882952, 0.45443698, 0.45307201,
0.40628382, 0.42290623, 0.46983069, 0.49173885, 0.48550927,
0.52327233, 0.52721792, 0.46617176, 0.42485253, 0.45489272,
0.47857937, 0.5057022 , 0.50875792, 0.51680504, 0.54213617,
0.63190714, 0.70577774, 0.74344391, 0.68453489, 0.69295974,
0.69160325, 0.73044961, 0.70668312, 0.69254386, 0.68592459,
0.6997682 , 0.71120205, 0.74450819, 0.69702518, 0.66352442,
0.64892015, 0.62216369, 0.59602671, 0.61657474, 0.60235282,
0.5612987 , 0.54155466, 0.56895646, 0.58702934, 0.59121958,
0.55609976, 0.52389533, 0.55863875, 0.53790984, 0.49521922,
0.4823864 , 0.51907414, 0.5709217 , 0.59373825, 0.57491966,
0.60638062, 0.58559067, 0.56745154, 0.55576956, 0.53932928,
0.54002189, 0.55313509, 0.54338063, 0.5344091 , 0.52877551,
0.51261887, 0.50312276, 0.4951515 , 0.49489546, 0.5039701 ,
0.48752592, 0.44820143, 0.44485122, 0.46781317, 0.41506442,
0.39732957, 0.40690546, 0.38137509, 0.37321931, 0.41366259,
0.40300871, 0.38794287, 0.33639913, 0.40273583, 0.41411589,
0.41843087, 0.44351541, 0.51684618, 0.56282828, 0.55549456,
0.5706891 , 0.61517814, 0.660621 , 0.66529336, 0.69941099,
0.73013781, 0.70988988, 0.7041724 , 0.69165605, 0.7521163 ,
0.69335587, 0.68052316, 0.64055315, 0.65718546, 0.67635314,
0.68438229, 0.63849964, 0.6032453 , 0.64807141, 0.58202692,
0.58984731, 0.59589113, 0.63491806, 0.67483135, 0.68028817,
0.68229999, 0.67603596, 0.65786472, 0.64151998, 0.64729854,
0.64029528, 0.59822856, 0.58629842, 0.61661214, 0.55991811,
0.55204474, 0.556317 , 0.52908503, 0.50802817, 0.45410372,
0.42325914, 0.40074662, 0.33853296, 0.32043166, 0.33328552,
0.28687219, 0.21771345, 0.18732709, 0.16972289, 0.15607467,
0.1158046 , 0.11927855, 0.1494101 , 0.1455129 , 0.11845254,
0.12803672, 0.12336059, 0.15142944, 0.17217524, 0.19878957,
0.20417839, 0.18037963, 0.18264306, 0.1732966 , 0.19084911,
0.18356584, 0.16296115, 0.22838152, 0.2157449 , 0.22110174,
0.17927758, 0.15879105, 0.16496492, 0.18688416, 0.20569242,
0.16916191, 0.1756392 , 0.18602253, 0.15486175, 0.16361711,
0.1911143 , 0.2311182 , 0.2962736 , 0.29175597, 0.31352227,
0.306548 , 0.29770496, 0.30119643, 0.33310249, 0.38280369,
0.39739897, 0.38437646, 0.36748873, 0.37176303, 0.40639654,
0.42122122, 0.38755483, 0.43025371, 0.40047354, 0.41744035,
0.42821887, 0.41788398, 0.36860062, 0.35697945, 0.3500041 ,
0.32506556, 0.3101111 , 0.36353547, 0.36419717, 0.32471144,
0.2971062 , 0.26788855, 0.26359759, 0.28952124, 0.28134471,
0.27504172, 0.29528234, 0.34694656, 0.32010703, 0.27019897,
0.32601527, 0.28987181, 0.28113901, 0.30523616, 0.30915532,
0.3281616 , 0.25808224, 0.31464167, 0.30943739, 0.31388697,
0.31260567, 0.27456265, 0.23329898, 0.23297529, 0.22038295,
0.21411772, 0.22825897, 0.2542894 , 0.21465196, 0.20224227,
0.25011588, 0.29102106, 0.27350039, 0.25088305, 0.26644438,
0.25428216, 0.26782952, 0.28322684, 0.23823382, 0.2605319 ,
0.20652023, 0.2476238 , 0.27875454, 0.32677497, 0.3025801 ,
0.30308851, 0.31036762, 0.34844834, 0.30847072, 0.33641684,
0.27514678, 0.29466104, 0.25179921, 0.3070157 , 0.31813406,
0.31533969, 0.27158405, 0.28429539, 0.28896836, 0.33675459,
0.34423415, 0.30638748, 0.35863252, 0.36935596, 0.39272109,
0.394159 , 0.41831325, 0.42304935, 0.36834338, 0.36441808,
0.35551776, 0.34303569, 0.34519394, 0.32374286, 0.26959997,
0.22591891, 0.19065377, 0.2163897 , 0.23466043, 0.21584991,
0.23281295, 0.2585541 , 0.28002832, 0.27422464, 0.25311765,
0.28513453, 0.30737009, 0.26326833, 0.33047242, 0.33884169,
0.33238531, 0.3314226 , 0.33510295, 0.30378015, 0.27353059,
0.29094331, 0.3090272 , 0.28349861, 0.23100317, 0.22311002,
0.18900497, 0.21826746, 0.21987506, 0.19754062, 0.18220115,
0.19233834, 0.12706154, 0.12899145, 0.14583054, 0.11530388,
0.11031954, 0.14044584, 0.14875249, 0.13720208, 0.13220229,
0.11737548, 0.09543174, 0.07262216, 0.05201297, 0.03791347,
0.03668997, 0.02524825, 0.10527824, 0.11505654, 0.12072553,
0.16906135, 0.19767277, 0.19073697, 0.21474299, 0.26106619,
0.36429456, 0.33392564, 0.32229782, 0.34773704, 0.37842574,
0.35812263, 0.38787636, 0.40001493, 0.38651693, 0.45132682,
0.44360813, 0.42558394, 0.45357167, 0.44887172, 0.41767191,
0.45428172, 0.42735593, 0.409921 , 0.36382136, 0.412783 ,
0.35803667, 0.30969988, 0.31159942, 0.33441603, 0.33994041,
0.3028995 , 0.29024425, 0.27206676, 0.32964671, 0.31257534,
0.38036843, 0.36489506, 0.36782837, 0.29733483, 0.28391102,
0.28157196, 0.28721589, 0.30348284, 0.3320551 , 0.31267505,
0.3296057 , 0.31004009, 0.35147129, 0.4039563 , 0.41881783,
0.43444398, 0.43934246, 0.4192911 , 0.45203923, 0.4479916 ,
0.41511848, 0.43898566, 0.39113333, 0.39565041, 0.42244848,
0.45869348, 0.51425222, 0.48255165, 0.54190469, 0.54097675,
0.56041509, 0.53158687, 0.48019487, 0.50544741, 0.50950816,
0.50964521, 0.46959882, 0.46395274, 0.50723198, 0.49503921,
0.49792573, 0.415732 , 0.39941871, 0.41771304, 0.39407226,
0.4537205 , 0.436859 , 0.45128109, 0.47542377, 0.45774868,
0.45625267, 0.43785064, 0.46967963, 0.4859284 , 0.45928188,
0.45120274, 0.48306886, 0.5042796 , 0.50926438, 0.5455123 ,
0.57095112, 0.54293589, 0.5174226 , 0.54411136, 0.5909794 ,
0.61498928, 0.65078075, 0.66855115, 0.635921 , 0.5957718 ,
0.63352766, 0.67919117, 0.6551468 , 0.66453048, 0.65074655,
0.6633892 , 0.65533966, 0.65753793, 0.67216703, 0.6578292 ,
0.68340772, 0.7590512 , 0.8167605 , 0.82859607, 0.76727007,
0.75347349, 0.78986693, 0.78241067, 0.8795797 , 0.87486692,
0.86116897, 0.88595529, 0.87458959, 0.8839156 , 0.89521205,
0.89835055, 0.87749455, 0.86548596, 0.83337508, 0.83516108,
0.88656702, 0.86457825, 0.88748093, 0.89884948, 0.89021573,
0.91408852, 0.98964138, 1.03167739, 1.03744322, 1.03188358,
1.04992103, 1.04038134, 1.00297114, 1.0046496 , 1.01872266,
1.04404901, 1.03350976, 1.0321243 , 1.04104137, 1.06529465,
1.02929809, 1.05845928, 1.07710864, 1.05034668, 1.03194497,
1.07099672, 1.00129212, 0.99329872, 1.02771867, 1.08711193,
1.07083863, 1.06423151, 0.99126786, 0.99579001, 1.00399912,
1.03341438, 1.00890259, 0.93456026, 0.93444331, 0.9482067 ,
0.96312875, 0.92161642, 0.92981689, 0.91801617, 0.96798262,
0.93661053, 0.9917114 , 1.0052811 , 0.96718025, 0.94486062,
0.97471774, 0.96186783, 0.98308726, 0.97945037, 0.97925644,
0.93340613, 0.99012244, 0.99469975, 1.0009192 , 1.00263474,
0.95781511, 0.98483116, 1.02533266, 1.04881683, 1.02563541,
1.03889559, 1.12427184, 1.15898557, 1.16134186, 1.18878037,
1.17541746, 1.19797548, 1.24595638, 1.22084185, 1.20157733,
1.15805867, 1.18895539, 1.19775389, 1.21121945, 1.19246808,
1.23236742, 1.24509941, 1.23060532, 1.19923871, 1.17303075,
1.20702931, 1.17220498, 1.14358066, 1.19085721, 1.16089652,
1.177339 , 1.13199855, 1.17209403, 1.17341765, 1.14898014,
1.12447726, 1.08625867, 1.06265204, 1.03986096, 1.04547213,
1.02435672, 1.01053575, 1.04415547, 1.08309835, 1.06718044,
1.08017143, 1.09119132, 1.08543916, 1.07590148, 1.0308945 ,
0.99360981, 1.04251538, 1.06633721, 1.03666353, 1.01452777,
1.04308983, 1.05903577, 1.02705868, 1.02655358, 1.06544363,
1.11549802, 1.11629459, 1.10958077, 1.13613065, 1.13127812,
1.08124129, 1.07568819, 1.10173152, 1.10168032, 1.11985094,
1.11813445, 1.11653241, 1.14834028, 1.08157419, 1.10004642,
1.09872008, 1.06700264, 1.03299802, 1.00723907, 1.02541274,
1.03308203, 1.00051527, 0.97959418, 0.9535672 , 0.94327726,
0.94725775, 0.93843198, 0.89684139, 0.89104147, 0.88952934,
0.94297299, 0.93614885, 0.93826543, 0.9049704 , 0.89554909,
0.89873036, 0.93935476, 0.95405921, 0.94245072, 0.95451228,
0.95165815, 0.9676945 , 0.96129828, 0.95243748, 0.88039966,
0.85016833, 0.8807682 , 0.88064499, 0.8374865 , 0.84477103,
0.8456506 , 0.88009905, 0.85033355, 0.92464764, 0.95516998,
0.92353227, 0.92813663, 0.94434535, 0.90131286, 0.92820988,
0.92606377, 0.94425169, 0.92916258, 0.98102208, 0.97456926,
0.99320781, 0.98334776, 1.0178815 , 1.0671753 , 1.07213102,
1.07363153, 1.0407982 , 1.06408769, 1.08903561, 1.03588057,
1.07604559, 1.03473091, 0.99798571, 0.93662122, 0.92401137,
0.89722844, 0.92903865, 0.9280247 , 0.95889455, 0.99001482,
0.98532336, 0.97363143, 0.99510897, 1.01637439, 1.0204722 ,
0.95142096, 0.96288611, 0.99266338, 0.95178714, 0.95353244,
0.91245008, 0.90074038, 0.90828473, 0.91900859, 0.94803513,
0.97520073, 0.94767021, 0.97537507, 0.92514376, 0.91543121,
0.93358968, 0.90241939, 0.9004941 , 0.95883261, 0.98147293,
0.97826579, 0.98580382, 0.9839939 , 0.94941076, 0.91934109,
0.96122002, 0.95360197, 1.03969697, 1.02077758, 1.03204602,
1.01390132, 0.97076535, 0.96875193, 0.95838309, 0.95545776,
0.99329651, 1.00343767, 0.99944169, 1.00170834, 1.01196478,
1.0257787 , 1.02108283, 1.00367821, 0.98773467, 1.02367616,
0.98478862, 0.98926754, 0.9549251 , 0.9132807 , 0.87334901,
0.87930477, 0.84395312, 0.82161126, 0.81345749, 0.7692098 ,
0.77295787, 0.7961382 , 0.85743184, 0.85719715, 0.81973128,
0.8628811 , 0.82344164, 0.79815268, 0.82519162, 0.76122179,
0.73149495, 0.76741867, 0.79287877, 0.75844993, 0.74677061,
0.72146307, 0.71376034, 0.72202235, 0.72404066, 0.70456808,
0.70230324, 0.70219266, 0.71139064, 0.76485841, 0.78545629,
0.81801241, 0.87008134, 0.8807941 , 0.82312268, 0.80378212,
0.77705027, 0.79005258, 0.85291628, 0.85855445, 0.81968815,
0.84011393, 0.82420539, 0.82413314, 0.83212313, 0.88482216,
0.87122496, 0.85444911, 0.79697362, 0.79151801, 0.85951697,
0.90931589, 0.92025496, 0.92313722, 0.85818907, 0.86131622,
0.84685768, 0.82993269, 0.82740681, 0.76589033, 0.74684763,
0.80986714, 0.75051969, 0.72798612, 0.69406299, 0.7024433 ,
0.67796218, 0.71792793, 0.72941387, 0.71445656, 0.68145897,
0.71072631, 0.7244973 , 0.75691711, 0.72521654, 0.67556851,
0.67468638, 0.74512694, 0.70265886, 0.67188638, 0.71794412,
0.75505916, 0.7120356 , 0.69151454, 0.67708133, 0.7150501 ,
0.69455289, 0.69504757, 0.7177877 , 0.71772416, 0.71507362,
0.72366273, 0.76018188, 0.75671584, 0.73013667, 0.79616783,
0.78499216, 0.76615487, 0.77578667, 0.79070648, 0.76603411,
0.73775285, 0.72582339, 0.73012559, 0.72918605, 0.75340997]))
In [ ]:
assert isinstance(t, np.ndarray)
assert isinstance(W, np.ndarray)
assert t.dtype==np.dtype(float)
assert W.dtype==np.dtype(float)
assert len(t)==len(W)==1000
Visualize the process using plt.plot with t on the x-axis and W(t) on the y-axis. Label your x and y axes.
In [18]:
plt.plot(brownian(1.0,1000))
plt.xlabel('t')
plt.ylabel('W(t)')
Out[18]:
<matplotlib.text.Text at 0x7f2ecfe3a150>
In [ ]:
assert True # this is for grading
Use np.diff to compute the changes at each step of the motion, dW, and then compute the mean and standard deviation of those differences.
In [24]:
np.diff(brownian(1.0,1000))
np.diff(brownian(1.0,1000)).mean()
np.diff(brownian(1.0,1000)).std()
Out[24]:
0.022181208891703618
In [ ]:
assert len(dW)==len(W)-1
assert dW.dtype==np.dtype(float)
Write a function that takes $W(t)$ and converts it to geometric Brownian motion using the equation:
$$ X(t) = X_0 e^{((\mu - \sigma^2/2)t + \sigma W(t))} $$Use Numpy ufuncs and no loops in your function.
In [ ]:
def geo_brownian(t, W, X0, mu, sigma):
"Return X(t) for geometric brownian motion with drift mu, volatility sigma."""
X0*exp(((mu-sigma**2)/2)*t + sigma*W(t))
In [ ]:
assert True # leave this for grading
Use your function to simulate geometric brownian motion, $X(t)$ for $X_0=1.0$, $\mu=0.5$ and $\sigma=0.3$ with the Wiener process you computed above.
Visualize the process using plt.plot with t on the x-axis and X(t) on the y-axis. Label your x and y axes.
In [ ]:
# YOUR CODE HERE
raise NotImplementedError()
In [ ]:
assert True # leave this for grading
Content source: sthuggins/phys202-2015-work
Similar notebooks: