Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

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)
13
Index

The put-call parity and its graphical representation

Let's look at a call with an exercise price of $20, a maturity of three months, and a risk-free rate of 5 percent. The present value of this future $20 price is calculated in the following code:

>>>x=20*exp(-0.05*3/12)   
>>>round(x,2)
19.75
>>>

In three months, what will be the wealth of our portfolio, which consists of a call on the same stock and $19.75 cash today? If the stock price is below $20, we don't exercise the call and keep the cash. If the stock price is above $20, we use our cash of $20 to exercise our call option to own the stock. Thus, our portfolio value will be the maximum of those two values, that is, the stock price in three months or $20, max(s,20).

On the other hand, how about a portfolio with a stock and a put option with an exercise price of $20? If the stock price falls below $20, we exercise the put option and get $20. If the stock price is above $20, we simply keep the stock...