@@ -162,6 +162,8 @@ def __init__(self, fund: Fund, transactions: List[TransactionDataType]):
162162 self ._merged_transactions = self .merge_transactions ()
163163
164164 self .transactions = deque ()
165+ self .invested = Decimal (0.0 )
166+ self .balance = Decimal (0.0 )
165167 self .gains : List [GainEntry ] = []
166168
167169 self .process ()
@@ -205,6 +207,8 @@ def process(self):
205207
206208 def buy (self , txn_date : date , quantity : Decimal , nav : Decimal , tax : Decimal ):
207209 self .transactions .append ((txn_date , quantity , nav , tax ))
210+ self .invested += quantity * nav
211+ self .balance += quantity
208212
209213 def sell (self , sell_date : date , quantity : Decimal , nav : Decimal , tax : Decimal ):
210214 fin_year = get_fin_year (sell_date )
@@ -223,8 +227,6 @@ def sell(self, sell_date: date, quantity: Decimal, nav: Decimal, tax: Decimal):
223227 stamp_duty = round (purchase_tax * gain_units / units , 2 )
224228 stt = round (tax * gain_units / original_quantity , 2 )
225229
226- pending_units -= units
227-
228230 ge = GainEntry (
229231 fy = fin_year ,
230232 fund = self ._fund ,
@@ -238,6 +240,11 @@ def sell(self, sell_date: date, quantity: Decimal, nav: Decimal, tax: Decimal):
238240 units = gain_units ,
239241 )
240242 self .gains .append (ge )
243+
244+ self .balance -= gain_units
245+ self .invested -= purchase_value
246+
247+ pending_units -= units
241248 if pending_units < 0 and purchase_nav is not None :
242249 # Sale is partially matched against the last buy transactions
243250 # Re-add the remaining units to the FIFO queue
@@ -252,6 +259,8 @@ class CapitalGainsReport:
252259 def __init__ (self , data : CASParserDataType ):
253260 self ._data : CASParserDataType = data
254261 self ._gains : List [GainEntry ] = []
262+ self .invested_amount = Decimal (0.0 )
263+ self .current_value = Decimal (0.0 )
255264 self .process_data ()
256265
257266 @property
@@ -273,6 +282,8 @@ def process_data(self):
273282 fifo = FIFOUnits (
274283 Fund (name = name , isin = scheme ["isin" ], type = scheme ["type" ]), transactions
275284 )
285+ self .invested_amount += fifo .invested
286+ self .current_value += scheme ["valuation" ]["value" ]
276287 self ._gains .extend (fifo .gains )
277288
278289 def get_summary (self ):
0 commit comments