using if statements to find daily stock holding and cash
1 view (last 30 days)
Suppose you owned 100 shares with no cash over a 17 day period and you bought 10 shares every day the price was below $193.50 and sold 10 shares every day the price was above $195.00. For each transaction (buying or selling shares) you will have to pay a flat commission fee of $10.00. I'm trying to find ...
(a) The daily amount your total stock holding in dollars.
(b) The daily amount your total cash in dollars.
(c) The total number of shares you own at end of 17 day period
(d) The net change in the worth (defined as sum of stock holding and cash) at end of 17 day period
The problem I'm having is that the if statements are not working and it seems like nothing happens.
Price=[199.54 195.89 195 192 193.29 197.09 197.78 190.34 189.55 193.30...
196 194.60 193.63 193 193.77 195.23 193.97];
Sahithi Kanumarlapudi on 16 Dec 2020
From the code snippet you have provided, it looks like you are trying to compare whether all the elements of the Price array are either greater than 195 or less than 193.50.
But both these conditions
are never true with the input 'Price' which you are trying to use because all the elements in Price are between 192 and 199. This is reason why you are not seeing any output.
If your intention is to compare each and every element of the Price array with the cost of the share, using for loop might be helpful.
Hope this helps!