GithubHelp home page GithubHelp logo

ai4finance-foundation / fingpt Goto Github PK

View Code? Open in Web Editor NEW
12.7K 243.0 1.8K 11.71 MB

FinGPT: Open-Source Financial Large Language Models! Revolutionize 🔥 We release the trained model on HuggingFace.

Home Page: https://ai4finance.org

License: MIT License

Python 13.15% Jupyter Notebook 86.10% Shell 0.72% TypeScript 0.03%
chatgpt finance fintech large-language-models machine-learning nlp prompt-engineering pytorch reinforcement-learning robo-advisor sentiment-analysis technical-analysis fingpt

fingpt's Introduction

image

FinGPT: Open-Source Financial Large Language Models

Downloads Downloads Python 3.8 PyPI License

Let us not expect Wall Street to open-source LLMs or open APIs, due to FinTech institutes' internal regulations and policies.

Blueprint of FinGPT

https://huggingface.co/FinGPT

Visitors

What's New:

Why FinGPT?

1). Finance is highly dynamic. BloombergGPT trained an LLM using a mixture of finance data and general-purpose data, which took about 53 days, at a cost of around $3M). It is costly to retrain an LLM model like BloombergGPT every month or every week, thus lightweight adaptation is highly favorable. FinGPT can be fine-tuned swiftly to incorporate new data (the cost falls significantly, less than $300 per fine-tuning).

2). Democratizing Internet-scale financial data is critical, say allowing timely updates of the model (monthly or weekly updates) using an automatic data curation pipeline. BloombergGPT has privileged data access and APIs, while FinGPT presents a more accessible alternative. It prioritizes lightweight adaptation, leveraging the best available open-source LLMs.

3). The key technology is "RLHF (Reinforcement learning from human feedback)", which is missing in BloombergGPT. RLHF enables an LLM model to learn individual preferences (risk-aversion level, investing habits, personalized robo-advisor, etc.), which is the "secret" ingredient of ChatGPT and GPT4.

Milestone of AI Robo-Advisor: FinGPT-Forecaster

Try the latest released FinGPT-Forecaster demo at our HuggingFace Space

demo_interface

Enter the following inputs:

  1. ticker symbol (e.g. AAPL, MSFT, NVDA)
  2. the day from which you want the prediction to happen (yyyy-mm-dd)
  3. the number of past weeks where market news are retrieved
  4. whether to add the latest basic financials as additional information

Click Submit! And you'll be responded with a well-rounded analysis of the company and a prediction for next week's stock price movement!

For detailed and more customized implementation, please refer to FinGPT-Forecaster

FinGPT Demos:

Current State-of-the-arts for Financial Sentiment Analysis

  • FinGPT V3 (Updated on 10/12/2023)

    • What's new: Best trainable and inferable FinGPT for sentiment analysis on a single RTX 3090, which is even better than GPT-4 and ChatGPT Finetuning.

    • FinGPT v3 series are LLMs finetuned with the LoRA method on the News and Tweets sentiment analysis dataset which achieve the best scores on most of the financial sentiment analysis datasets with low cost.

    • FinGPT v3.3 use llama2-13b as base model; FinGPT v3.2 uses llama2-7b as base model; FinGPT v3.1 uses chatglm2-6B as base model.

    • Benchmark Results:

    • Weighted F1 FPB FiQA-SA TFNS NWGI Devices Time Cost
      FinGPT v3.3 0.882 0.874 0.903 0.643 1 × RTX 3090 17.25 hours $17.25
      FinGPT v3.2 0.850 0.860 0.894 0.636 1 × A100 5.5 hours $ 22.55
      FinGPT v3.1 0.855 0.850 0.875 0.642 1 × A100 5.5 hours $ 22.55
      FinGPT (8bit) 0.855 0.847 0.879 0.632 1 × RTX 3090 6.47 hours $ 6.47
      FinGPT (QLoRA) 0.777 0.752 0.828 0.583 1 × RTX 3090 4.15 hours $ 4.15
      OpenAI Fine-tune 0.878 0.887 0.883 - - - -
      GPT-4 0.833 0.630 0.808 - - - -
      FinBERT 0.880 0.596 0.733 0.538 4 × NVIDIA K80 GPU - -
      Llama2-7B 0.390 0.800 0.296 0.503 2048 × A100 21 days $ 4.23 million
      BloombergGPT 0.511 0.751 - - 512 × A100 53 days $ 2.67 million

      Cost per GPU hour. For A100 GPUs, the AWS p4d.24xlarge instance, equipped with 8 A100 GPUs is used as a benchmark to estimate the costs. Note that BloombergGPT also used p4d.24xlarge As of July 11, 2023, the hourly rate for this instance stands at $32.773. Consequently, the estimated cost per GPU hour comes to $32.77 divided by 8, resulting in approximately $4.10. With this value as the reference unit price (1 GPU hour). BloombergGPT estimated cost= 512 x 53 x 24 = 651,264 GPU hours x $4.10 = $2,670,182.40. For RTX 3090, we assume its cost per hour is approximately $1.0, which is actually much higher than available GPUs from platforms like vast.ai.

    • Reproduce the results by running benchmarks, and the detailed tutorial is on the way.

    • Finetune your own FinGPT v3 model with the LoRA method on only an RTX 3090 with this notebook in 8bit or this notebook in int4 (QLoRA)

  • FinGPT V1

    • FinGPT by finetuning ChatGLM2 / Llama2 with LoRA with the market-labeled data for the Chinese Market

