Skip to Content
Python金融实战
book

Python金融实战

by Posts & Telecom Press, Yuxing Yan
February 2024
Intermediate to advanced content levelIntermediate to advanced
347 pages
5h 19m
Chinese
Packt Publishing
Content preview from Python金融实战

第3章 用Python编写一个金融计算器

本章介绍如何编写一些简单的Python函数来完成常见的金融计算,如计算未来付款的现值、年金的现值以及按揭的月供。还介绍如何将20多个函数集合在一起,用Python实现一个专业金融计算器的功能。本章主要内容如下。

  • 编写不需要保存的Python函数
  • 缩进格式在Python编程中的重要性
  • 输入函数参数值的3种方式及它们的预设值
  • 利用dir()检查刚完成的函数是否存在
  • 保存自写的pv_f()函数
  • 利用import()在Python编辑器里激活函数
  • 在调试过程中使用Python编辑器激活函数
  • 生成自制的模块
  • 两种注释方法
  • if()函数
  • 计算年金
  • 利率换算和连续复利利率
  • 数据类型:list
  • 净现值法则(net present value,NPV)、投资回收期法则(payback)和内部收益率法则(internal rate of return,IRR)
  • 显示在某个目录下的指定文件
  • 用Python编写一个金融计算器
  • 将我们的目录加到Python的路径上

从编写一个最简单的Python函数开始。以下是计算未来现金的现值的数学公式。

PV=\frac{FV}{(1+R){{}^{n}}}

(3-1)

PV代表现值,FV代表未来获取的现金量,R代表每期折现率,n代表周期的数目。打开Python软件,输入如下两行命令,然后连续敲击回车键两次回到Python的提示符。

>>> def pv_f(fv,r,n):         return fv/(1+r)**n >>> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

实时数据处理和分析指南

实时数据处理和分析指南

Posts & Telecom Press, Shilpi Saxena, Saurabh Gupta
数据科学实战手册(R+Python)(第2版)

数据科学实战手册(R+Python)(第2版)

Posts & Telecom Press, Prabhanjan Narayanachar Tattar, Tony Ojeda, Sean Patrick Murphy, Sean P Murphy, Benjamin Bengfort, Bengfort Benjamin, ABHIJIT DASGUPTA
Python应用开发指南

Python应用开发指南

Posts & Telecom Press, Ninad Sathaye
编写整洁的Python代码(第2版)

编写整洁的Python代码(第2版)

Posts & Telecom Press, Mariano Anaya

Publisher Resources

ISBN: 9781803230375