San Quentin inmate Curtis Carroll, nicknamed "Wall Street," spends 18 hours a day studying the stock market. He carries a folder labeled "penny stocks" with printouts of his favorite stocks, broken down by how they performed each day. He studies patterns meticulously, predicting which ones will or won't make money.

Carroll, who's serving time for murder and armed robbery, is long on American Apparel (APP) and warns against investing in McDonald's (MCD). ("The country is moving more toward health. The ship is too big to turn.")

When Facebook (FB) first went public and the stock was tanking, he invested.

"We went in at about fifteen, sixteen bucks, and yesterday Facebook closed at $86 a share," he told CNNMoney in July.

Related: Hire a coder behind bars

He's also referred to as the "Oracle of San Quentin." Inmates line up for a class he co-teaches with an unlikely counterpart: 32-year-old Zak Williams, the son of beloved comedian Robin Williams.

Williams, who received his MBA from Columbia, spends a good amount of his time studying behavioral finance and valuing tech companies. Carroll, 36, was convicted at 17 and started "picking stocks" ten years ago. It started when he began picking up discarded copies of the Wall Street Journal from a fellow inmate.

"I said, 'Man, I'm going to follow you until you teach me about this stock game,'" he said.

Related: The startup staffed by ex-cons

After his father's death, Williams says he explored prison rehabilitation programs, looking for ways to give back.

"Spending time at San Quentin, giving back, and trying to add value to people's lives is something that's been very helpful for me personally," he told CNNMoney.

In the process, he formed a friendship with "Wall Street."

The duo now teaches a financial literacy class every Thursday at San Quentin. The class educates inmates on what's going in the economy, smart investment strategies, and how inmates can develop skills applicable to life outside prison.

"Whether they are [in for] non-violent or violent crimes, a grossly disproportionate amount [of the crimes] are money related," Williams told CNNMoney. "What we want to do is reveal a whole slew of ways to think about money, and hopefully reveal to people that they can earn it in ways that they didn't previously see."

When CNNMoney visited the class, the discussion was centered around the Greek Debt Crisis and how the crisis affects the market as a whole.

Growing up, Carroll said he would do anything for money.

"If I had a drug problem, or an alcohol problem, I would go to NA, AA, but I have a money problem. ... I believe that financial education is the cure for guys who are chasing money where they're willing to kill a guy for 20 bucks."

Related: 30-to-life and pitching a startup

According to Carroll, a handful of inmates taking the class are actively investing through their families. He wouldn't comment on how much money he's made behind bars.

Williams says the class is ultimately aimed at helping inmates view money from a long-term perspective rather than a "high-risk mindset" associated with trying to get money as quickly as possible.

For Williams, it's personal. Nearly a year after his father's death, Williams often thinks about his father, who lived nearby, when entering the prison gates.

"He was very compassionate towards those who might not have been dealt a great hand in life," he recalls. "His capacity for compassion and love was limitless... it was something that brought him great joy, providing happiness and laughter for untold millions and millions of people."