Book Image

Python for Finance - Second Edition

By : Yuxing Yan
5 (1)
Book Image

Python for Finance - Second Edition

5 (1)
By: Yuxing Yan

Overview of this book

This book uses Python as its computational tool. Since Python is free, any school or organization can download and use it. This book is organized according to various finance subjects. In other words, the first edition focuses more on Python, while the second edition is truly trying to apply Python to finance. The book starts by explaining topics exclusively related to Python. Then we deal with critical parts of Python, explaining concepts such as time value of money stock and bond evaluations, capital asset pricing model, multi-factor models, time series analysis, portfolio theory, options and futures. This book will help us to learn or review the basics of quantitative finance and apply Python to solve various problems, such as estimating IBM’s market risk, running a Fama-French 3-factor, 5-factor, or Fama-French-Carhart 4 factor model, estimating the VaR of a 5-stock portfolio, estimating the optimal portfolio, and constructing the efficient frontier for a 20-stock portfolio with real-world stock, and with Monte Carlo Simulation. Later, we will also learn how to replicate the famous Black-Scholes-Merton option model and how to price exotic options such as the average price call option.
Table of Contents (23 chapters)
Python for Finance Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
Index

Exercises


  1. Where can you download and install Python?

  2. Is Python case-sensitive?

  3. How do you assign a set of values to pv in the format of a tuple. Could we change its values after the assignment?

  4. Estimate the area of a circle if the diameter is 9.7 using Python.

  5. How do you assign a value to a new variable?

  6. How can you find some sample examples related to Python?

  7. How do you launch Python's help function?

  8. How can you find out more information about a specific function, such as print()?

  9. What is the definition of built-in functions?

  10. Is pow() a built-in function? How do we use it?

  11. How do we find all built-in functions? How many built-in functions are present?

  12. When we estimate the square root of 3, which Python function should we use?

  13. Assume that the present value of a perpetuity is $124 and the annual cash flow is $50; what is the corresponding discount rate? The formula is given here:

  14. Based on the solution of the previous question, what is the corresponding quarterly rate?

  15. For a perpetuity, the same cash flow happens at the same interval forever. A growing perpetuity is defined as follows: the future cash flow is increased at a constant growth rate forever. If the first cash flow happens at the end of the first period, we have the following formula:

    Here PV is the present value, C is the cash flow of the next period, g is a growth rate, and R is the discount rate. If the first cash flow is $12.50, the constant growth rate is 2.5 percent, and the discount rate is 8.5 percent. What is the present value of this growing perpetuity?

  16. For an n-day variance, we have the following formula:

    Here is the daily variance and is is the daily standard deviation (volatility). If the volatility (daily standard deviation) of a stock is 0.2, what is its 10-day volatility?

  17. We expect to have $25,000 in 5 years. If the annual deposit rate is 4.5 percent, how much do we have to deposit today?

  18. The substitution function called sub() is from a Python module. Find out how many functions are contained in that module.

  19. Write a Python program to convert the standard deviation estimated based on daily data or monthly data to an annual one by using the following formulas:

  20. The Sharpe ratio is a measure of trade-off between benefit (excess return) and cost (total risk) for an investment such as a portfolio. Write a Python program to estimate the Sharpe ratio by applying the following formula:

    Here is the portfolio mean return, is the mean risk-free rate and σ is the risk of the portfolio. Again, at this moment, it is perfectly fine that a reader does not understand the economic meaning of this ratio since the Sharpe ratio will be discussed in more detail in Chapter 7, Multifactor Models and Performance Measures.