我需要创建此计算的SQL版本,如此处详细描述(https://www.adjustedcostbase.ca/blog/how-to-calculate-adjusted-cost-base-acb-and-capital-gains/)。作为表格或视图。
总而言之,最终结果需要是一个表格,如下图所示:([1]:https://i.stack.imgur.com/ZmFPQ.png)
Row 1) New Total ACB = [Previous Total ACB] + ([Share Price] x [Number of Shares Purchased]) + [Transaction Costs]
= $0 + ($50/share x 100 shares) + $10
= $5,000 + $10
= $5,010
Row 2) New Total ACB = [Previous Total ACB] x (([Previous Number of Shares] – [Number of Shares Sold]) / [Previous Number of Shares])
= $5,010 x ((100 shares – 50 shares) / 100 shares)
= $2,505
Row 3) New Total ACB = [Previous Total ACB] + ([Share Price] x [Number of Shares Purchased]) + [Transaction Costs]
= $2,505 + ($130/share x 50 shares) + $10
= $9,015
Row 4) New Total ACB = [Previous Total ACB] x (([Previous Number of Shares] – [Number of Shares Sold]) / [Previous Number of Shares])
= $9,015 x ((100 shares – 40 shares) / 100 shares)
= $5,409
发生负交易(出售)时,事情变得复杂,我无法弄清楚如何计算“ ACB的变化”和“ ACB”列。