DAY 0: a0A is the cost of A shares at $a0 per share.
DAY 7: sale of A shares at $a7=$4.60 per share=a7A=4.60A; cost of 2000 shares of company B=2000b7; 4.60A-2000b7=7400.
DAY 12: a12=4.80; b7=4.80-0.50=4.30;
5000b12-a12A=5800=5000b12-4.80A: 5000b12-4.80A=5800.
4.60A=7400+2000b7=7400+2000*4.3=7400+8600=16000.
So A=16000/4.6=3478.26 shares.
5000b12=5800+4.80A=5800+16695.65=22495.65, so b12=$4.50
The number of shares=3478.26; company B's share price on Day 12 is $4.50.
CHECK
If company A shares sold, result of sale of A shares on Day 7 would be 3478.26*4.60=$16000.
Cost of B shares on Day 7 is 2000*4.30=$8600, so 16000-8600=$7400 in pocket.
If company A shares are sold on Day 12, sale=3478.26*4.80=$16700; 5000 B shares cost 5000*4.50=$22500. To pay: 22500-16700=$5800.
(Some of the figures are rounded up.)