第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

熊貓的復利資本化

熊貓的復利資本化

桃花長相依 2021-11-16 17:03:53
我正在用熊貓寫一個銀行存款賬戶的模擬。我被復利困住了(這是利息再投資的結果,所以下一個時期的利息是通過本金加上以前累積的利息來賺取的。)到目前為止,我有以下代碼:import pandas as pdfrom pandas.tseries.offsets import MonthEndfrom datetime import datetime# Create a date rangestart = '21/11/2017'now = datetime.now()date_rng = pd.date_range(start=start, end=now, freq='d')# Create an example data frame with the timestamp datadf = pd.DataFrame(date_rng, columns=['Date'])# Add column (EndOfMonth) - shows the last day of the current monthdf['LastDayOfMonth'] = pd.to_datetime(df['Date']) + MonthEnd(0)# Add columns for interest, Sasha, Artem, Total, Descriptiondf['Debit'] = 0df['Credit'] = 0df['Total'] = 0df['Description'] = ''# Iterate through the DataFrame to set "IsItLastDay" valuefor i in df:    df['IsItLastDay'] = (df['LastDayOfMonth'] == df['Date'])# Add the transaction of the first depositdf.loc[df.Date == '2017-11-21', ['Debit', 'Description']] = 10000, "First deposit"# Calculate the principal sum (It the summ of all deposits minus all withdrows plus all compaund interests)df['Total'] = (df.Debit - df.Credit).cumsum()# Calculate interest per day and Cumulative interest# 11% is the interest rate per yeardf['InterestPerDay'] = (df['Total'] * 0.11) / 365df['InterestCumulative'] = ((df['Total'] * 0.11) / 365).cumsum()# Change the order of columnsdf = df[['Date', 'LastDayOfMonth', 'IsItLastDay', 'InterestPerDay', 'InterestCumulative', 'Debit', 'Credit', 'Total', 'Description']]df.to_excel("results.xlsx")輸出文件看起來不錯,但我需要以下內容:“InterestCumulative”欄在每個月的最后一天添加到“Total”欄(復合利息)在每個月的開始,“InterestCumulative”列應該被清除(因為利息被添加到本金總和中)。我怎樣才能做到這一點?
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻1850條經驗 獲得超11個贊

您將需要循環(huán),因為您的總數會根據前面的行而變化,然后會影響后面的行。因此,您當前的利息計算是錯誤的。


total = 0

cumulative_interest = 0


total_per_day = []

interest_per_day = []

cumulative_per_day = []

for day in df.itertuples():

    total += day.Debit - day.Credit

    interest = total * 0.11 / 365

    cumulative_interest += interest


    if day.IsItLastDay:

        total += cumulative_interest


    total_per_day.append(total)

    interest_per_day.append(interest)

    cumulative_per_day.append(cumulative_interest)


    if day.IsItLastDay:

        cumulative_interest = 0


df.Total = total_per_day

df.InterestPerDay = interest_per_day

df.InterestCumulative = cumulative_per_day

不幸的是,這看起來更令人困惑,但當值依賴于以前的值時就會發(fā)生這種情況。根據您的確切要求,可能有一些很好的方法可以使用數學來簡化這一過程,但除此之外,這就是您所擁有的。


我已將其直接寫入 stackoverflow,因此它可能并不完美。


查看完整回答
反對 回復 2021-11-16
  • 1 回答
  • 0 關注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號