我在excel工作簿中有一个这样的交易日志 -
+----+-----------+-----------+----------+-----+-------------------------------+------------+-------+---------+---------+
| | A | B | C | D | E | F | G | H | I |
+----+-----------+-----------+----------+-----+-------------------------------+------------+-------+---------+---------+
| 1 | Date | Stock/ETF | Price | Qty | Buy/Sell/Deposit/Withdrawn/RH | Adjustment | Fees | Total | Balance |
+----+-----------+-----------+----------+-----+-------------------------------+------------+-------+---------+---------+
| 2 | 9/1/2016 | | | | Deposit | | | $100.00 | $100.00 |
| 3 | 9/29/2016 | MSTX | $0.1006 | 900 | Buy | | | $90.54 | $9.46 |
| 4 | 9/30/2016 | MSTX | $0.1016 | 900 | Sell | | $0.11 | $91.44 | $100.79 |
| 5 | 9/30/2016 | BVX | $4.9000 | 20 | Buy | | | $98.00 | $2.79 |
| 6 | 10/3/2016 | AMRS | $0.5921 | 4 | Buy | | | $2.37 | $0.42 |
| 7 | 10/3/2016 | BVX | $5.3700 | 10 | Sell | | $0.00 | $53.70 | $54.12 |
| 8 | 10/3/2016 | NTNX | $40.1500 | 1 | Buy | | | $40.15 | $13.97 |
| 9 | 10/3/2016 | AMRS | $0.5973 | 21 | Buy | | | $12.54 | $1.43 |
| 10 | 10/3/2016 | AMRS | $0.5859 | 2 | Buy | | | $1.17 | $0.26 |
| 11 | 10/4/2016 | NTNX | $40.2600 | 1 | Sell | | $0.00 | $40.26 | $40.51 |
| 12 | 10/4/2016 | AMRS | $0.5828 | 27 | Sell | | $0.00 | $15.74 | $56.25 |
| 13 | 10/4/2016 | AUPH | $3.4800 | 16 | Buy | -$0.08 | | $55.60 | $0.65 |
| 14 | 10/6/2016 | AUPH | $5.1500 | 16 | Sell | | $0.00 | $82.40 | $83.04 |
| 15 | 10/6/2016 | BVX | $5.2500 | 10 | Sell | | $0.00 | $52.50 | $135.54 |
+----+-----------+-----------+----------+-----+-------------------------------+------------+-------+---------+---------+
以下是公式 -
H3 =IF(((C3*D3)+F3)<>0,((C3*D3)+F3),"")
I3 =IF(E3="Buy",I2-H3,IF(E3="Sell",I2+H3-G3,IF(E3="Deposit",I2+H3,IF(E3="Withdrawn",I2-H3,IF(E3="Robin Hood",I2-G3,"")))))
G4 =IF(E4="Sell",(D4*C4*0.0000218)+(D4*0.000119),"")
日期,调整,股票/ ETF,价格,数量,买入/卖出/存款/撤回/ RH,调整列均为人工输入!
我试图在excel中实现这样的事情,其中每一行都指的是&#34; Sells&#34;在主表中计算利润/亏损,具体取决于当天销售的股票数量和销售价格。它也应该适用于部分销售,并且不会计入尚未售出的股票 -
+---+-----------+--------+-------------+
| | A | B | C |
+---+-----------+--------+-------------+
| 1 | Date | Ticker | Profit/Loss |
+---+-----------+--------+-------------+
| 2 | 9/30/2016 | MSTX | $0.90 |
| 3 | 10/3/2016 | BVX | $4.70 |
| 4 | 10/4/2016 | NTNX | $0.11 |
| 5 | 10/4/2016 | AMRS | -$0.34 |
| 6 | 10/6/2016 | AUPH | $26.80 |
| 7 | 10/6/2016 | BVX | $3.50 |
+---+-----------+--------+-------------+
我已经填充了A列和B列。现在我需要根据此PowerShell代码计算利润/损失(PL)列 -
$AllbuyTickers = @()
$AllsellTickers = @()
$AllsellTickers += $Current_Ticker
do
{
if (closest similar ticker above current cell = "Buy")
{
$AllBuyTickers += $This_Ticker
$OutstandingShares = Sumof($AllbuyTickers.Qty) - Sumof($AllsellTickers.Qty)
}
else
{
$AllSellTickers += $This_Ticker
}
Find the next similar ticker above
}
until ($OutstandingShares >= 0)
if (OutstandingShares < 0)
{
do
{
if (closest similar ticker above current cell = "Buy")
{
AllBuyTickers += This Ticker
OutstandingShares = Sumof(AllbuyTickers.Qty) - Sumof(AllsellTickers.Qty)
}
else
{
AllSellTickers += This Ticker
}
Find the next similar ticker above
}
until (OutstandingShares = 0)
}
$AvgSellPrice = Sumof($AllsellTickers.Total) / Sumof($AllsellTickers.qty)
$AvgBuyPrice = Sumof($AllbuyTickers.Total) / Sumof($AllbuyTickers.qty)
$PL = ($AvgSellPrice - $AvgBuyPrice) * Sumof($AllsellTickers.qty)
如何在excel中使用它?