According to Wikipedia, optimism is ” an attitude reflecting a belief or hope that the outcome of some specific endeavor, or outcomes in general, will be positive, favorable, and desirable.” So optimism is basically a hopeful mode that you are in when there is little hope about something that you are hopeful about. There are actually ten psalms about hope. One is Psalms 34:17-20:

When the righteous cry for help, the Lord hears,
and rescues them from all their troubles.

The Lord is near to the brokenhearted,
and saves the crushed in spirit.

Many are the afflictions of the righteous,
but the Lord rescues them from them all.

He keeps all their bones;
not one of them will be broken.

One more is Psalms 121:1-2;7-8:

I raise my eyes toward the mountains.
From whence shall come my help?

My help comes from the Lord,
the maker of heaven and earth…

The Lord will guard you from all evil;
He will guard your soul.

The Lord will guard your coming and going
both now and forever.

Some of the reasons offered in the Psalms for long-term optimism are when David is asking God for help from his enemies. In Psalms 59:

1  Deliver me from my enemies, O my God;

protect me from those who rise up against me;

 2  deliver me from those who work evil,

and save me from bloodthirsty men.

 3  For behold, they lie in wait for my life;

fierce men stir up strife against me.

For no transgression or sin of mine, O Lord,

 4  for no fault of mine, they run and make ready.

Awake, come to meet me, and see!

 5  You, Lord God of hosts, are God of Israel.

Rouse yourself to punish all the nations;

spare none of those who treacherously plot evil. Selah

 6  Each evening they come back,

howling like dogs

and prowling about the city.

 7  There they are, bellowing with their mouths

with swords in their lips—

for “Who,” they think, “will hear us?”

 8  But you, O Lord, laugh at them;

you hold all the nations in derision.

 9  O my Strength, I will watch for you,

for you, O God, are my fortress.

 10  My God in his steadfast love will meet me;

God will let me look in triumph on my enemies.

 11  Kill them not, lest my people forget;

make them totter by your power and bring them down,

O Lord, our shield!

 12  For the sin of their mouths, the words of their lips,

let them be trapped in their pride.

For the cursing and lies that they utter,

 13  consume them in wrath;

consume them till they are no more,

that they may know that God rules over Jacob

to the ends of the earth. Selah

 14  Each evening they come back,

howling like dogs

and prowling about the city.

 15  They wander about for food

and growl if they do not get their fill.

 16  But I will sing of your strength;

I will sing aloud of your steadfast love in the morning.

For you have been to me a fortress

and a refuge in the day of my distress.

 17  O my Strength, I will sing praises to you,

for you, O God, are my fortress,

the God who shows me steadfast love.

In Psalms by David, you can see that in most of them David is asking God for protection. In some David is asking God for forgiveness. And in many of them, you can see that David is very optimistic in a lot of them.