ipywidgets_未来价值和Ipywidgets

ipywidgets

How to use Ipywidgets to visualize future value with different interest rates.

如何使用Ipywidgets可视化不同利率下的未来价值。

There are some calculations that even being easy becoming better with a visualization of his terms. Moreover, the sooner we start investing the more gains we will have in the future. Of course, there are several other variables in the equation of “the game of saving resources for the future” but now two variables will be presented here: interest rate and time.

Ť这里有一些计算方法,甚至易于与他的条件的可视化变得更好。 此外,我们越早开始投资,将来将获得更多收益。 当然,也有“节约资源,为未来的游戏”的公式中其他几个变量,但现在两个变量将在这里介绍: 利率时间

未来价值 (Future Values)

The most basic principle of finance is: a dollar today is worth more than a dollar tomorrow. That means money has a time value.

财务的最基本原则是: 今天的一美元比明天的一美元值更多。 这意味着金钱具有时间价值。

If you invest $100 in a bank account that pays interest of rate 5% a year. In the first year, you will earn interest of 0.05 $100 $5 and the value of your investment will grow to $105:

如果您在银行帐户中投资100美元,该银行帐户的年利率为5%。 在第一年,您将获得0.05美元的利息$ 100 $ 5,您的投资价值将增加到$ 105:

Image for post

如果我们可以“看到”这一点? (And if we can “see” this?)

Now the same equation above can be presented using python. We can use the future value formula or utilize the library Numpy Financial .

现在,可以使用python呈现上述相同的方程式。 我们可以使用未来价值公式或使用Numpy Financial

The numpy financial module contains a function future value, .fv(rate, nper, pmt, pv), which allows you to calculate the future value of an investment as before with a few simple parameters:

numpy金融模块包含一个功能.fv(rate,nper,pmt,pv) ,它允许您像以前一样通过一些简单的参数来计算投资的值:

  • rate: the rate of return of the investment

    rate :投资回报率

  • nper: the lifespan of the investment

    nper :投资寿命

  • pmt: the (fixed) payment at the beginning or end of each period (which is 0 in our example)

    pmt :每个期间开始或结束时的(固定)付款(在我们的示例中为0)

  • pv: the present value of the investment

    pv :投资的现值

It is important to note that in this function call, you must pass a negative value into the pv parameter if it represents a negative cash flow (cash going out).

重要的是要注意,在此函数调用中,如果它表示负现金流量(现金支出),则必须将负值传递到pv参数中。

First, we must import the libraries:

首先,我们必须导入库:

# Importing the libraries
import numpy as np
import numpy_financial as npf
import matplotlib.pyplot as plt

Then, use Numpy’s .fv() function, calculate the future value of a $100 investment returning 5% per year for 2 years.

然后,使用Numpy的.fv()函数,计算100美元的投资在2年内每年返回5%的终值。

# Calculate investment
investment = npf.fv(rate=.05, nper=2, pmt=0, pv=-100)
print("$" + str(round(investment, 2)))$110.25

利率越高,您的储蓄增长越快 (The higher the interest rate, the faster your savings will grow)

Next, you’ll see how plot different interest rates (0%, 5%, 10%, and 15%) with an investment of $100 in the same graph.

接下来,您将看到如何在同一张图中绘制以100美元投资的不同利率(0%,5%,10%和15%)。

figure = figsize=(10,8)
y = [npf.fv(rate=np.linspace(0,0.15,num=4), nper=i, pmt=0, pv=-100) for i in range(21)]

Using the function np.linspace(0, 0.15 , num=4) at rate allows plot 4 curves(num=4), in a range between 0 and 0.15.

以速率使用函数np.linspace(0,0.15,num = 4)允许绘制4条曲线(num = 4),范围在0到0.15之间。

plt.plot(y)plt.legend(["r = 0%", "r = 5%","r = 10%" , "r = 15%"])plt.ylabel('Future value of $100, dollars')
plt.xlabel('years')

As the rates are plotted from a function, to write the legend as an array is a way to present the four rates.

由于比率是从函数中绘制的,因此将图例写为数组是表示这四个比率的一种方法。

