Technology and Innovation Community

 View Only
  • 1.  AI/ML and local LLM in Python for finance

    Posted 6 days ago

    Good evening everyone,

    I had the chance to meet some of you at certain CFA UK events where I noticed a certain interest for Python solutions linked with AI/ML and local LLM applications for company analysis. As a result and at the suggestion of certain members, I wanted to share with the community one of my recent open-source Python project on that topic.

    In parallel of my studies at Audencia BS and Aston University (MSc FinTech), I am developing a Python script aiming to provide a synthetic overview of the main characteristics of a company and its stock from simply its ticker. The main challenge was to work on a way to process financial data using AI locally, without sending any data to servers on the other side of the globe which is often a contractual clause for private funds when processing their clients' confidential information.

    On a side note, one of my motivations for developing this script was the CFA program. I learnt about concepts like skewness, kurtosis and return distributions, but current real-world examples aren't always easy to find online. It helped me gain more confidence when using these notions.

    You can find the full code on GitHub: gruquilla/FinAPy: Single-stock analysis using Python and local machine learning/ AI tools (Ollama, LSTM).


    The project relies on several libraries, but gets its data using yfinance and pygooglenews mainly.
    The script includes at the moment:

    • A basic synthesis about the company: name, location, sector, industry,...
    • A market data analysis, with LSTM machine learning forecast, returns statistics, AI LLM analysis,...
    • A ratio-based analysis, computed from the financial statements of the last 3 years with AI LLM interpretation and PESTEL context.

    The code uses some AI and ML-oriented libraries, but even if you are not used to Python at all, the readme on its own should allow you to understand how the script operates. It can be a good introduction with real-world examples to deploy your own ML/LLM-Python pipeline.



    ------------------------------
    Guillaume (William) RUQUILLA
    MSc Fintech - MiM / Finance
    Audencia BS x Aston University
    ------------------------------


  • 2.  RE: AI/ML and local LLM in Python for finance

    Posted 5 days ago

    Great Project Guillaume. Some ideas:

    • Try sentiment analysis using LLM as well but omitting ticker information and/or company information to minimize forward-looking bias risk.
    • Use standardized financial information from a data vendor API to tackle the formatting issues you mention.
    • Ollama AI commentary can be enhanced by adding context e.g. provide news sentiment analysis to Ollama so that it does not only work with financial ratio data.

    In any case, it's a great tool. Congrats and thanks for sharing



    ------------------------------
    Carlos Salas
    Portfolio Manager & Freelance Investment Research Consultant
    ------------------------------



  • 3.  RE: AI/ML and local LLM in Python for finance

    Posted 5 days ago

    Thank you very much for your feedback ! That's very valuable insights, I'm still working on improving the project so that's very helpful for the next steps.

    Here are the main aspects I'm thinking about related to the points you mentioned:

    • -        Concerning sentiment analysis, I'm torn between two alternative approaches to improve the current one.

      The current approach (FinBERT ran on the headlines) is relatively light, often accurate but far from ideal as it does not take into account any context. For instance, if the headline is "Stock X at its best while stock Y plunges", I get a neutral score regardless of the stock the script is working on.

      The first approach is, as you suggested, to use a LLM. Given the process, I don't think a local run is necessary so using a third-party API seems more appropriate. The main downside I see is consistency. If I do an API call for each headline, I will have a lot of API calls to make and an inconsistent sentiment analysis scale. If I submit all the headlines in a single dataframe I send with a prompt to the LLM, there is a risk the LLM output format is not as requested and causes unnecessary errors. I feel like the last approach can be more efficient as it simplifies the API call routine and LLMs are getting more robust at handling predetermined output formats, but I'd be glad to have your insights on the matter.

      The second approach is to have a more "traditional" NLP approach. I'm thinking about chunking the headlines in context of each company/ ticker mentioned and then running FinBERT on the one that concerns us. The issue is I fear it might require a lot of testing and accuracy might not be the best.

    • -        Concerning the information source, you're definitely right. Yahoo Finance is for non commercial purposes only, it's definitely suitable for a university project but not for any professional pipeline. I was thinking about creating a "dictionary" of the different terms for each item in the statements so in the absence of the default terms in fetches another one available. The upside of this approach is anyone can then modify the dictionary with the terms used by their own provider and hence adapt the pipeline to their own API provider.

    • -        In terms of context for the Ollama analysis, that would definitively be an improvement. As you probably noticed, the sentiment analysis approach is still in work in progress but that's definitely something to be done.

    Thanks again!



    ------------------------------
    Guillaume (William) RUQUILLA
    MSc Fintech - MiM / Finance
    Audencia BS x Aston University
    ------------------------------



  • 4.  RE: AI/ML and local LLM in Python for finance

    Posted 5 days ago
    Interesting work, thanks Guillaume for sharing!