Python code to analyze a stock portfolio