We study the expected discounted penalty at ruin under a stochastic discount rate for the compound Poisson risk model with a threshold dividend strategy. The discount rate is modeled by a Poisson process and a standard Brownian motion. By applying the differentiation method and total expectation formula, we obtain an integrodifferential equation for the expected discounted penalty function. From this integrodifferential equation, a renewal equation and an asymptotic formula satisfied by the expected discounted penalty function are derived. In order to solve the integrodifferential equation, we use a physics-informed neural network (PINN) for the first time in risk theory and obtain the numerical solutions of the expected discounted penalty function in some special cases of the penalty at ruin.