Instruction Tuning Datasets and Models

The datasets we used, and the multi-task financial LLM models are available at https://huggingface.co/FinGPT

Our Code

Datasets Train Rows Test Rows Description
fingpt-sentiment-train 76.8K N/A Sentiment Analysis Training Instructions
fingpt-finred 27.6k 5.11k Financial Relation Extraction Instructions
fingpt-headline 82.2k 20.5k Financial Headline Analysis Instructions
fingpt-ner 511 98 Financial Named-Entity Recognition Instructions
fingpt-fiqa_qa 17.1k N/A Financial Q&A Instructions
fingpt-fineval 1.06k 265 Chinese Multiple-Choice Questions Instructions

Multi-task financial LLMs Models:

  demo_tasks = [
      'Financial Sentiment Analysis',
      'Financial Relation Extraction',
      'Financial Headline Classification',
      'Financial Named Entity Recognition',]
  demo_inputs = [
      "Glaxo's ViiV Healthcare Signs China Manufacturing Deal With Desano",
      "Apple Inc. Chief Executive Steve Jobs sought to soothe investor concerns about his health on Monday, saying his weight loss was caused by a hormone imbalance that is relatively simple to treat.",
      'gold trades in red in early trade; eyes near-term range at rs 28,300-28,600',
      'This LOAN AND SECURITY AGREEMENT dated January 27 , 1999 , between SILICON VALLEY BANK (" Bank "), a California - chartered bank with its principal place of business at 3003 Tasman Drive , Santa Clara , California 95054 with a loan production office located at 40 William St ., Ste .',]
  demo_instructions = [
      'What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}.',
      'Given phrases that describe the relationship between two words/phrases as options, extract the word/phrase pair and the corresponding lexical relationship between them from the input text. The output format should be "relation1: word1, word2; relation2: word3, word4". Options: product/material produced, manufacturer, distributed by, industry, position held, original broadcaster, owned by, founded by, distribution format, headquarters location, stock exchange, currency, parent organization, chief executive officer, director/manager, owner of, operator, member of, employer, chairperson, platform, subsidiary, legal form, publisher, developer, brand, business division, location of formation, creator.',
      'Does the news headline talk about price going up? Please choose an answer from {Yes/No}.',
      'Please extract entities and their types from the input sentence, entity types should be chosen from {person/organization/location}.',]
Models Description Function
fingpt-mt_llama2-7b_lora Fine-tuned Llama2-7b model with LoRA Multi-Task
fingpt-mt_falcon-7b_lora Fine-tuned falcon-7b model with LoRA Multi-Task
fingpt-mt_bloom-7b1_lora Fine-tuned bloom-7b1 model with LoRA Multi-Task
fingpt-mt_mpt-7b_lora Fine-tuned mpt-7b model with LoRA Multi-Task
fingpt-mt_chatglm2-6b_lora Fine-tuned chatglm-6b model with LoRA Multi-Task
fingpt-mt_qwen-7b_lora Fine-tuned qwen-7b model with LoRA Multi-Task
fingpt-sentiment_llama2-13b_lora Fine-tuned llama2-13b model with LoRA Single-Task
fingpt-forecaster_dow30_llama2-7b_lora Fine-tuned llama2-7b model with LoRA Single-Task

Tutorials

[Training] Beginner’s Guide to FinGPT: Training with LoRA and ChatGLM2–6B One Notebook, $10 GPU

Understanding FinGPT: An Educational Blog Series

FinGPT Ecosystem

FinGPT embraces a full-stack framework for FinLLMs with five layers:

  1. Data source layer: This layer assures comprehensive market coverage, addressing the temporal sensitivity of financial data through real-time information capture.
  2. Data engineering layer: Primed for real-time NLP data processing, this layer tackles the inherent challenges of high temporal sensitivity and low signal-to-noise ratio in financial data.
  3. LLMs layer: Focusing on a range of fine-tuning methodologies such as LoRA, this layer mitigates the highly dynamic nature of financial data, ensuring the model’s relevance and accuracy.
  4. Task layer: This layer is responsible for executing fundamental tasks. These tasks serve as the benchmarks for performance evaluations and cross-comparisons in the realm of FinLLMs
  5. Application layer: Showcasing practical applications and demos, this layer highlights the potential capability of FinGPT in the financial sector.
  • FinGPT Framework: Open-Source Financial Large Language Models
  • FinGPT-RAG: We present a retrieval-augmented large language model framework specifically designed for financial sentiment analysis, optimizing information depth and context through external knowledge retrieval, thereby ensuring nuanced predictions.
  • FinGPT-FinNLP: FinNLP provides a playground for all people interested in LLMs and NLP in Finance. Here we provide full pipelines for LLM training and finetuning in the field of finance. The full architecture is shown in the following picture. Detail codes and introductions can be found here. Or you may refer to the wiki
  • FinGPT-Benchmark: We introduce a novel Instruction Tuning paradigm optimized for open-source Large Language Models (LLMs) in finance, enhancing their adaptability to diverse financial datasets while also facilitating cost-effective, systematic benchmarking from task-specific, multi-task, and zero-shot instruction tuning tasks.

