import numpy as npimport scipy.stats as statsimport matplotlib.pyplot as plt# set the random seed:np.random.seed(1234567)# initialize plot:x_range = np.linspace(0, 50, num=51)plt.ylim([-18, 18])plt.xlim([0, 50])# loop over draws:for r in range(0, 30):# i.i.d. standard normal shock:e = stats.norm.rvs(0, 1, size=51)# set first entry to 0 (gives y_0 = 0):e[0] = 0# random walk as cumulative sum of shocks:y = np.cumsum(e)# add line to graph:plt.plot(x_range, y, color='lightgrey', linestyle='-')plt.axhline(linewidth=2, linestyle='--', color='black')plt.ylabel('y')plt.xlabel('time')plt.savefig('PyGraphs/Simulate-RandomWalk.pdf')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。