Commit cb6d334e authored by Anthony Jacob's avatar Anthony Jacob
Browse files

add info to the portfolio summary provided to llm

parent 4ef37f90
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@ type PortfolioSummary = {
        quantity: number;
        averagePrice: number;
        currentPrice: number | null;
        buyFees: number;
        sellFees: number;
        profitOrLossIfSold: number;
    }>;
};

@@ -155,15 +158,24 @@ export class ChatService {
                    quantity: 0,
                    averagePrice: 0,
                    currentPrice,
                    buyFees: 0,
                    sellFees: 0,
                    profitOrLossIfSold: 0,
                };
            }

            const existing = summary.position[ticker];
            const totalCost = existing.averagePrice * existing.quantity + unitPrice * quantity;
            const totalQty = existing.quantity + quantity;
            const buyFees = existing.buyFees + this.toNumber(position.buyFees) + this.toNumber(position.buyTaxes);
            const sellFees = currentPrice !== null ? totalQty * currentPrice * 0.0065 : 0; // estimated sell fees and taxes
            const profitOrLossIfSold = currentPrice !== null ? (currentPrice - existing.averagePrice) * totalQty - buyFees - sellFees : 0;
            existing.quantity = totalQty;
            existing.averagePrice = totalQty > 0 ? totalCost / totalQty : 0;
            existing.currentPrice = currentPrice;
            existing.buyFees = buyFees;
            existing.sellFees = sellFees;
            existing.profitOrLossIfSold = profitOrLossIfSold;
        }

        return summary;