Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset Wise Transaction List - Profit Loss Account #325

Open
STOCKZE opened this issue Dec 28, 2023 · 0 comments
Open

Asset Wise Transaction List - Profit Loss Account #325

STOCKZE opened this issue Dec 28, 2023 · 0 comments

Comments

@STOCKZE
Copy link

STOCKZE commented Dec 28, 2023

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant