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

A few frequently used functions

There are several functions we are going to use quite frequently. In this section, we will discuss them briefly. The functions are print(), type(), upper(), strip(), and last expression _. We will also learn how to merge two string variables. The true power function pow() discussed earlier belongs to this category as well.

The print() function

Occasionally, we need to print something on screen. One way to do so is to apply the print() function as shown in the following example:

>>>import math            
>>>print('pi=',math.pi)
pi= 3.141592653589793

At this stage, a new user just applies this format without going into more detail about the print() function.

The type() function

In Python, the type() function can be used to find out the type of a variable as follows:

>>>pv=100.23
>>>type(pv)
<class 'float'>
>>>n=10
>>>type(n)
<class 'int'>
>>>

From these results...