Digging deep: Getting the best out of ChatGPT means finding the right prompts

Digging deep: Getting the best out of ChatGPT means finding the right prompts

ChatGPT and other large language models (LLMs) may someday automate many investment management and finance industry tasks. While that day is not here yet, LLMs are still useful additions to the stock analyst’s toolkit.

So, how can the research-driven fundamental analysts on the one hand, and the ‘techie’ quant analysts on the other, apply LLMs like ChatGPT? How effective a co-pilot or assistant can these technologies be?

Central to these questions is the new dark art of ‘prompt engineering’. To best leverage ChatGPT and other LLMs, equity analysts need to focus on constructing the right prompt. Indeed, prompt engineering has become a critical new discipline. The better the question we ask ChatGPT, the better its answer will be. The system responds best to keywords, phrases, and bullet points, as well as well-ordered follow-up questions.

Assisting the Fundamental Analyst

Fundamental stock analysts generally know their target companies from top to bottom, so ChatGPT may not reveal anything altogether new about their primary bets. However, LLMs can generate overviews of less well-known firms quickly and at scale.

Here are the ChatGPT prompts we would deploy to analyse a hypothetical Company X.

Company Overview

  • “explain the business model of Company X”
  • “conduct a SWOT analysis of Company X” (strengths, weaknesses, opportunities, threats)
  • “list 10 competitors of Company X”
  • “list the 10 main risks to an investment in Company X”

Environmental, Social, and Governance (ESG) Overview

  • “list and describe 10 key Environmental scandals of Company X”
  • “list and describe 10 key Governance scandals of Company X”
  • “list and describe 10 key Social scandals of Company X”
  • “Drill down as appropriate”

We would also add a standard ending to each prompt to increase the chances of an accurate response, such as “list your sources; if you do not know an answer, write ‘do not know.’”

Using ChatGPT for stock analysis on two companies

We ran the above ChatGPT analysis on two real-life companies. One was a mid-capitalisation IT firm in India – Mphasis – that had received light research attention from analysts. The other was Vale, a very well-covered Brazilian mining company. In the real world, multiple LLMs would have been used to give us more control over the responses, greater validation and cross-checking, and much greater scale; but in this test case answers were generated simply by prompting ChatGPT4.

While the results were hardly revelatory for Mphasis, ChatGPT did provide an informative, high-level summary of the Indian firm. In the SWOT analysis it produced on the company, it found that Mphasis had built long-standing relationships with clients, many of whom are Fortune 500 companies. On the other hand, it also identified a key weakness in Mphasis’ over-dependence on the banking, financial services and insurance (BFSI) sector.

Meanwhile, ChatGPT successfully picked up on the ESG issues of Vale, the Brazilian mining firm. A simple prompt for a specific aspect – “social” – yielded accurate results, even though the system cautioned that it could not attribute sources and recommended we cross-reference the response.

To unearth more detail, we needed to delve deeper than ChatGPT allows.

Finally, when it comes to a company presentation of its results, ChatGPT can summarise and interrogate a company’s latest earnings call, news flow, third-party analysis, or whatever data we provide. It is important to remember that if we don’t actively specify and deliver the text for ChatGPT to analyse, it will rely only on its training data – the billions of web pages it has access to on the internet – which increases the risk of misleading fakery or ‘hallucinations’ as they are known.

Another point to keep in mind: official company communications tend to be upbeat and positive. So rather than ask ChatGPT to “summarise” an earnings call, we might request that it “list 10 negatives”, which should yield more revealing answers. We did this with Mphasis and ChatGPT delivered a fast and effective result.

Although they are usually obvious, this sort of list can often reveal important weaknesses that we can probe further.

How ChatGPT can be used by quant analysts

Turning to the technical ‘quant’ side of things, ChatGPT can write simple functions and describe how to produce particular types of code. In fact, GPT codex – a GPT3 component trained on computer programming code – is already a helpful auto-complete coding tool in the AI programmer GitHub Copilot, and GPT4 will be the basis of the forthcoming and more comprehensive GitHub Copilot X.

Nevertheless, unless the function is fairly standard, ChatGPT-generated code nearly always requires tweaks and changes for correct and optimised results, and thus serves best as a template. So at the moment, LLM auto-pilots appear unlikely to replace quant coders anytime soon.