Open-Source Base Model used in the LLMs layer of FinGPT

  • Feel free to contribute more open-source base models tailored for various language-specific financial markets.
Base Model Pretraining Tokens Context Length Model Advantages Model Size Experiment Results Applications
Llama-2 2 Trillion 4096 Llama-2 excels on English-based market data llama-2-7b and Llama-2-13b llama-2 consistently shows superior fine-tuning results Financial Sentiment Analysis, Robo-Advisor
Falcon 1,500B 2048 Maintains high-quality results while being more resource-efficient falcon-7b Good for English market data Financial Sentiment Analysis
MPT 1T 2048 MPT models can be trained with high throughput efficiency and stable convergence mpt-7b Good for English market data Financial Sentiment Analysis
Bloom 366B 2048 World’s largest open multilingual language model bloom-7b1 Good for English market data Financial Sentiment Analysis
ChatGLM2 1.4T 32K Exceptional capability for Chinese language expression chatglm2-6b Shows prowess for Chinese market data Financial Sentiment Analysis, Financial Report Summary
Qwen 2.2T 8k Fast response and high accuracy qwen-7b Effective for Chinese market data Financial Sentiment Analysis
InternLM 1.8T 8k Can flexibly and independently construct workflows internlm-7b Effective for Chinese market data Financial Sentiment Analysis
  • Benchmark Results for the above open-source Base Models in the financial sentiment analysis task using the same instruction template for SFT (LoRA):
    Weighted F1/Acc Llama2 Falcon MPT Bloom ChatGLM2 Qwen InternLM
    FPB 0.863/0.863 0.846/0.849 0.872/0.872 0.810/0.810 0.850/0.849 0.854/0.854 0.709/0.714
    FiQA-SA 0.871/0.855 0.840/0.811 0.863/0.844 0.771/0.753 0.864/0.862 0.867/0.851 0.679/0.687
    TFNS 0.896/0.895 0.893/0.893 0.907/0.907 0.840/0.840 0.859/0.858 0.883/0.882 0.729/0.731
    NWGI 0.649/0.651 0.636/0.638 0.640/0.641 0.573/0.574 0.619/0.629 0.638/0.643 0.498/0.503

All Thanks To Our Contributors :

News

ChatGPT at AI4Finance

Introductory

The Journey of Open AI GPT models. GPT models explained. Open AI's GPT-1, GPT-2, GPT-3.

(Financial) Big Data

Interesting Demos

  • GPT-3 Creative Fiction Creative writing by OpenAI’s GPT-3 model, demonstrating poetry, dialogue, puns, literary parodies, and storytelling. Plus advice on effective GPT-3 prompt programming & avoiding common errors.

ChatGPT for FinTech

ChatGPT Trading Bot

Citing FinGPT

@article{yang2023fingpt,
  title={FinGPT: Open-Source Financial Large Language Models},
  author={Yang, Hongyang and Liu, Xiao-Yang and Wang, Christina Dan},
  journal={FinLLM Symposium at IJCAI 2023},
  year={2023}
}
@article{zhang2023instructfingpt,
      title={Instruct-FinGPT: Financial Sentiment Analysis by Instruction Tuning of General-Purpose Large Language Models}, 
      author={Boyu Zhang and Hongyang Yang and Xiao-Yang Liu},
      journal={FinLLM Symposium at IJCAI 2023},
      year={2023}
}
@article{zhang2023fingptrag,
  title={Enhancing Financial Sentiment Analysis via Retrieval Augmented Large Language Models},
  author={Zhang, Boyu and Yang, Hongyang and Zhou, tianyu and Babar, Ali and Liu, Xiao-Yang},
 journal = {ACM International Conference on AI in Finance (ICAIF)},
  year={2023}
}

@article{wang2023fingptbenchmark,
  title={FinGPT: Instruction Tuning Benchmark for Open-Source Large Language Models in Financial Datasets},
  author={Wang, Neng and Yang, Hongyang and Wang, Christina Dan},
  journal={NeurIPS Workshop on Instruction Tuning and Instruction Following},
  year={2023}
}
@article{2023finnlp,
  title={Data-centric FinGPT: Democratizing Internet-scale Data for Financial Large Language Models},
  author={Liu, Xiao-Yang and Wang, Guoxuan and Yang, Hongyang and Zha, Daochen},
  journal={NeurIPS Workshop on Instruction Tuning and Instruction Following},
  year={2023}
}

LICENSE

MIT License

Disclaimer: We are sharing codes for academic purposes under the MIT education license. Nothing herein is financial advice, and NOT a recommendation to trade real money. Please use common sense and always first consult a professional before trading or investing.

fingpt's People

Contributors

0armaan025 avatar amayuelas avatar asmcos avatar bhadreshpsavani avatar bhargavshirin avatar boyuzh avatar bruceyanghy avatar eleniverteouri avatar eltociear avatar gasonbai avatar guichardvictor avatar gxxu-ml avatar kalyanimhala avatar kris248 avatar llk010502 avatar mmmarchetti avatar noir97 avatar oliverwang15 avatar pitmonticone avatar pschofield2 avatar radientbrain avatar raphaelzhou1 avatar shahupdates avatar shivam250702 avatar theredstoneradiant avatar williamgazeley avatar xjtlumedia avatar yangletliu avatar yonv1943 avatar zhumingpassional avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fingpt's Issues

