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
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Ways to launch Python


There are three ways to launch Python and they are explained in the following sections.

Launching Python with GUI

To launch Python, perform the following steps:

  1. Click on Start and then on All Programs.

  2. Find Python 3.3.

  3. Click on IDLE (Python GUI) as shown in the following screenshot:

  4. After Python starts, the following window appears:

Assume that an estimate of $100 is expected to be received in one year with an annual discount rate of 10 percent. The present value of one future cash flow is as follows:

In this equation, PV is the present value, FV is the future value, R is the discount rate, and n is the number of periods. According to the preceding formula, we could manually type those values to get the present value of this one future cash flow. Assume that we would receive $100 in one year. If the annual discount rate is 10 percent, what is the present value of this $100? For this, let's take a look at the following lines of code:

>>>100/(1+0.1)
90.9090909090909
>>>

Note

The triple larger than signs (>>>) is the Python prompt.

It is a good idea to create a Python icon on your desktops for your convenience. In addition to the preceding method, there are other methods to launch Python; see the next two sections: Launching Python from the Python command line and Launching Python from our own DOS window.

Launching Python from the Python command line

A new user could skip this section and go to the Quitting Python section because learning how to launch Python with GUI is more than enough. There are two reasons for this. The first is because we know how to launch Python by using Python IDLE or by clicking on the Python icon on our desktops, and the second reason is that we could save and run our Python programs easily using Python IDLE.

To launch Python from the Python command line, we have to perform the following steps:

  1. Click on Start and then on All Programs.

  2. Find Python 3.3.

  3. Click on Python (command line) as shown in the following screenshot:

  4. After we click on Python (command line), we will see the following window:

Launching Python from our own DOS window

We could generate our own DOS window, and then launch Python from there. In addition, we could navigate to the subdirectory, which contains our Python programs. In order to this, perform the following steps:

  1. Open a Window command line by clicking on Start and then enter cmd in the run window as shown in the following screenshot:

  2. Type cd c:\python33 to move to the appropriate directory.

  3. Type python to run the software as shown in the following screenshot:

If we want to launch Python anywhere else, we have to include the path of our Python directory. Assume that after installation we have python33 in C:. Replace step 2 with the following DOS command:

set path=%path%;C:\python33