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

Performing array manipulations


In finance-related research, quite often we need to change the dimensions of a matrix or an array. For example, converting a set of 100 random numbers into a 20 by 5 matrix or vice versa. For this purpose, we could use two NumPy functions, flatten() and reshape(), as follows:

>>>pv=np.array([[100,10,10.2],[34,22,34]]) # 2 by 3
>>>x=pv.flatten()                      #  matrix becomes a vector
>>>vp2=np.reshape(x,[3,2])             # 3 by 2 now