Calculating reinvestment of dividends with a cumulative approach
问题 This is what my data.table looks like. The A:E columns are just to draw comparison to excel. Column NewShares is my desired column. I DO NOT have that column in my data. A B C D E F dt<-fread(' InitialShares Level Price Amount CashPerShare NewShares 1573.333 0 9.5339 13973.71 0 1573.333 0 1 10.2595 0 .06689 1584.73 0 1 10.1575 0 .06689 1596.33 0 1 9.6855 0 .06689 1608.58') I am trying to calculate NewShares with the assumption that new shares are added to InitialShares by reinvesting