FYI, when you buy shares using CPF, the broking firm will request money from your agent bank. If no credit balance, agent bank will request fund from your CPF. Within 2 or 3 days, fund will be deducted from your CPF. That will bring your CPF savings to a lower amount for interest calculation for that month.
When you sell, the money will go to your agent bank. The money with agent bank earns very little interest, but there is no hurry to push the fund back to CPF as it will not earn CPF interest for that month. If want, refund it few days before end of the month. Refund to CPF can be done through ATM. Usually it takes 2 days for the refund to enter your CPF.
Theoretically, the cost of using CPF to buy shares is loss of 2 months' CPF interest excluding agent bank charges of $xxx for each lot of shares and gst.