Image for post
Figure 1 — Growth of an investment at different interest rates
图1 –不同利率下的投资增长

与Ipywidgets互动 (Interact with Ipywidgets)

Another way to see the impact of interest rate in your future value is by applying an interactive tool in your data. Ipywidgets is a library that uses interface (UI) controls for exploring code and data interactively.

查看利率对未来价值的影响的另一种方法是在数据中应用交互式工具。 Ipywidgets是一个使用界面(UI)控件以交互方式浏览代码和数据的库。

import ipywidgets as widgets
from IPython.display import display
%matplotlib inlinedef show_fv(rate):
figure = figsize=(10,8)
y = [npf.fv(rate, nper=i, pmt=0, pv=-100) for i in range(21)]plt.plot(y)plt.ylabel('Future value of $100, dollars')
plt.xlabel('years')

controls = widgets.interactive(show_fv,rate=(0, .20, .01))
display(controls)

The result is the graph interactive below:

结果是下面的交互式图:

Image for post
Figure 2 — The graph shows different Future values according to the interest rates
图2 —该图显示了根据利率不同的未来值

Figure 2 presents the output of the code using the library Ipywidgets. This is a way to use this tool and know at the time the influence of a variable in your results.

图2展示了使用库Ipywidgets的代码输出。 这是使用此工具并了解变量在结果中的影响的一种方式。

翻译自: https://medium.com/analytics-vidhya/future-values-and-ipywidgets-ce45e4d6a076

ipywidgets

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391982.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2019 css 框架_宣布CSS 2019调查状态

2019 css 框架by Sacha Greif由Sacha Greif 宣布#StateOfCSS 2019调查 (Announcing the #StateOfCSS 2019 Survey) 了解JavaScript状况之后,帮助我们确定最新CSS趋势 (After the State of JavaScript, help us identify the latest CSS trends) I’ve been using C…

计算机主机后面辐射大,电脑的背面辐射大吗

众所周知,电子产品的辐射都比较大,而电脑是非常常见的电子产品,它也存在着一定的辐射,那么电脑的背面辐射大吗?下面就一起随佰佰安全网小编来了解一下吧。有资料显示,电脑后面的辐射比前面大,长期近距离在…

spring— Bean标签scope配置和生命周期配置

scope配置 singleton 默认值,单例的prototype 多例的request WEB 项目中,Spring 创建一个 Bean的对象,将对象存入到 request 域中session WEB 项目中,Spring 创建一个 Bean 的对象,将对象存入session 域中global sess…

装饰器3--装饰器作用原理

多思考,多记忆!!! 转载于:https://www.cnblogs.com/momo8238/p/7217345.html

用folium模块画地理图_使用Folium表示您的地理空间数据

用folium模块画地理图As a part of the Data Science community, Geospatial data is one of the most crucial kinds of data to work with. The applications are as simple as ‘Where’s my food delivery order right now?’ and as complex as ‘What is the most optim…

Windows下安装Python模块时环境配置

“Win R”打开cmd终端,如果直接在里面使用pip命令的时候,要么出现“syntax invalid”,要么出现: pip is not recognized as an internal or external command, operable program or batch file. 此时需要将C:\Python27\Scripts添加…

播客2008

http://blog.tangcs.com/2008/12/29/year-2008/转载于:https://www.cnblogs.com/WarrenTang/articles/1364465.html

linear在HTML的作用,CSS3里的linear-gradient()函数

linear-gradient() 函数用于创建一个线性渐变的 "图像"。为了创建一个线性渐变,你需要设置一个起始点和一个方向(指定为一个角度)的渐变效果。你还要定义终止色。终止色就是你想让Gecko去平滑的过渡,并且你必须指定至少两种,当然也…

golang底层深入_带有Golang的GraphQL:从基础到高级的深入研究

golang底层深入by Ridham Tarpara由里德姆塔帕拉(Ridham Tarpara) 带有Golang的GraphQL:从基础到高级的深入研究 (GraphQL with Golang: A Deep Dive From Basics To Advanced) GraphQL has become a buzzword over the last few years after Facebook made it ope…

