This is actually a really often-asked question and I was always ashamed that I could not answer it. So today I decided to see what I can find. And here's the best thing that I can get, from the Collaborative Reference Database (for research using the National Diet Library of Japan), here (if you can read Japanese)
The movie is based on Ibun Rōninki or "A Strange Rōnin Tale", a novel published in 1958. According to the author's note's and afterwards, the novel took inspiration from a story he read in the Meiryōkōhan of about 220 characters in length.
And what do you know, the book does record a similar story. Not having formal training on reading early-modern Japanese, I am very bad at this but bear with me (if anyone can correct me please do):
The Meiryōkōhan was a collection of stories compiled in the early-mid Edo by (supposedly) an abbot of Edo (Tokyo) Seirin-ji named Sanada Zōyo (died 1707 according kotobank encyclopedia). The stories collected range from the late Sengoku to the early-mid Edo. There's little way of knowing whether these stories are correct, however, and it's probably something we will never know.
However, if the story was true, then the timing is different from that of the novel (and movie). Ii Naosumi was head of the Ii family from 1659, and Tairō in the Bakufu from 1668 until his death in 1676. The novel (and movie) make the story take place in the early Edo (1630, during the time of Ii Naotaka, Naosumi's father), specifically tying the characters and their situation to Fukushima Masanori losing his domain in 1619-20. But by the timing of the story in the Meiryōkōhan, I would put forward the hypothesis that it would more likely have taken place in the aftermath of the Great Meireki Fire in 1657, when large sections of Edo, including the castle's keep itself, burnt down, causing widespread hardship and greatly draining the bakufu's resources to deal with restoration. Of course, even without the fire, things were tough enough for rōnin, for the Bakufu policy of transferring daimyō and eliminating domains increase the number of rōnin, many flooding into Edo. There were protests throughout the mid 1630s, Shimabara Rebellion in 1637, the Great Kanei Famine in the early 1640s, one plot to overthrow the newly inherited child shogun Ietsuna in 1651 by rōnin, and another to attack high officials the following year. The plots forced the Bakufu to try to decrease the number of rōnin, encouraging their employment, and refocusing them into bureaucratic work. But then the fire broke out.
So whether or not the story is true, and whether it took place in 1630s or 1650s/60s, it was definately a bad time to be a rōnin.