A casual observer may assume Bridgewater Associates founder Ray Dalio, who runs the world's largest hedge fund, only had a charmed investing career filled with success after success.

But that isn't the case, as the legendary investor explained in his upcoming book. He actually went broke eight years after he started his investment firm. Counterintuitively, this failure was the best thing that ever happened to him, he said.

In 1982, Dalio confidently predicted the global economy was headed toward a depression and he traded accordingly.

"I was dead wrong … The stock market began a big bull run, and over the next eighteen years the U.S. economy enjoyed the greatest noninflationary growth period in its history," he wrote in his book entitled "Principles: Life and Work," available on Tuesday.

"My experience over this period was like a series of blows to the head with a baseball bat. Being so wrong – and especially so publicly wrong – was incredibly humbling and cost me just about everything I had built at Bridgewater," he added.

Due to the losses, the investor was forced to lay off all of his employees and ask for money from his family.

"I'd lost so much money I couldn't afford to pay the people who worked with me. One by one, I had to let them go," he wrote. "To make ends meet, I even had to borrow $4,000 from my dad until we could sell our second car."

Dalio said he was too arrogant, overconfident and failed to do enough historical research, but the incident led to the self-improvement he needed to become successful:

"In retrospect, my crash [failure] was one of the best things that ever happened to me because it gave me the humility I needed to balance my aggressiveness. I learned a great fear of being wrong that shifted my mind-set from thinking 'I'm right' to asking myself 'How do I know I'm right?' And I saw clearly that the best way to answer this question is by finding other independent thinkers who are on the same mission as me and who see things differently from me. By engaging them in thoughtful disagreement, I'd be able to understand their reasoning and have them stress-test mine."

Failure was the key driver in developing a new perspective Dalio called being "radically open-minded" and helped turn Bridgewater into an idea meritocracy.

"I learned that failing is an essential step toward success, and that the key to success lies in knowing how to both strive for a lot and fail well," he wrote. "By failing well, I mean being able to experience painful failures that provide big learnings without failing badly enough to get knocked out of the game."