CS 4580/5580 - Problem Set 2

Assigned:Wednesday February 4th
Deadline:Monday March 2nd, 11:59pm

The world's biggest casino: the stock market

In homework 1, you wrote a procedure hitme() which decided whether to have the dealer give you a card for your blackjack hand.

In this assignment, you will write a procedure invest(ticker, client=False), which will take a stock ticker symbol as its argument and return one of three values: buy, sell, or hold. It will also provide an explanation for its recommendation. The optional client parameter can be one of: income, growth, or esg, in which case the procedure will evaluate the stock for inclusion in an income portfolio, growth portfolio, or environment, social, and governance portfolio.

Note: yahoofinance used to provide ESG scores for stocks. It may now be considered too woke. If this data is not available, you should ask your AI friend for advice.

You will use the Yahoo finance api: yahooquery, which is no longer installed as a Python module on the zoo. See yquery.html for more information and a demonstration. You may also avail yourself of yfinance and

Note: you can probably install these modules on your own machine using the normal:

pip install yahooquery
  
OR
pip3 install yahooquery
  
However, I found that the zoo did not let me do that. Instead, I had to install the modules in a python environment:
python3 -m venv 
source /bin/activate
pip install yfinance
pip install yahooquery
    
Moreover, when I wanted to access these modules within jupyter notebooks, I needed more magic. I asked Google (Gemini), which tells you: To use a Python virtual environment with a Jupyter Notebook, you must create the environment, install the ipykernel package within it, and then register it as a kernel that Jupyter can access.

Your program will be similar to your blackjack program. When it gets a ticker, it will use yahooquery to get information about the stock and then use that information to index a table of results. Here are some sample indices:

yahooquery provides you these data (and a boatload more) for most US companies. For this assignment, that is your world. All companies should be US and report in US dollars.

You should gather data on dozens of companies and determine which of these indices can predict performance. To do so, you need to look at a stock's performance for the past 10 years or so. A stock is good if it outperformed the S and P 500 index during that period, and bad if it did worse than the S and P. The ticker for the S and P is "^GSPC".

Your analysis does not need to be one size fits all. You may evaluate companies differently depending on their size, sector, or ESG scores. For example, you could have one metric for technology companies and another for banks.

Explanation

Your procedure needs to provide an explanation that justifies your recommendation. Your process may be either quantitative or qualitative. You might use a machine learning classification based on the Merrill Lynch model portfolios or you might come up with your own set of rules. The explanation should be qualitative. I don't want to see R2's or p-values.

We will not evaluate the accuracy of your recommendation. We are more interested in the coherency of your explanation. Does it make sense? Is it a good story? Even the best Wall Street analyst is not going to be right all the time.

SUBMIT

This assignment will be submitted through Gradescope on the Course Assignments page. You should submit two files: hw2.py and a README file which explains how your program works, as well as a transcript of the program in action. Alternatively, you can submit a jupyter notebook file, hw2.ipynb which contains both code and discussion. The jupyter notebook can also include zippy graphs. The clients love graphs. If you submit a jupyter notebook, also submit the downloaded html and py files - that is, a total of three files.

Here is a simple program for plotting AAPL: aaplchart.py