Endoprosthesis are exposed to the risk of aseptic loosening. The design of the prosthesis shaft to achieve physiological force application is therefore of great importance. Additive manufacturing offers the potential to fabricate highly variable topologies, but challenges the designer with a large number of design variables. In this work, a method is developed to determine an optimized density topology that approximates a given mechanical stress state in the bone after implantation. For this purpose, a topology optimization of the density distribution of the implant is performed.