However, a quant might use ChatGPT for the three tasks described below. (Here, again, we are simply prompting ChatGPT. In practice, we would access specific codex LLMs and integrate other tools to create far more reliable code automatically).

1 Develop an entire investment pipeline

ChatGPT can partly execute complex computer programming instructions, such as “write Python functions to drive quant equity investment strategy”.

But again, the resulting code may need considerable editing and finessing. The challenge is getting ChatGPT to deliver code that is as close as possible to the finished article. To do that, it helps to deploy a numbered list of instructions with each item containing important details.

2 Create a machine-learning, alpha-forecasting function

Follow-up requests give us a simple machine-learning function, or template, to forecast stock returns. ChatGPT does a reasonable job here. It provides a function that we can then adjust and offers advice on how to apply it, recommending cross validation with a random forest algorithm.

3 Create a useful function: target shuffling

We next asked ChatGPT to write a helpful and moderately complex function to conduct target shuffling. Target shuffling is a method to help verify an investment model’s outcomes. A simple request to “write Python code for a target shuffling function” does not give us much. Again, we had to input a detailed list outlining what we wanted for ChatGPT to produce a reasonable template.

Why ChatGPT is best at summarising stocks

As an adjunct to a fundamental analyst, ChatGPT functions reasonably well. Although detail is sometimes lacking on less well-covered companies, the stock summaries demonstrate ChatGPT’s speed and precision as an aggregator – when queries require no reasoning, subjectivity, or calculation. For ESG applications, ChatGPT has great potential, but once we identified a controversy, we could only drill down so far as the system only had so much data.

ChatGPT excels at quickly and precisely summarising earnings transcripts and other long-form text about companies, sectors, and products, which should free up time for human analysts to dedicate themselves to other tasks. One of those should be regulatory compliance because, as the situation stands now, raw LLM technology cannot satisfy the duty of care obligations intrinsic to investment management.

Meanwhile, ChatGPT seems to disappoint as a quant co-pilot. But it does add some value. To produce complex pipelines, ChatGPT needs precise prompts that require considerable time and intervention to construct. But with more specific functions, ChatGPT is more reliable and can save time. So overall, ChatGPT’s effectiveness as a programming assistant is largely a function of how well we engineer the prompts.

However, if we step things up and build an application on top of GPT4, with refined prompts, cross-validated results, and structured outputs, we could significantly improve our results across the board.

Future applications of ChatGPT and LLMs for stock analysts

If analysis and investment indeed compose a mosaic, LLMs provide managers who understand the technology with a powerful tile. The examples above have been simply ChatGPT prompts, but developers and managers with class-leading technology are already working to apply LLMs to investment management workflows.

As a result, portfolio managers are increasingly able to sense check investments with LLMs at a portfolio or even asset allocation level based on such criteria as ESG scandals or investment risks. This could ultimately be extended to institutional investing and robo-advisers.

With carefully managed prompts, LLMs can now help fundamental analysts quickly acquire basic knowledge about many companies at once, and help quant analysts to develop and debug code. But apps that write prompts automatically are likely to be available soon and should help achieve more detailed and specific objectives. Indeed, we expect a new tech arms race to develop.

Ultimately higher-tech systematic managers will harness LLMs to automate the research that fundamental analysts would otherwise conduct, though they will use this output as another input into their stock selection and investment models. For this to work, LLMs’ flaws, particularly those related to timeliness and logical or causal reasoning, will have to be addressed.

But even in their current form, well-integrated LLMs can create significant efficiencies if applied in the right way. And they hint at the technology’s vast potential.

In its next generation, LLM technology will become an indispensable investment management tool. By automating information gathering and other tasks, human analysts will have more time and bandwidth to focus on the reasoning and judgement side of the investment process.

This is only the beginning.

 

This is an abridged version of a blog that first appeared in the Enterprising Investor, the forum of the Chartered Financial Analyst (CFA) Institute.

This post is the opinion of the author. As such, it should not be construed as investment advice, nor do the opinions expressed necessarily reflect the views of the CFA Institute or the author’s employer.

Dan Philps is an Honorary Research Fellow in the Gillmore Centre for Financial Technology and Head of Investment Strategies at Rothko Investment Strategies. 

For more articles on Finance and Markets sign up to Core Insights here.