spring—Bean实例化三种方式

1&#xff09; 使用无参构造方法实例化 它会根据默认无参构造方法来创建类对象&#xff0c;如果bean中没有默认无参构造函数&#xff0c;将会创建失败 <?xml version"1.0" encoding"UTF-8"?> <beans xmlns"http://www.springframework.o…

bzoj 3439: Kpm的MC密码

Description 背景 想Kpm当年为了防止别人随便进入他的MC&#xff0c;给他的PC设了各种奇怪的密码和验证问题&#xff08;不要问我他是怎么设的。。。&#xff09;&#xff0c;于是乎&#xff0c;他现在理所当然地忘记了密码&#xff0c;只能来解答那些神奇的身份验证问题了。。…

python创建类统计属性_轻松创建统计数据的Python包

python创建类统计属性介绍 (Introduction) Sometimes you may need a distribution figure for your slide or class. Since you are not using data, you want a quick solution.有时&#xff0c;您的幻灯片或课程可能需要一个分配图。 由于您不使用数据&#xff0c;因此需要快…

pytorch深度学习_在本完整课程中学习在PyTorch中应用深度学习

pytorch深度学习In this complete course from Fawaz Sammani you will learn the key concepts behind deep learning and how to apply the concepts to a real-life project using PyTorch. 在Fawaz Sammani的完整课程中&#xff0c;您将学习深度学习背后的关键概念&#x…

html让a标签左右一样宽,button和a标签设置相同的css样式,但是宽度不同

登录注册.btn {display: block;-moz-appearance: none;background: rgba(0, 0, 0, 0) none repeat scroll 0 0;border-radius: 0.25rem;box-sizing: border-box;cursor: pointer;font-family: inherit;font-size: 0.8rem;height: 2rem;line-height: 1.9rem;margin: 0;padding: …

浅析STM32之usbh_def.H

【温故而知新】类似文章浅析USB HID ReportDesc (HID报告描述符) 现在将en.stm32cubef1\STM32Cube_FW_F1_V1.4.0\Middlewares\ST\STM32_USB_Host_Library\Core\Inc\usbh_def.H /********************************************************************************* file us…

spring—依赖注入

依赖注入&#xff08;Dependency Injection&#xff09; 它是 Spring 框架核心 IOC 的具体实现。 在编写程序时&#xff0c;通过控制反转&#xff0c;把对象的创建交给了 Spring&#xff0c;但是代码中不可能出现没有依赖的情况。 IOC 解耦只是降低他们的依赖关系&#xff0c;…

C# (类型、对象、线程栈和托管堆)在运行时的相互关系

在介绍运行时的关系之前,先从一些计算机基础只是入手,如下图: 该图展示了已加载CLR的一个windows进程,该进程可能有多个线程,线程创建时会分配到1MB的栈空间.栈空间用于向方法传递实参,方法定义的局部变量也在实参上,上图的右侧展示了线程的栈内存,栈从高位内存地址向地位内存地…

2019-08-01 纪中NOIP模拟赛B组

T1 [JZOJ2642] 游戏 题目描述 Alice和Bob在玩一个游戏&#xff0c;游戏是在一个N*N的矩阵上进行的&#xff0c;每个格子上都有一个正整数。当轮到Alice/Bob时&#xff0c;他/她可以选择最后一列或最后一行&#xff0c;并将其删除&#xff0c;但必须保证选择的这一行或这一列所有…

knn分类 knn_关于KNN的快速小课程

knn分类 knnAs the title says, here is a quick little lesson on how to construct a simple KNN model in SciKit-Learn. I will be using this dataset. It contains information on students’ academic performance.就像标题中所说的&#xff0c;这是关于如何在SciKit-Le…

spring—配置数据源

数据源&#xff08;连接池&#xff09;的作用 数据源(连接池)是提高程序性能如出现的 事先实例化数据源&#xff0c;初始化部分连接资源 使用连接资源时从数据源中获取 使用完毕后将连接资源归还给数据源 常见的数据源(连接池)&#xff1a;DBCP、C3P0、BoneCP、Druid等 开发步…