A DSGE Model with Endogenous Term Structure