My experience is a lot like Lski'stash's above. To slightly rephrase the question, you might also look at optimism as a type of awareness or as a practice or skill. All of us have millions of thoughts and emotions that pop up every day without us consciously asking for them. Out of all these thoughts, there's usually ample evidence for both a positive or negative interpretation of a given set of circumstances, so pure rationality could take you in either direction. It's how we react to these thoughts -- specifically the mental narrative that we create based on them -- that makes the difference.
For example, I'm sure almost everyone has had something like the following take place: I walk into the kitchen and there's a dirty plate with scraps of food. Clearly, the person who used it is finished with their meal. Our informal house rule is that everyone cleans up after him/herself. It wasn't me that used it, so it had to have been my wife.
Why did she just leave it there for me to pick it up? Mild annoyance. Oh, ok. This is payback for me forgetting to feed the dog last night. Real mature. Beginnings of anger. I wish instead of pulling crap like this, she'd just TELL me when she's unhappy with something. Growing anger. Geez, this always happens. I don't know why I thought that this stuff would go away once we got married. Everything I do is wrong, and she never makes a mistake. And now I've arrived at full-blown anger.
Wife walks in, and before I can say something nasty to her, she says, "Hey, honey. Sorry about the plate. I was about to wash it when my mom called. I've been waiting to hear what the doctor told her, so I wanted to make sure I caught her."
So what's happened is that I've acted in a way that mimics rationality by taking an external event, analyzing it using the evidence at hand, and then coming to a conclusion about what's happened. The problem is that all of my inputs, my evidence, were a complete fiction that I treated as fact. Along the way, the physical manifestations of anger in my body -- increased heart rate, tensed muscles, etc. -- fuel the fictional narrative in my head, and I arrive at an entirely irrational conclusion: "Dirty plate sitting on the counter" = "My wife doesn't respect me, and our very marriage may have been a mistake."
To put it in terms of the stock market, in the analyses that we all like to laugh at -- one person saying, "Dow on its way to 40,000" and the other, "Put all your money in canned food and bullets. It's about to get rocky." -- you've got different people using the same data to come to wildly different conclusions that are each rational in their way. One of them is choosing to argue one potential positive outcome out of an almost infinite number, and the other a potential negative outcome. The problem is when you start getting too attached to your own interpretation, which is, by virtue of the fact that we can't see or control the future, always by definition a fiction. When you habitually lean in one direction or the other, you become an optimist or a pessimist.
To return to the original question, you can learn to see and address this through Buddhist meditation, mindfulness training (pretty similar secular version of meditation), and cognitive-behavioral therapy. All of which basically teach you that "dirty plate sitting on the counter" does NOT equal "wife doesn't respect me, and our very marriage may have been a mistake." "Dirty plate sitting on the counter" = "Dirty plate sitting on the counter."