API,OPENAI & Finance Python Project

High level

So combining a few of my interests:
1) Python

2) Finance

3) AI

I have uploaded the script to

https://github.com/herepete/Fidelity

Setup steps

From a AWS Linux Vm

yum install git
yum install pip
pip3.9 install bs4 pandas
pip3.9 install openai==0.28

create openai account > https://platform.openai.com/docs/overview, create an API key , add openai key to .bashrc for example

export OPENAI_API_KEY="bla"


make sure its visible when running

 env | grep OPEN

run test api script.py – fix issues
run option 1 on menu within main.py -fix issues

run option 2

High Level Aim

A script to find a list of income funds i am interested in.

Then pass that list to openai for some feedback.

What it does

Based on the config in config.py

connect to the Fidelity OpenAi and with the minimal of calls check against criteria namely:

is it an Income fund?

does it have a yield over 4%

is the cost under 1%

As it produced a return of over 3 in the last 1,3 & 5 years

If the Api fails for any reason or the criteria is not met reject the fund straight away to reduce the number of API Calls needed.

If all the tests are passed some extra info is grabbed Last Years Yield, and Overall Morning Star Rating.

At the end you should have a list of funds which have passed all off the test and then that information is all passed to openai to get some feedback.

Considerations and Ideas

I am the first to admit this script needs tweaking and improvement but my aim was to get a first version published rather than having a perfect solution.

I though about multi-threading or multi-processing to speed everything up, but i don’t want to hammer the API.

I could do more with the AI i.e langchain but my aim was to get version 1 working.

I did wonder about getting the results written to a db like sqllite but thats another option for version2

In the output i could use colour and ask the Openai for more information.

You need quite a wide screen to display the ouput as designed.

Maybe play with different openai models to check output.

Maybe open a chat type windows from the command line to allow you to ask questions about the funds.

Play with Openai instructions to get better answers, i haven’t done any fine tunning of the commands.

Files

config.py – basic config, set testing to 0 if you want to unleash the power! & set any criteria you wish on the other fields

main.py – main script to run

test_openai.py – a basic test to check openai is being called, can be run on its own or from the menu in main.py

failer_test_fund.txt – is a log of what fund errored and why, this is only generated when option 2 from main.py is run. We use the funds here and mark them as Previously checked so we don’t unnecessarily test them again.

fidelity_funds.csv – this is your master list of funds to consider about 3,000 ish. This file is only generated when option 1 from main.py is run. The first check in option 2 of main.py is looking through all funds names and removing anything with the word “inc” in.

Typical workflow

setup enviorement

download git scripts

run main.py choose option 1 to create your all files lookup

run main.py chose option 2 – 10 funds are checked

edit config.py and change testing to 0

run main.py choose option 2 – sit back and watch and review results

Interface

It’s all Command line but i have tried to make it visualize as nice as possible.

The page should refresh:

Income stocks found should be about 1117 ish – is all income funds found in fidelity_funds.csv

Previously checked – funds found in failer_test_fund.txt, which is failed funds from any previous runs.

This Round checking – how many funds to check based on Db.config values

This round rejected – how many funds failed

This round suitable funds found – how many funds passed

Verbose stuff – a log of the 10 most recent things than happened

Basic run with no Funds found

Basic run with Funds found

note anything below the line “**Analysis:**” is aI generated.

A Screenshot didn’t look as good here so i have copied and pasted the output as a code line

Income Stocks Found           Previously checked            This round Checking           This Round Rejected           This Round Suitable Funds found

1117                          537                           20                            18                            2

Verbose Stuff...
Starting work on - Rathbone M-A Strategic Growth Port S Inc
Yield check failure
Starting work on - Rathbone M-A Strategic Income Port S Inc
Yield check failure
Starting work on - Rathbone M-A Total Return Port S Inc
Yield check failure
Starting work on - Schroder High Yield Opportunities Z Inc
Suitable Fund Found=Schroder High Yield Opportunities Z Inc
Starting work on - Schroder Strategic Credit L Inc
Suitable Fund Found=Schroder Strategic Credit L Inc

Here are the raw results and the AI feedback on those funds...
Based on the provided data, here is a comparison of the two income funds:

| Fund Name                           | ISIN          | Fee (%) | Yield (%) | Frequency     | Y1_Annualized | Y3_Annualized | Y5_Annualized | Last Year's Yield | Morning Star Rating |
|------------------------------------|-------------------------------|--------|----------|----------------|----------------|----------------|----------------|------------------|---------------------
| Schroder High Yield Opportunities Z Inc | GB00B5143284 | 0.72   | 7.71      | Monthly        | 15             | 3             | 5                | 7.82                 | 5                   |
| Schroder Strategic Credit L Inc         | GB00B11DP098 | 0.67   | 6.33      | Semi-Annually | 12             | 3             | 4                | 5.90                 | 5                   |

**Analysis:**

**Schroder High Yield Opportunities Z Inc:**
- **Pros:**
  - Higher yield (7.71%)
  - Monthly frequency of payouts
  - Higher Y1_Annualized return (15%)
  - Higher Last Year's Yield (7.82%)
  - Morning Star Rating of 5

- **Cons:**
  - Slightly higher fee compared to the other fund (0.72%)
  - Lower Y3_Annualized and Y5_Annualized returns

**Schroder Strategic Credit L Inc:**
- **Pros:**
  - Lower fee (0.67%)
  - Lower fee than the other fund
  - Consistent Morning Star Rating of 5

- **Cons:**
  - Lower yield (6.33%)
  - Semi-annual frequency of payouts
  - Lower Y1_Annualized and Last Year's Yield
  - Lower Y3_Annualized and Y5_Annualized returns compared to the other fund

**Additional Research:**
- Further research into the credit quality of the underlying assets might provide insights into the risk profile of these funds.
- Comparison of the fund performance against relevant benchmark indices.

In summary, the Schroder High Yield Opportunities Z Inc fund offers a higher yield and better short-term performance, but at a slightly higher fee. On the other hand, the Schroder Strategic Credit L Inc fund has a lower fee and consistent Morning Star Rating, but with lower yield and overall returns. Investors may consider their investment goals, risk tolerance, and liquidity preferences when choosing between these two funds.
AI Anslysis completed