人生苦短,我用Python。
Life is short, you need Python!
——吉多·范罗苏姆(Guido van Rossum)
Core Functions and Syntaxes
ax.plot(x,y)绘制以x为自变量,y为因变量的二维线图
ax.set(xlabel='Time step',ylabel='Interest rate',title='Vasicek Model')设置x轴标签为"Time step",y轴标签为"Interest rate",图的标题为"Vasicek Model"
def vasicek(r0,k,theta,sigma, T=1., N=10,seed=500)定义函数
import math导入第三方数学运算工具库math
import numpy as np导入第三方矩阵运算库,并给它取一个别名np,在后序代码中,可以通过np来调用numpy中的子库
input("Please enter your name")在Python的console中显示"Please enter your name"后接受键盘的输入
math.sqrt(81)调用第三方数学运算库math中的sqrt()函数用来求开方根值
matplotlib.pyplot.show()显示图片
print()在Python的console中输出信息
random.random()调用第三方库random中的random()函数,返回0到1之间的随机数
range(N)生成一个含有N个整数的列表,列表的元素从0到N
return range(N+1), rates在函数定义中用于返回变量range(N+1)和rates的值
round(4.35,1)将4.35圆整到一位小数
type(num_int)返回变量num_int的数据类型