The president purchased up to $24.3 million in stocks from arms manufacturers and other Pentagon contractors last year.