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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

熊貓的復(fù)利資本化

熊貓的復(fù)利資本化

桃花長(zhǎng)相依 2021-11-16 17:03:53
我正在用熊貓寫一個(gè)銀行存款賬戶的模擬。我被復(fù)利困住了(這是利息再投資的結(jié)果,所以下一個(gè)時(shí)期的利息是通過本金加上以前累積的利息來賺取的。)到目前為止,我有以下代碼: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")輸出文件看起來不錯(cuò),但我需要以下內(nèi)容:“InterestCumulative”欄在每個(gè)月的最后一天添加到“Total”欄(復(fù)合利息)在每個(gè)月的開始,“InterestCumulative”列應(yīng)該被清除(因?yàn)槔⒈惶砑拥奖窘鹂偤椭校N以鯓硬拍茏龅竭@一點(diǎn)?
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

您將需要循環(huán),因?yàn)槟目倲?shù)會(huì)根據(jù)前面的行而變化,然后會(huì)影響后面的行。因此,您當(dāng)前的利息計(jì)算是錯(cuò)誤的。


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

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


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


查看完整回答
反對(duì) 回復(fù) 2021-11-16
  • 1 回答
  • 0 關(guān)注
  • 196 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)