10.12.2019 Views

Python for Finance

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1

7. Click Run, then Run module. If no error occurs, we can use the function just

like other embedded functions, as shown here:

Variable assignment, empty space, and

writing our own programs

First, for Python language, an empty space or spaces is very important. For

example, if we accidently have a space before typing pv=100, we will see the

following error message:

The name of the error is called IndentationError. The reason is that, for Python,

indentation is important. Later in the chapter, we will learn that a proper indentation

will regulate/define how we write a function or why a group of codes belongs to a

specific topic, function, or loop.

Assume that we deposit $100 in the bank today. What will be the value 3 years later

if the bank offers us an annual deposit rate of 1.5%? The related codes is shown here:

>>>pv=100

>>>pv

100

>>>pv*(1+0.015)**3

104.56783749999997

>>>

[ 7 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!