Hello everyone,
Just when I thought I had it all worked out With FIFO and Averages after many days, trials and errors,
I started inputting different Symbols and it all Failed on me.
The current FIFO Module calculations works perfectly if I only use same symbol in Column "I" But not when I input Different Symbols.
I Have highlighted in Yellow the should be result, in Orange the Bad result and in Green the Good result.
How can I Calculate The P/L in Column "O" and Average-FIFO in Column "U" based only on Individual Symbol transactions?
I have attempted to find a solution with functions such as Sumproduct, Sumifs and index/match but to no avail.
I believe the Module code needs modifications to accept different symbols
Of perhaps have been writing the attempted formulas incorrectly.
All would be perfect If I could Have the FIFO P/L and FIFO Averages corrected.
Thank you for the help
Cheers
ONP
This is the Code written in the Module
Just when I thought I had it all worked out With FIFO and Averages after many days, trials and errors,
I started inputting different Symbols and it all Failed on me.
The current FIFO Module calculations works perfectly if I only use same symbol in Column "I" But not when I input Different Symbols.
I Have highlighted in Yellow the should be result, in Orange the Bad result and in Green the Good result.
How can I Calculate The P/L in Column "O" and Average-FIFO in Column "U" based only on Individual Symbol transactions?
I have attempted to find a solution with functions such as Sumproduct, Sumifs and index/match but to no avail.
I believe the Module code needs modifications to accept different symbols
Of perhaps have been writing the attempted formulas incorrectly.
All would be perfect If I could Have the FIFO P/L and FIFO Averages corrected.
Thank you for the help
Cheers
ONP
This is the Code written in the Module
VBA Code:
Function CostOfShares(PresentShares As Range, DescriptionRng As Range, SharesRng As Range, DebitRng As Range)
Dim T As Long, Temp As Long, Amt As Double
Temp = PresentShares.Value
For T = DescriptionRng.Rows.Count To 1 Step -1
If DescriptionRng.Cells(T, 1) = "BUY" Then 'And SharesRng.Cells(T, 1) < Temp
If Temp >= SharesRng.Cells(T, 1) Then
Amt = Amt + DebitRng.Cells(T, 1)
Temp = Temp - SharesRng.Cells(T, 1)
Else
Amt = Amt + (Temp * (DebitRng.Cells(T, 1) / SharesRng.Cells(T, 1)))
Exit For
End If
End If
Next T
CostOfShares = Amt
End Function
Onp MrExcel Forum Symbol FIFO Sample.xlsm | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | |||
1 | BUY And SELL Is CASE SENSITIVE | ||||||||||||||||
2 | |||||||||||||||||
3 | |||||||||||||||||
4 | |||||||||||||||||
5 | |||||||||||||||||
6 | Doesn’t work well if Different symbols are used | FIFO | |||||||||||||||
7 | Module Formula | Average FIFO | |||||||||||||||
8 | Date | Description | Symbol | Shares | Price | Debit | Credit | Bal. | P/L | ||||||||
9 | 12/21/2020 | BUY | AGNC | 100 | 15.240 | 1,524.00 | 0.00 | 100 | 0.00 | Should Be | 1524.00 | 15.2400 | |||||
10 | 12/29/2020 | BUY | NLY | 100 | 10.000 | 1,000.00 | 0.00 | 200 | 0.00 | GOOD | 2524.00 | 12.6200 | |||||
11 | 12/30/2020 | BUY | AGNC | 100 | 14.240 | 1,424.00 | 0.00 | 300 | 0.00 | BAD | 3948.00 | 13.1600 | |||||
12 | 12/30/2020 | SELL | AGNC | 100 | 14.060 | 0.00 | 1,406.00 | 200 | -118.00 | 2424.00 | 12.1200 | ||||||
13 | 1/6/2021 | SELL | NLY | 50 | 11.000 | 0.00 | 550.00 | 150 | 50.00 | 1924.00 | 12.8267 | ||||||
14 | 10/8/2020 | BUY | AGNC | 100 | 13.460 | 1,346.00 | 0.00 | 250 | 0.00 | 3270.00 | 13.0800 | ||||||
15 | 10/8/2020 | SELL | AGNC | 100 | 13.170 | 0.00 | 1,317.00 | 150 | 105.00 | -107 | 2058.00 | 13.7200 | |||||
16 | 10/8/2020 | BUY | AGNC | 100 | 11.750 | 1,175.00 | 0.00 | 250 | 0.00 | 3233.00 | 12.9320 | ||||||
17 | |||||||||||||||||
18 | |||||||||||||||||
19 | |||||||||||||||||
20 | |||||||||||||||||
21 | |||||||||||||||||
22 | |||||||||||||||||
23 | GOOD | Works Well if all Same Symbol | FIFO | ||||||||||||||
24 | Module Formula | Average FIFO | |||||||||||||||
25 | Date | Description | Symbol | Shares | Price | Debit | Credit | Bal. | P/L | ||||||||
26 | 12/21/2020 | BUY | AGNC | 100 | 15.240 | 1,524.00 | 0.00 | 100 | 0.00 | 1524.00 | 15.2400 | ||||||
27 | 12/29/2020 | BUY | AGNC | 100 | 14.080 | 1,408.00 | 0.00 | 200 | 0.00 | 2932.00 | 14.6600 | ||||||
28 | 12/30/2020 | BUY | AGNC | 100 | 14.240 | 1,424.00 | 0.00 | 300 | 0.00 | 4356.00 | 14.5200 | ||||||
29 | 12/30/2020 | SELL | AGNC | 100 | 14.060 | 0.00 | 1,406.00 | 200 | -118.00 | 2832.00 | 14.1600 | ||||||
30 | 1/6/2021 | SELL | AGNC | 50 | 13.790 | 0.00 | 689.50 | 150 | -14.50 | 2128.00 | 14.1867 | ||||||
31 | 10/8/2020 | BUY | AGNC | 100 | 13.460 | 1,346.00 | 0.00 | 250 | 0.00 | 3474.00 | 13.8960 | ||||||
32 | 10/8/2020 | SELL | AGNC | 100 | 13.170 | 0.00 | 1,317.00 | 150 | -99.00 | 2058.00 | 13.7200 | ||||||
33 | 10/8/2020 | BUY | AGNC | 100 | 11.750 | 1,175.00 | 0.00 | 250 | 0.00 | 3233.00 | 12.9320 | ||||||
34 | |||||||||||||||||
35 | |||||||||||||||||
36 | |||||||||||||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
L26:L33,L9:L16 | L9 | =IF(H9="BUY",J9*K9,0) |
M26:M33,M9:M16 | M9 | =IF(H9="SELL",J9*K9,0) |
N9,N26 | N9 | =J9 |
O9:O16 | O9 | =T9+SUM(M$9:M9)-SUM(L$9:L9)-SUM(O$8:O8) |
N27:N33,N10:N16 | N10 | =N9+SUMIFS(J10,H10,"BUY")-SUMIFS(J10,H10,"SELL") |
T9:T16 | T9 | =CostOfShares(N9,$H$9:$H9,$J$9:$J9,$L$9:$L9) |
U26:U33,U9:U16 | U9 | =T9/N9 |
O26:O33 | O26 | =T26+SUM(M$26:M26)-SUM(L$26:L26)-SUM(O$25:O25) |
T26:T33 | T26 | =CostOfShares(N26,$H$26:$H26,$J$26:$J26,$L$26:$L26) |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
AF:XFD,T15:AD15,A15:R15,A6:F6,A16:AD1048576,A3:G3,L3:AD3,A1:AD2,H6:Q6,A4:Q5,S4:AD6,A7:AD14 | Cell Value | =0 | text | NO |