We take advantage of a unique setting in China to provide novel evidence on a catering theory for analyst optimism. Our study utilizes the Stock Connect programs that allowed foreign investors to invest in Chinese stocks as an exogenous shock to investor beliefs. We further focus our study on a subset of Chinese firms with both "A shares" (listed in mainland China) and "H shares" (listed in Hong Kong) to provide a clean test of our hypotheses. We find that A share analysts become less optimistic in their recommendations following the introduction of less optimistic investors through the Stock Connect programs. In addition, catering theory predicts that when investors hold heterogeneous beliefs, analysts tend to segment the market and slant toward extreme positions in order to attract target investors. Consistent with this prediction, we find that A share analysts with buy or strong buy (sell or underperform) recommendations of a given firm become more optimistic (pessimistic) in their forecasts and research report tone after the Stock Connect programs. Finally, we show that in updating their earnings forecasts, analysts are more (less) responsive to earnings surprises that are consistent (inconsistent) with their stock recommendations. Overall, the results suggest that analysts cater to investors' opinions