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

Chapter 4. 13 Lines of Python to Price a Call Option

To many readers, option theory is like rocket science. In order to make option theory less intimidating, we deliberately avoided any mathematical formula in this chapter. Literally, the focus of the whole chapter is around 13 lines of Python code. An option buyer pays to acquire the right to buy (or sell) something in the future while an option seller receives an upfront payment to bear an obligation to sell to (or buy from) the option buyer. A call option buyer has the right to buy a stock at a fixed price and at a fixed date in the future. A European option can only be exercised when the option expires, while an American option could be exercised any time before or at the maturity date.

In this chapter, we will cover the following topics:

  • 13 lines of Python code to price a call option

  • Writing a Python function without saving it

  • Using the empty shell method to write a complex Python program

  • Using the comment-all-out method to write a complex...