(Bloomberg) -- Follow Bloomberg on LINE messenger for all the business news and analysis you need.

John Rachmat spent three years researching, backtesting and tweaking his quantitative investment model before he was convinced he had a winning formula.

It took less than four months for the market to put his portfolio to the test.

The former sell-side strategist, best known for accurately predicting the last two bear markets in Indonesia, has dropped near the bottom of the country’s performance rankings after his fund’s ill-fated move to turn bullish on mining stocks shortly after it began trading in mid-2018.

The timing could hardly have been worse. About a day after the fund boosted its weighting in equities to nearly 80% from 2%, with a heavy emphasis on coal companies, a surprise government statement on domestic sales quotas sent the industry tumbling. As his losses surpassed 10%, Rachmat was compelled to intervene: He took some decision-making power back from the algorithm.

“We decided to use a degree of subjective judgment,” he said, adding that he remains confident the fund will perform well over the long term.

Rachmat’s experience illustrates the rocky transition that many asset managers face as they shift toward computer-driven trading strategies that proponents have extolled as the future of investing. Despite their promise, quant funds globally have delivered uneven returns in recent years as they’ve struggled to cope with market volatility. Investors pulled $8 billion from the category in the first four months of 2019, after withdrawing $19 billion in 2018, data from eVestment show.

Rachmat, 52, started experimenting with quantitative models during his time at PT Mandiri Sekuritas, the brokerage arm of a state-run Indonesian lender.

It was there that he earned the nickname “Mr. Bear’’ for his willingness to issue sell calls on the nation’s stock market -- a rarity among analysts at government-owned brokerages. His pessimistic outlooks in late 2012 and 2014 preceded declines of more than 20% in the Jakarta Composite Index.

In 2015 he teamed up with Francis Lim, then a quantitative analyst at Mandiri Sekuritas, who backtested Rachmat’s theories on what kinds of automated trading strategies might perform well in Indonesia. It was a humbling experience.

“Every single one of the numerous ideas I had was shot down by his actual tests,” Rachmat said. “None of those things actually worked.”

Read more: One of Wall Street’s Most Popular Trading Strategies Is Failing

The pair eventually landed on a model that makes two key decisions: how much money to put in stocks relative to safer assets, and which stocks to buy. It picks stocks based on their momentum -- the only factor observed by Rachmat that has worked consistently in Indonesia.

In backtests over 25 years, the model outperformed the Jakarta Composite by an average 2% annually while giving investors some protection from equity crashes, Rachmat said.

By the time he was ready to deploy his model in the real world, Rachmat had moved to PT Pinnacle Persada Investama, Indonesia’s first quantitative asset manager. In April 2018, the firm started the Pinnacle Granditas Dynamic Balanced Fund, tapping Rachmat as its adviser.

The model’s bullish signal in July prompted the fund to increase its equity exposure to the maximum allowed. Its buying was concentrated in mining stocks because they had been outpacing the market on speculation the government would scrap a requirement that at least a quarter of the industry’s coal be sold in Indonesia, where producers earn less relative to the export market.

“Unfortunately, just one day after we did that, the minister of mines and energy canceled any plans of doing away with the domestic-market obligation,” Rachmat said. “Even with the best statistics in the world, you cannot prevent event risk.”

He has since tweaked the fund’s strategy to make its asset-allocation changes more gradual. Now when the algorithm tells him to shift between stocks and safer assets, Rachmat and his team will use some discretion when deciding how quickly to execute the change.

Whether that’s enough to boost returns and assets under management at the 16.4 billion rupiah ($1.1 million) fund remains to be seen. Even though performance has stabilized after last year’s slump, it’s still worse than 84% of peers tracked by Bloomberg in 2019.

Rachmat said the fund’s volatility remains within expectations and that he’s more concerned with long-term performance than short-term swings.

“We remain confident that this fund will deliver its promise once there is sufficient time to allow its statistical properties to shine,” he said.

To contact the reporters on this story: Harry Suhartono in Jakarta at hsuhartono@bloomberg.net;Tom Redmond in Singapore at tredmond3@bloomberg.net

To contact the editors responsible for this story: Divya Balji at dbalji1@bloomberg.net, Michael Patterson

©2019 Bloomberg L.P.