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.pswp.cn/news/391982.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391982.shtml
英文地址,請注明出處:http://en.pswp.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等 開發步…