An algorithm for managing a portfolio of stocks using a trading agent is presented. A simulation game inspired by history-based Parrondo games is described. A performance measure is defined, with which various strategy mixes can be judged. Even when transaction costs are taken into account, active portfolio management (as opposed to Buy and Hold) is shown to be profitable.