Calculating Trades with Python