
Python for Finance

In this section, we will discuss how to install Python. More specifically, we will discuss two methods: installing Python via Anaconda and installing Python directly.
There are several reasons why the first method is preferred:
We could install Python in several ways. The consequence is that we will have different environments for writing a Python program and running a Python program.
The following is a simple two-step approach. First, we go to http://continuum.io/downloads and find an appropriate package; see the following screenshot:
For Python, different versions coexist. From the preceding screenshot, we see that there exist two versions, 3.5 and 2.7.
For this book, the version is not that critical. The old version had fewer problems while the new one usually has new improvements. Again, module dependency could be a big headache; see Chapter 2, Introduction to Python Modules for more detail. The version of Anaconda is 4.2.0. Since we will launch Python through Spyder, it might have different versions as well.
After Python is installed via Anaconda, we can navigate to Start (for a Windows version) |All Programs |Anaconda3(32-bit), as shown in the following screenshot:
After we click Spyder, the last entry in the preceding screenshot, we will see the following four panels:
The top-left panel (window) is our program editor, where we write our programs. The bottom-right panel is the IPython console, where we cantype our simple commands. IPython is the default one. To know more about IPython, just type a question mark; see the following screenshot:
Alternatively, we could launch Python console by clicking Consoles on the menu bar and then Open a Python console. After that, the following window will appear:
From the image with four panels, the top-right panel is our help window, where we can seek help. The middle one is called Variable Explorer, where the names of variables and their values are shown. Depending on personal preference, users will scale those panels or reorganize them.
For most users, knowing how to install Python via Anaconda is more than enough. Just for completeness, here the second way to install Python is presented.
The following steps are involved:
IDLE (Python 3.5. 32 bit)
and get to see the following screen:>>>pv=100 >>>pv*(1+0.1)**20 672.7499949325611 >>> import math >>>math.sqrt(3) 1.7320508075688772 >>>
Change the font size
Change margin width
Change background colour