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

Understanding the Net Present Value (NPV) profile


Gradually, we use graphs and other visual representations to explain many complex financial concepts, formulae, and trading strategies. An NPV profile is the relationship between a project's NPV and its discount rate (cost of capital). For a normal project, where cash outflows first then cash inflows, its NPV will be a decreasing function of the discount rate. The reason is that when the discount rate increases, the present value of the future cash flows (most time benefits) will decrease more than the current or the latest cash flows (most time costs). The NPV is defined by the following formula:

The following program demonstrates a negative correlation between NPV and the discount rate:

>>>import scipy as sp
>>>from matplotlib.pyplot import *
>>>cashflows=[-100,50,60,70]
>>>rate=[]
>>>npv=[]
>>>x=(0,0.7)
>>>y=(0,0)
>>>for i in range(1,70):
    rate.append(0.01*i)
  ...