We construct an algorithm that makes it possible to numerically obtain an investor's optimal portfolio under general preferences. In particular, the objective function and risks constraints may be driven by benchmarks (reflecting state-dependent preferences). We apply the algorithm to various...