Complex dynamics and financial fragility in an agent based model