FinGPT-v1 finetune.py. ValueError: You can't train a model that has been loaded in 8-bit precision on a different device than the one you're training on.

When running FinGPT-v1/training/finetune.py, there is an error:

You are adding a <class 'transformers.integrations.TensorBoardCallback'> to the callbacks of this Trainer, but there is already one. The currentlist of callbacks is
:DefaultFlowCallback
TensorBoardCallback
/data/kexin/anaconda3/envs/fingpt/lib/python3.8/site-packages/transformers/optimization.py:411: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set 'no_deprecation_warning=True' to disable this warning
 warnings.warn(
Traceback (most recent call last):
 File "/data/kexin/project/FinGPT/fingpt/FinGPT-v1/training/finetune.py", line 144, in <module>
   main()
 File "/data/kexin/project/FinGPT/fingpt/FinGPT-v1/training/finetune.py", line 137, in main
   trainer.train()
 File "/data/kexin/anaconda3/envs/fingpt/lib/python3.8/site-packages/transformers/trainer.py", line 1645, in train
   return inner_training_loop(
 File "/data/kexin/anaconda3/envs/fingpt/lib/python3.8/site-packages/transformers/trainer.py", line 1756, in _inner_training_loop
   model, self.optimizer = self.accelerator.prepare(self.model, self.optimizer)
 File "/data/kexin/anaconda3/envs/fingpt/lib/python3.8/site-packages/accelerate/accelerator.py", line 1182, in prepare
   result = tuple(
 File "/data/kexin/anaconda3/envs/fingpt/lib/python3.8/site-packages/accelerate/accelerator.py", line 1183, in <genexpr>
   self._prepare_one(obj, first_pass=True, device_placement=d) for obj, d in zip(args, device_placement)
 File "/data/kexin/anaconda3/envs/fingpt/lib/python3.8/site-packages/accelerate/accelerator.py", line 1022, in _prepare_one
   return self.prepare_model(obj, device_placement=device_placement)
 File "/data/kexin/anaconda3/envs/fingpt/lib/python3.8/site-packages/accelerate/accelerator.py", line 1258, in prepare_model
   raise ValueError(
ValueError: You can't train a model that has been loaded in 8-bit precision on a different device than the one you're training on. Make sure you loaded the model on the correct device using for example 'device_map={'':torch.cuda.current_device()}you're training on. Make sure you loaded the model on the correct device using for example 'device_map={'':torch.cuda.current_device() or device_map={'':torch.xpu.current_device()}
Process finished with exit code 1

It seems like it's caused by loading in 8-bit. What should I do to fix it? Thanks for your help

报错信息如下,请指教。

Mac系统,CPU i7 内存16G, 下载了001-007的文件;运行报错:
/Users/kongfanyu/Downloads/MyFinGPT/venv/bin/python /Users/kongfanyu/Downloads/MyFinGPT/fingpt/FinGPT-v3/test.py
Traceback (most recent call last):
File "/Users/kongfanyu/Downloads/MyFinGPT/fingpt/FinGPT-v3/test.py", line 13, in
model = AutoModel.from_pretrained(base_model, trust_remote_code=True, device_map="auto")
File "/Users/kongfanyu/Downloads/MyFinGPT/venv/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 558, in from_pretrained
return model_class.from_pretrained(
File "/Users/kongfanyu/Downloads/MyFinGPT/venv/lib/python3.10/site-packages/transformers/modeling_utils.py", line 3175, in from_pretrained
) = cls._load_pretrained_model(
File "/Users/kongfanyu/Downloads/MyFinGPT/venv/lib/python3.10/site-packages/transformers/modeling_utils.py", line 3296, in _load_pretrained_model
raise ValueError(
ValueError: The current device_map had weights offloaded to the disk. Please provide an offload_folder for them. Alternatively, make sure you have safetensors installed if the model you are using offers the weights in this format.

进程已结束,退出代码1

FinGPT-v1 , errors with download_titles.py

I don't understand what does al_re mean ?

# ATTENTION! Should replace this with your results path!
al_re = os.listdir(r"D:\python_project\FinRL-Meta\experiment\scrape\results")
al_re = [al.split(".")[0] for al in al_re]

执行finetune.sh 之后,效果不理想

目前我爬取了5只股票(东方财富的资讯),大约有4w条数据,执行finetune.sh 日志如下图
image
执行脚本参数
python -u finetune.py
--dataset_path "/data/program/data/dataset6/jsonl/dataset_title_train_and_valid"
--lora_rank 8
--per_device_train_batch_size 16
--per_device_eval_batch_size 16
--gradient_accumulation_steps 1
--num_train_epochs 1
--save_steps 100
--save_total_limit 5
--learning_rate 1e-6
--fp16
--remove_unused_columns false
--logging_steps 10
--eval_steps 100
--load_best_model_at_end true
--evaluation_strategy "steps"
--output_dir "/data/program/data/dataset6/model" > train.log 2>&1

然后运行infer 通过测试数据做了对比
image

通过这些指标看效果不好,是参数样本数据少还是样本数据有问题?

Open AI key present in the code.

In the source fingpt/chatgpt-trading-v2/openai_token/token_.py the Openai secret key is present. Request to remove and disable token.

How to run fingpt on replit?

Hi everyone,

I wanted to ask how can i run fingpt on replit or locally is there any tutorial available?

Thanks

FinGPT-v1, only 1 type of instruction used in tuning?

In FinGPT-v1, there is only 1 type of instruction being used as model input during fine-tuning:
"instruction": "What is the sentiment of this news? Answer:{very negative/negative/neutral/positive/very positive} \n input": "今天的日期为:2023-06-12。\n新闻标题为:\"南山铝业本周融资净偿还862.5万元,居有色金属板块第九\"。

Did you only use this type of instruction? Or you designed other instructions for different tasks and used them for tuning? If you used other instructions, may I ask if they can be made public? Thank you.

这个组织中这么多库 Fin-Meta, Fin-NLP, FinRL, Prodracer, FinGPT 对于新手来说应该如何选择?

感谢团队的分享, 我也看了很多关于AI4Finance的资料,作为一个新手小白,我想入门金融的强化学习,但是被这么多的库砸晕了。

他们都是什么关系,是版本更新,还是并且共存,是否有先后顺序,都处于更新中吗?有更新的优先级吗?
作为一个新手程序员,有些python和pytorch的基础,应该从哪个库入手。
Fin-Meta好像是数据层的, 那么在Fin-RL 和Fin-GPT中的数据层是否还是用Fin-Meta来做的? 还是每一个库都是独立的?

这些库中,哪个是最新的能学习如何应用强化学习的?

希望能有一篇内容介绍这些库的关系,已经在当下的时间点,学习哪个库才是最合适的选择。谢谢

Trying to replicate the work

Hi Authors,

Thanks to open-source this great work.

I am wondering:

  1. if the FinGPT refered in the finGPT paper V1 or V2? I guess it is V2 but under v2 I only found a simple script for downloading some data.
  2. it seems that I didn't see the "stock return RL" step on the script. And there is no evaluation metric shown in the paper. Is there any quantitative evidence shows Stock return RL improve performance on some tasks?
  3. It seems there is no instruction on README showing how to replicate the work from 0 to 1 that is demonstrated on the FinGPT website demo

Could you please provide some information about these?

Thanks,

希望取得联系

尊敬的FinGPT 应用开发者,我是 InternLM 社区开发者&志愿者尖米, 大佬开源的工作对我的启发很大,希望可以探讨使用 InternLM 实现FinGPT 的可能性和实现路径,我的微信是mzm312,希望可以取得联系进行更深度的交流。

Please remove the youtube videos from the readme

They are completely useless videos made from youtubers and would made a quant laugh.
First of all they start by applying the "super easily AI made trading system" to an already rockstar instrument (ie Bitcoin, AAPL, TSLA, whatever), and they intentionally leave the "Buy and Hold" stats out.
If they'd included it you'd see that you wouldn't need ANY system AT ALL to make insane returns with those instruments if you bought them at the beginning.. so they're cheating from the start.

Plus you cannot use Tradingview (IN SAMPLE DATA) to backtest/create a proper trading system.
Proper/robust trading systems need to be build with a "Walk Forward" approach using OUT OF SAMPLE data, carefully crafted so that it cannot peak into the future. You'd need specialized software for that.

http://www.codefortraders.com/Walk-Forward_Analysis/WFA_Introduction.htm

Could AI help here? Definitely. But not like this.

Too many attempt to download; and 'other_code_list' is not defined

Hello,

When trying to download the data for US model, there seem many attempt threads been started, while most of them are interrupted, guessing this is a issue from the website?

Also, after the first download is completed, it will run "for stock in tqdm(other_code_list):", but "other_code_list" seems not defined.

Any suggestion, thanks.
alex

How to make dataset_title_test.json file?

I try FinGPT-v1/data_preparations.
I have use add_labels.py make results_with_content/*.csv

How to make dataset_title_test.json?

I find example: instructions = json.load(open("/root/FinGPT-ChatGLM-Fineturning/data/title/dataset_title_test.json"))
The file is alpaca format ?

Training Killed

Attempted to run default FinGPT\fingpt\FinGPT-v3\benchmark\benchmarks.ipynb. The only change was commenting v3.1.

# v3.1
#base_model = "THUDM/chatglm2-6b"
#peft_model = "oliverwang15/FinGPT_v31_ChatGLM2_Sentiment_Instruction_LoRA_FT"
#tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
#model = AutoModel.from_pretrained(base_model, trust_remote_code=True, load_in_8bit = False, device_map = "auto")
#model = PeftModel.from_pretrained(model, peft_model)
#model = model.eval()

Processes was killed with no results.

image

Reinforcement Learning on Stock Prices

Thank you for your works.
How to fine-tune with Reinforcement Learning on Stock Prices?.
Can you provide the source code for training with RLSP?
Thanks

Fin GPT For indian stock market

Hi ,Thanks for the wonderful work and the report creation towards democrizing fin GPT, any plans to include FIN GPT for Indian stock market, it's quite a huge market with various test case possibilities

on_filled

why it doesn't have the same signature as on_execution

For training quantitative trading, you only need to train transaction data.

作为经常和成熟能够稳定盈利交易者打交道的从业人员,程序是能够从市场成交数据上看出市场的情绪。因为市场的消息是滞后,且大多数是不真实的,所以直接用成交数据来训练模型才是出路。就像是扑克游戏一样,只根据对手每个回合下注比例和行为,就足够判断对方情绪和牌力了。

As a practitioner who regularly deals with mature, stable and profitable traders, the program is able to read market sentiment from market turnover data. Because market information is lagging and mostly untrue, training models directly on trading data is the way to go. Just like a poker game, it is enough to judge the opponent's mood and card power based on the proportion of bets and behavior of the opponent each turn.

我对国内交易市场的渠道是熟悉的,或许我们能够沟通出好的思路。训练交易或许并不需要爬取太多是市场资讯,这会让我们走更多的弯路。如果有需要我帮助介绍国内期货交易市场,和相关交易数据获取的问题,可以找我。

I am familiar with the channels of the domestic trading market, maybe we can communicate a good idea.

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)

在运行 python3 shares_news_sentiment_classify.py 时报下面错误, 你们是否遇到过?

File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1458, in connect
self.sock = self._context.wrap_socket(self.sock,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 517, in wrap_socket
return self.sslsocket_class._create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1108, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1379, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)

How to install the this on my Mac ?

Hello Team ,

came across this REPO and wanted to explore more but i wanted to know the installation steps to try this out on my mac.

can anyone please help me with the steps for the same?

Thanks in advance :)

It did not work when I try to convert the default model "chatglm2" to "llama2"

Thanks for your awesome project. I reproduced the FinGPT v3.1.2 (4-bit QLoRA). It does work with the default LLM model "chatglm2" on Colab, but it comes to a halt when I wanna get better results with Llama2.

  • I have changed the model as per your instructions, modifying model_name = "THUDM/chatglm2-6b" to model_name = "daryl149/llama-2-7b-chat-hf"

  • Then removed the device due to running error:

model = AutoModel.from_pretrained(
        model_name,
        quantization_config=q_config,
        trust_remote_code=True,
        token = access_token,
        # device='cuda'
    )
  • Changed the target_modules to llama:
    target_modules = TRANSFORMERS_MODELS_TO_LORA_TARGET_MODULES_MAPPING['llama']

  • Unfortunately, the final step got a TypeError: 'NoneType' object cannot be interpreted as an integer

writer = SummaryWriter()
trainer = ModifiedTrainer(
    model=model,
    args=training_args,             # Trainer args
    train_dataset=dataset["train"], # Training set
    eval_dataset=dataset["test"],   # Testing set
    data_collator=data_collator,    # Data Collator
    callbacks=[TensorBoardCallback(writer)],
)
trainer.train()
writer.close()
# save model
model.save_pretrained(training_args.output_dir)

The detail error as follows:

You are adding a <class 'transformers.integrations.TensorBoardCallback'> to the callbacks of this Trainer, but there is already one. The currentlist of callbacks is
:DefaultFlowCallback
TensorBoardCallback
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-d05cf508c134> in <cell line: 11>()
      9     callbacks=[TensorBoardCallback(writer)],
     10 )
---> 11 trainer.train()
     12 writer.close()
     13 # save model

6 frames
<ipython-input-25-26476d7038e4> in data_collator(features)
     37         ids = ids + [tokenizer.pad_token_id] * (longest - ids_l)
     38         _ids = torch.LongTensor(ids)
---> 39         labels_list.append(torch.LongTensor(labels))
     40         input_ids.append(_ids)
     41     input_ids = torch.stack(input_ids)

TypeError: 'NoneType' object cannot be interpreted as an integer

Could you please do me a favor resolving this issue? Looking forward to your reply!
(Platform: A100 on Google Colab)

Datasets used in the fine-tuning process

I've noticed that while creating the dataset, the news headlines and news content were separated. This means that there are distinct training and testing sets for news headlines, as well as for news content. However, during the fine-tuning process, only the dataset containing news headlines was utilized, and the dataset with news content wasn't employed. Consequently, I'm somewhat perplexed about the role of the news content dataset in the fine-tuning process.
image
image

dataset分享

有人可以分享一下从东方财富中下载的数据么?我运行download_contents已经一天了,程序仍然在运行,但是无任何输出结果。

Setup Configuration Improvements in FinGPT

There are a few improvements that can enhance its readability and maintainability. Here are the details:

Error Handling for Missing Requirements File:
The code attempts to read the requirements.txt file to gather the project's dependencies. However, if the file is not found, the code simply prints an error message to the console. It would be better to raise an exception or exit the setup process with an appropriate error message to inform the user of the missing file.

Use of "with" Statement for File Handling:
The code currently uses a try-except block to handle file operations without utilizing the recommended with statement. Using with ensures proper handling of file resources, including automatic closing, even if an exception occurs.

Consistent Quoting Style:
The code uses both single and double quotes for string literals. It is recommended to use a consistent quoting style throughout the codebase to improve readability. Choose either single quotes or double quotes and apply it consistently.

To improve the code, consider the following suggestions:

from setuptools import setup, find_packages

# Read requirements.txt, ignore comments
try:
    with open("requirements.txt", "r") as f:
        REQUIRES = [line.split('#', 1)[0].strip() for line in f if line.strip()]
except FileNotFoundError:
    raise FileNotFoundError("requirements.txt not found!")

setup(
    name="FinGPT",
    version="0.0.0",
    include_package_data=True,
    author="Hongyang Yang, Xiao-Yang Liu",
    author_email="[email protected]",
    url="https://github.com/AI4Finance-Foundation/FinGPT",
    license="MIT",
    packages=find_packages(),
    install_requires=REQUIRES,
    description="FinGPT",
    long_description="FinGPT",
    classifiers=[
        # Trove classifiers
        # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: Implementation :: CPython",
        "Programming Language :: Python :: Implementation :: PyPy",
    ],
    keywords="Financial Large Language Models",
    platforms=["any"],
    python_requires=">=3.6",
)

when I run finetune.sh shell,RuntimeError: Only Tensors of floating point and complex dtype can require gradients

===================================BUG REPORT===================================
Welcome to bitsandbytes. For bug reports, please submit your error trace to: https://github.com/TimDettmers/bitsandbytes/issues

CUDA_SETUP: WARNING! libcudart.so not found in any environmental path. Searching /usr/local/cuda/lib64...
/home/ubuntu/.local/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:136: UserWarning: WARNING: The following directories listed in your path were found to be non-existent: {PosixPath('/usr/local/cuda/
lib64')}
warn(msg)
/home/ubuntu/.local/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:136: UserWarning: WARNING: No libcudart.so found! Install CUDA or the cudatoolkit package (anaconda)!
warn(msg)
CUDA SETUP: Highest compute capability among GPUs detected: 7.0
CUDA SETUP: Detected CUDA version 117
/home/ubuntu/.local/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:136: UserWarning: WARNING: Compute capability < 7.5 detected! Only slow 8-bit matmul is supported for your GPU!
warn(msg)
CUDA SETUP: Loading binary /home/ubuntu/.local/lib/python3.8/site-packages/bitsandbytes/libbitsandbytes_cpu.so...
/home/ubuntu/.local/lib/python3.8/site-packages/bitsandbytes/cextension.py:31: UserWarning: The installed version of bitsandbytes was compiled without GPU support. 8-bit optimizers and GPU quantization are unavai
lable.
warn("The installed version of bitsandbytes was compiled without GPU support. "
No compiled kernel found.
Compiling kernels : /home/ubuntu/.cache/huggingface/modules/transformers_modules/chatglm-6b-int8/quantization_kernels_parallel.c
Compiling gcc -O3 -fPIC -pthread -fopenmp -std=c99 /home/ubuntu/.cache/huggingface/modules/transformers_modules/chatglm-6b-int8/quantization_kernels_parallel.c -shared -o /home/ubuntu/.cache/huggingface/modules/t
ransformers_modules/chatglm-6b-int8/quantization_kernels_parallel.so
Load kernel : /home/ubuntu/.cache/huggingface/modules/transformers_modules/chatglm-6b-int8/quantization_kernels_parallel.so
Setting CPU quantization kernel threads to 5
Using quantization cache
Applying quantization to glm layers
Traceback (most recent call last):
File "finetune.py", line 137, in
main()
File "finetune.py", line 90, in main
model = AutoModel.from_pretrained(
File "/home/ubuntu/.local/lib/python3.8/site-packages/transformers/models/auto/auto_factory.py", line 479, in from_pretrained
return model_class.from_pretrained(
File "/home/ubuntu/.local/lib/python3.8/site-packages/transformers/modeling_utils.py", line 2675, in from_pretrained
model = cls(config, *model_args, **model_kwargs)
File "/home/ubuntu/.cache/huggingface/modules/transformers_modules/chatglm-6b-int8/modeling_chatglm.py", line 1061, in init
self.quantize(self.config.quantization_bit, self.config.quantization_embeddings, use_quantization_cache=True, empty_init=True)
File "/home/ubuntu/.cache/huggingface/modules/transformers_modules/chatglm-6b-int8/modeling_chatglm.py", line 1439, in quantize
self.transformer = quantize(self.transformer, bits, use_quantization_cache=use_quantization_cache, empty_init=empty_init, **kwargs)
File "/home/ubuntu/.cache/huggingface/modules/transformers_modules/chatglm-6b-int8/quantization.py", line 501, in quantize
layer.attention.query_key_value = QuantizedLinearWithPara(
File "/home/ubuntu/.cache/huggingface/modules/transformers_modules/chatglm-6b-int8/quantization.py", line 374, in init
self.weight = Parameter(self.weight.to(kwargs["device"]), requires_grad=False)
File "/home/ubuntu/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1632, in setattr
self.register_parameter(name, value)
File "/home/ubuntu/.local/lib/python3.8/site-packages/accelerate/big_modeling.py", line 108, in register_empty_parameter
module._parameters[name] = param_cls(module._parameters[name].to(device), **kwargs)
File "/home/ubuntu/.local/lib/python3.8/site-packages/torch/nn/parameter.py", line 36, in new
return torch.Tensor._make_subclass(cls, data, requires_grad)
RuntimeError: Only Tensors of floating point and complex dtype can require gradients

环境: ubuntu
GPU: [Tesla V100 SXM2 32GB] GPU是 32G的
config.json
{
"_name_or_path": "THUDM/chatglm-6b-int8",
"architectures": [
"ChatGLMModel"
],
"auto_map": {
"AutoConfig": "configuration_chatglm.ChatGLMConfig",
"AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration",
"AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration"
},
"bos_token_id": 130004,
"eos_token_id": 130005,
"gmask_token_id": 130001,
"hidden_size": 4096,
"inner_hidden_size": 16384,
"layernorm_epsilon": 1e-05,
"mask_token_id": 130000,
"max_sequence_length": 2048,
"model_type": "chatglm",
"num_attention_heads": 32,
"num_layers": 28,
"pad_token_id": 3,
"position_encoding_2d": true,
"quantization_bit": 0,
"quantization_embeddings": false,
"torch_dtype": "float16",
"transformers_version": "4.27.1",
"use_cache": true,
"vocab_size": 130528
}

在执行infer.ipynb 时,文件里面的两个目录问题

root_path = "/root/autodl-tmp/results"
instructions = pd.read_csv(f"{root_path}/results_new.csv")
instructions.shape
ori_instructions = pd.read_csv(f"{root_path}/results.csv")
ori_instructions.shape

这两个文件从哪里获取的,没有看到生成的代码

download_content.py has problem

使用这个文件得到数据的时候会报错If using all scalar values, you must pass an index,并且运行很久也没有结果,能帮忙一下吗

chatgpt-trading-v2\trade_with_gpt3.ipynb run error

你好,我在trade_with_gpt3.ipynb 中把env_args的stock_name 换成“MSFT”,运行中会出现
KeyError: 'microsoft corporation : microsoft assigned patent $ msft URL'错误,目前发现除了AAPL可以,有的会有失败
MSFT

Encountering a bug when using add_label.py

Is your feature request related to a problem? Please describe.
Hi, I'm encountering an issue when using add_label.py. The code segment df["post_publish_time"] = pd.to_datetime(df["post_publish_time"]) is throwing an error. I checked the csv file under the 'results_with_content' folder and found that all the values of the 'post_publish_time' field are in dictionary format hence cannot be processed by the pd.to_datetime() function. What could be causing this?

csv:
image

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

FinGPT-v1 download_contents.py bug modify

I made two changes:

There was an error in judging the status
The content could not be obtained because of the web page revision, and the modification is as follows:

    while not ok:
        try:
            response = requests.get(url = url, headers = headers)
            print(url,response.status_code)
            if response.status_code == 200:
                res = etree.HTML(response.text)
                res = res.xpath("//script[2]//text()")[0]
                res = json.loads(res[17:])
                res = pd.Series(res).to_frame().T
                ok = True
                return res
        except :
            pass

Quantitative sentiment analysis

Small issue to flag here; in the training data I see the author has determined this to be neutral -

_Example 4:

News: “Estee Lauder Q2 adj. EPS $2.11; FactSet consensus $1.90.”

The statement about Estee Lauder and FactSet consensus is neutral, as it merely states the facts without indicating a positive or negative sentiment. Here, FinGPT accurately identifies the neutrality of the statement._

Quantitatively, this is an EPS beat by $0.21 which may be enough for the stock to reactive positively to the news. I'd suggest we count this as "positive sentiment" not "neutral sentiment". I know the LLM is going to struggle with numerical analysis but this is what we need to really drive the AI to the promised land.

We are entering very grey territory once the reported EPS is within a certain range of consensus. Understanding the standard deviation within consensus estimates would really help determine if something is within the boundary of "neutral" "positive" or "negative" but this is likely a too granular at this point.

I encountered a problem while executing download_contents.py

When executing download_contents.py, the system became unresponsive without any error logs or prompts.
微信图片_20230630171100

Additionally, could you provide a tutorial outlining the installation steps for this model, the installation and support of the required companion models? Is it possible to obtain instructions for using this model and performing trend analysis and investment recommendations for a specific stock after training the model with data?"

当执行download_contents.py时,系统停止了响应,无报错日志和提示。
微信图片_20230630171100
另外一个问题,可否出一个教程,介绍一下这个模型的安装步骤、需要的配套模型的安装和支持,能不能下这个模型的使用方法,
经过数据训练后如何对某一只股票进行趋势分析和投资建议。

training resources

Hello, I would like to ask can the full training of fingpt be done on colab with A100? How long will it take.

Juchao_Annoumcement 拼写错误 请修改为o Juchao_Announcement

Juchao_Annoumcement 拼写错误,实际是Juchao_Announcement ,demo文件中多个地方拼写错误,导致无法import‘’
这个示例代码:ChatGPT_Robo_Advisor_v2.ipynb中有2处
1、from finnlp.data_sources.company_announcement.juchao import Juchao_Annoumcement
2、 "downloader = Juchao_Annoumcement()"

Pretrained model and Using instruction.

Hello, nice work.

I would like to ask when the trained model will be open sourced and how I can call the trained model input text to predict the stock price.

Thank you.

title??

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

在FinGPT-v1的例子,执行 finetune.sh脚本训练时间

我目前用两只股票(茅台和福耀玻璃),大约有70M,在执行 finetune.sh脚本的时候,一切都正常,但是训练时间很短,只有几分钟,这个正常吗,生成的outdir 看着没啥问题,运行环境是 Tesla V100 SXM2 32GB 使用Fn16

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.