Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Python for Finance
  • Toc
  • feedback
Python for Finance

Python for Finance

By : Yuxing Yan
3.9 (22)
close
Python for Finance

Python for Finance

3.9 (22)
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)
close
13
Index

Understanding a for loop

A for loop is one of the most used loops in many computer languages. The following flow diagram demonstrates how a loop works. Usually, we start with an initial value. Then, we test a condition. If the condition is false, the program stops. Otherwise, we execute a set of commands:

Understanding a for loop

The simplest example is given as follows:

>>>for i in range(1,5):
      print i

Running these two lines will print 1, 2, 3, and 4. We have to be careful with the range() function since the last number, 5, will not be printed in Python. Thus, if we intend to print from 1 to n, we have to use the following code:

>>>n=10
>>>for i in range(1,n+1):
      print i

In the previous two examples, the default incremental value is 1. If we intend to use an incremental value other than 1, we have to specify it as follows:

>>>for i in xrange(1,10,3):
      print i

The output values will be 1, 4, and 7. Along the same lines, if we want to print 5 to 1, that is, in descending...

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete