This study proposes methods for solving the optimal self-scheduling and bidding strategy of a thermal generating unit subject to ramp constraints and price uncertainty. In the first-half of the study, the authors propose a polynomial algorithm for deterministic self-scheduling for the generating company (GenCo) to optimally respond to day-ahead markets assuming market prices can be precisely forecasted. The authors then consider the GenCo bidding to real-time market in the second-half of the study. A multi-stage stochastic program is set up, where in the first stage the GenCo makes a decision as whether it should submit a bid or change an existing bid to the real-time market. In case that the GenCo participates in the first stage, the unit is dispatched by the market in the next stage. Then the process repeats. The authors propose a regression-based method to approximate the recourse function and determine the optimal commitment and dispatch policy for the GenCo, which yields the optimal bidding strategy for the GenCo to participate the real-time spot market.