I think you'll have to make some tradeoffs to represent this.
For tax tracking purposes, you'll want to keep the total cost basis the same. That will let you calculate realized profit when you choose to sell.
For investment performance purposes, you want to know what price you actually bought it at.
Assuming the tax part is more important to you, you can track like this:
2021-01-01 * "Buy"
Assets:Brokerage 10 AAA {{10 EUR}}; Buy 10 AAA at 1 EUR each.
Assets:Bank -10 EUR
2021-05-01 * "Exchange"
Assets:Brokerage -10 AAA {1 EUR} ; AAA price is now 2 EUR per unit. 20 EUR transfer.
Assets:Brokerage 4 BBB {{ 10 EUR }} ; BBB current price 5 EUR. Buy 20 EUR of BBB, 10 EUR cost.
An important downside of this method: Beancount uses the `units * cost` as the weight of the posting. That means that if you made a typo and exchanged into 40 BBB, Beancount has no way to check that.