Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

A hands-on guide with easy-to-follow examples to help you learn about option theory, quantitative finance, financial modeling, and time series using Python. Python for Finance is perfect for graduate students, practitioners, and application developers who wish to learn how to utilize Python to handle their financial needs. Basic knowledge of Python will be helpful but knowledge of programming is necessary.
Table of Contents (14 chapters)
13
Index

Working with arrays of ones, zeros, and the identity matrix


In the following code examples, we don't show values of all the variables, from a to i, to save space:

>>>import numpy as np
>>>a=np.zeros(10)                #  array with 10 zeros
>>>b=np.zeros((3,2),dtype=float) #  3 by 2 with zeros
>>>c=np.ones((4,3),float)        #  4 by 3 with all ones
>>>d=np.array(range(10),float)   #  0,1, 2,3 .. up to 9
>>>e1=np.identity(4)             #  identity 4 by 4 matrix
>>>e2=np.eys(4)                  #  same as above
>>>e3=np.eys(4,k=1)              #  1 start from k  
>>>f=np.arange(1,20,3,float)     # from 1 to 19 interval 3
>>>g=np.array([[2,2,2],[3,3,3]]) #  2 by 3
>>>h=np.zeros_like(g)            #  all zeros
>>>i=np.ones_linke(g)            #  all ones