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:

如果我們可以“看到”這一點? (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.
由于比率是從函數中繪制的,因此將圖例寫為數組是表示這四個比率的一種方法。

與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:
結果是下面的交互式圖:

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,一經查實,立即刪除!