True optimism for a Muslim comes from their understanding of Allah’s nature, not from circumstances. The best way you can sustain optimism is by remembering the favors Allah has bestowed upon you. Every time you catch yourself falling down this path, remind yourself of what goodness Allah has granted you, so much so that you will build up your relationship and love for Him, and it will become the norm for you.