| Assigned: | Wednesday February 4th |
|---|---|
| Deadline: | Monday March 2nd, 11:59pm |
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 yahooqueryOR
pip3 install yahooqueryHowever, I found that the zoo did not let me do that. Instead, I had to install the modules in a python environment:
python3 -m venvMoreover, 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.source /bin/activate pip install yfinance pip install yahooquery
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:
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.
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.
Here is a simple program for plotting AAPL: aaplchart.py