remaining payments affect ytm in many ways:

1. liquidity risk, longer remaining payments means your investment is locked longer. You demand higher yield for compensation (e.g: 1yr CD rate is usually lower than 3yr CD).

2. interest rate risk. usually ignored for consumer credit product because of dominance of credit risk.

3. Default risk. The biggest part. A unit default risk (academic name: hazard rate, default risk per month) is different at each age (e.g. higher rate of default in middle age than earlier age.). Using survival analysis, you can compute an empirical survival curve and use this curve to calculate YTM that depends on remaining payments.