Stephen Hawking completed a theory outlining his prediction for the end of the world just two weeks before his death, it has emerged.