Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

Table of Contents (20 chapters)
Python for Finance
About the Author
About the Reviewers

Generating our own module

The math module has more than two dozen functions, such as the pow(), sin(), and ceil() functions. It is definitely a good idea to have just one program or file or package or module to include all of them. Let's start from the simplest case of two functions. The first function is the pv_f() function we discussed before. Our second function is the present value of perpetuity, which has constant cash flow at the same interval forever. If the first cash flow occurs at the end of the first period, we have the following formula:

Here, c is the constant periodic cash flow occurring at the end of each period, and R is the periodic discount rate. For example, if we are expected to receive $10 at the end of each year forever, and the first cash flow would happen at the end of the first year, then the present value of such a perpetuity is $100 (10 / 0.1) if the annual discount rate is 10 percent.

Again, we need to navigate to File | (Choose) A new Window (Ctrl+N), and then...