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

Using dir() to find variables and functions

After assigning values to a few variables, we could use the dir() function to show their existence. In the following example, variables n, pv, and r are shown among other names. At the moment, just ignore the first five objects in the following code, which start and end with two underscores:

>>>pv=100
>>>r=0.1
>>>n=5
>>>dir()
['__builtins__', '__doc__', '__loader__', '__name__', '__package__', 'n', 'pv', 'r']

Deleting or unsigning a variable

Sometimes, when we write our programs, it might be a good idea to delete those variables that we no longer need. In this case, we could use the del() function to remove or unsign a variable. In the following example, we assign a value to rate, show its value, delete it, and type the variable name trying to retrieve its value again:

>>>rate=0.075
>>>rate
0.075

The value 0.075 seen...