You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To have a asset wise transaction history - summary where we can see profit/loss for transactions asset wise, something along these lines - where every portfolio change can be analyzed for asset wise summary
def record_transaction(self, old_weights, new_weights, current_date, current_prices):
for asset in self.portfolio:
old_weight = old_weights.get(asset, 0)
new_weight = new_weights.get(asset, 0)
quantity_change = (new_weight - old_weight) * current_prices[asset]
transaction = {
'date': current_date,
'asset': asset,
'type': 'buy' if new_weight > old_weight else 'sell',
'quantity': abs(quantity_change),
'price_per_unit': current_prices[asset],
'total_value': abs(quantity_change) * current_prices[asset],
# Add other elements like fees, profit/loss, etc.
}
self.transaction_history.append(transaction)
The text was updated successfully, but these errors were encountered:
To have a asset wise transaction history - summary where we can see profit/loss for transactions asset wise, something along these lines - where every portfolio change can be analyzed for asset wise summary
The text was updated successfully, but these errors were encountered: