Scientists at the University of Lincoln tested 36 animals, offering them bowls containing chocolate or less appealing coffee beans in two fixed locations.
Pigs were considered optimists if they investigated a third bowl, placed in the middle of the two bowls, even though it might not contain treats.
Dr Lisa Collins said it suggested the judgment of pigs was similar to humans.
The research, which has been published in the Royal Society journal Biology Letters, saw some pigs treated to improved living conditions with more living space and extra-deep layers of straw.
The other animals, with less space and no straw, tended to be negative and pessimistic, the research suggested.
They were, however, found to have been cheered up by an improvement in their living conditions.
Dr Collins, from the University of Lincoln, and colleagues wrote: "Reactive pigs in the less enriched environment were more pessimistic and those in the more enriched environment more optimistic.
"These results suggest that judgment in non-human animals is similar to humans, incorporating aspects of stable personality traits and more transient mood states."
Pigs have personalities and can be pessimists or optimists, much like humans, new research has suggested.