Benjamin Consolvo commited on
Commit
1612b28
·
1 Parent(s): 13d43cd

readme updates

Browse files
Files changed (1) hide show
  1. README.md +66 -28
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 📚
4
  colorFrom: yellow
5
  colorTo: purple
6
  sdk: streamlit
7
- sdk_version: 1.42.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
@@ -14,20 +14,58 @@ short_description: 'Stock trading application'
14
  # Stock Trader Application
15
 
16
  ## Overview
17
- Stock Trader is an interactive web application built with Streamlit that allows you to monitor stock market data, execute trades using a paper trading account through Alpaca, analyze market sentiment, and visualize stock performance. The application combines real-time market data, news sentiment analysis, and automated trading capabilities in an easy-to-use interface.
18
 
19
 
20
- ## Features
21
- - **Real-time Stock Data**: Track current prices and market status
22
- - **Manual Trading**: Buy and sell stocks with customizable quantities
23
- - **Sentiment Analysis**: Analyze news sentiment for stocks using multiple sources
24
- - **Automated Trading**: Background process trades stocks based on sentiment analysis
25
- - **Portfolio Visualization**: View your holdings and portfolio value in real-time
26
- - **Market Insights**: Monitor top volume stocks with interactive charts
27
 
28
- ## Prompt
29
- I used a DeepSeek distilled Llama model with the following chat application to build the initial codebase: https://huggingface.co/spaces/Intel/intel-ai-enterprise-inference.
30
- Here is the prompt I wrote:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  ```text
33
  You are an expert Python software engineer and financial technology developer. Generate a fully functional Python stock trading application that uses the `yfinance` and `alpaca` packages to fetch stock data and automatically buys and sells stocks (a day-trader) based on sentiment analysis of news headlines. The app should:
@@ -44,12 +82,11 @@ You are an expert Python software engineer and financial technology developer. G
44
  10. Create a simple web UI for the program. I prefer streamlit.
45
  11. Include comments, a short README describing how to run the app, and a requirements.txt file for what packages are required.
46
  12. Use only free frameworks and APIs. Don’t use any paid ones.
47
-
48
-
49
  ```
50
 
51
- ## Installation
52
 
 
53
  ### Prerequisites
54
  - Python 3.8 or higher
55
  - [UV](https://github.com/astral-sh/uv) package manager (for dependency management)
@@ -99,13 +136,12 @@ ALPHA_VANTAGE_API_KEY = "your_alpha_vantage_api_key"
99
 
100
  Or you can add your secrets directly to the Hugging Face Space Settings if you are deploying the application on Hugging Face.
101
 
102
- 6. Launch the application
103
  ```bash
104
  streamlit run app.py
105
  ```
106
 
107
  ## Using the Application
108
-
109
  ### Manual Trading
110
  1. **Enter a Stock Symbol**: Type a valid stock ticker symbol (e.g., AAPL, MSFT) in the sidebar.
111
 
@@ -126,22 +162,24 @@ The main area displays charts for top volume stocks, showing historical price mo
126
  - Hover over data points for precise values
127
 
128
  ### Automated Trading
129
- The application includes an automated trading feature that runs in the background:
130
- 1. Analyzes sentiment for top volume stocks
 
131
  2. Executes buy orders for stocks with positive sentiment (if there is sufficient buying power)
132
  3. Executes sell orders for stocks with negative sentiment (if a position is held)
133
  4. Holds positions for stocks with neutral sentiment
134
 
135
- ## Troubleshooting
136
-
137
  ### Common Issues
138
- - **API Rate Limits**: If charts or data fail to load, you may have exceeded API rate limits. Wait a few minutes and try again.
 
 
139
  - **Invalid Stock Symbols**: Ensure you're entering valid ticker symbols when trading.
140
- - **Market Hours**: Some features may behave differently when markets are closed.
 
 
 
 
141
 
142
- ### API Limitations
143
- - **News API**: Limited to 100 requests per day on the free tier
144
- - **Alpha Vantage**: Limited to 5 API requests per minute and 500 requests per day on the free tier
145
 
146
- ## License
147
- This project is licensed under the Apache 2.0 License.
 
4
  colorFrom: yellow
5
  colorTo: purple
6
  sdk: streamlit
7
+ sdk_version: 1.45.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
14
  # Stock Trader Application
15
 
16
  ## Overview
17
+ Stock Trader is an interactive web application built with Streamlit that allows you to monitor stock market data, execute trades using a paper trading account through Alpaca, analyze market sentiment, and visualize stock performance. It is hosted on Hugging Face
18
 
19
 
20
+ ## Prompt and LLM-Generated Code
21
+ I used the [deepseek-ai/DeepSeek-R1-Distill-Llama-70B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-70B) model with another LLM chat application I also built on Hugging Face Spaces to generate the initial codebase. The LLM chat app is here: https://huggingface.co/spaces/Intel/intel-ai-enterprise-inference. It takes advantage of a [Intel® AI for Enterprise Inference](https://github.com/opea-project/Enterprise-Inference) with an OpenAI-compatible API key and model endpoint, hosted on cloud provider [Denvr Dataworks](https://www.denvrdata.com/intel).
 
 
 
 
 
22
 
23
+ If you are interested in looking at which models are currently available, you can ping the endpoint with the instructions below. This is standard boilerplate OpenAI code to check on your models that you can use with any OpenAI-compatible API key and model endpoint. First, make sure to save your API key and model endpoint in your environment variables first.
24
+ ```bash
25
+ export OPENAI_API_KEY="your-api-key"
26
+ export BASE_URL="https://api.inference.denvrdata.com/v1/"
27
+ ```
28
+
29
+ Here is the Python code to check on the models available on your endpoint:
30
+ ```python
31
+ from openai import OpenAI
32
+ import os
33
+
34
+ api_key = os.environ["OPENAI_API_KEY"]
35
+ base_url = os.environ["BASE_URL"]
36
+ client = OpenAI(api_key=api_key, base_url=base_url)
37
+ models= client.models.list()
38
+ model_names = [model.id for model in models]
39
+ print(f'client model_names = {model_names}')
40
+ ```
41
+
42
+ You should get back something like:
43
+
44
+
45
+ ```bash
46
+ client model_names = ['deepseek-ai/DeepSeek-R1-Distill-Llama-8B', 'mistralai/Mixtral-8x7B-Instruct-v0.1', 'tiiuae/Falcon3-10B-Instruct', 'BAAI/bge-base-en-v1.5', 'mistralai/Mistral-7B-Instruct-v0.1', 'inceptionai/jais-adapted-70b-chat', 'mistralai/Mistral-7B-Instruct-v0.2', 'tiiuae/Falcon3-7B-Instruct', 'meta-llama/Llama-3.2-1B-Instruct', 'meta-llama/Meta-Llama-3.1-8B-Instruct', 'meta-llama/Llama-3.3-70B-Instruct', 'ALLaM-AI/ALLaM-7B-Instruct-preview', 'meta-llama/Llama-3.2-3B-Instruct', 'meta-llama/Llama-3.1-70B-Instruct', 'deepseek-ai/DeepSeek-R1-Distill-Llama-70B']
47
+ ```
48
+ The models supported on Denvr at the time of writing are highlighted below. New models are always being added.
49
+
50
+ | Model |
51
+ |------------|
52
+ | [ALLaM-AI/ALLaM-7B-Instruct-preview](https://huggingface.co/ALLaM-AI/ALLaM-7B-Instruct-preview) |
53
+ | [BAAI/bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) |
54
+ | [deepseek-ai/DeepSeek-R1-Distill-Llama-70B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-70B) |
55
+ | [deepseek-ai/DeepSeek-R1-Distill-Llama-8B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-8B) |
56
+ | [inceptionai/jais-adapted-70b-chat](https://huggingface.co/inceptionai/jais-adapted-70b-chat) |
57
+ | [meta-llama/Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Llama-3.1-70B-Instruct) |
58
+ | [meta-llama/Llama-3.2-1B-Instruct](https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct) |
59
+ | [meta-llama/Llama-3.2-3B-Instruct](https://huggingface.co/meta-llama/Llama-3.2-3B-Instruct) |
60
+ | [meta-llama/Llama-3.3-70B-Instruct](https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct) |
61
+ | [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct) |
62
+ | [mistralai/Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1) |
63
+ | [mistralai/Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2) |
64
+ | [mistralai/Mixtral-8x7B-Instruct-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) |
65
+ | [tiiuae/Falcon3-10B-Instruct](https://huggingface.co/tiiuae/Falcon3-10B-Instruct) |
66
+ | [tiiuae/Falcon3-7B-Instruct](https://huggingface.co/tiiuae/Falcon3-7B-Instruct) |
67
+
68
+ Here is the initial prompt I gave to the DeepSeek model to generate the stock trading application:
69
 
70
  ```text
71
  You are an expert Python software engineer and financial technology developer. Generate a fully functional Python stock trading application that uses the `yfinance` and `alpaca` packages to fetch stock data and automatically buys and sells stocks (a day-trader) based on sentiment analysis of news headlines. The app should:
 
82
  10. Create a simple web UI for the program. I prefer streamlit.
83
  11. Include comments, a short README describing how to run the app, and a requirements.txt file for what packages are required.
84
  12. Use only free frameworks and APIs. Don’t use any paid ones.
 
 
85
  ```
86
 
87
+ After generating the initial code, I took that and modified it to my needs to arrive at what you would find in [app.py](app.py).
88
 
89
+ ## Installing the Application
90
  ### Prerequisites
91
  - Python 3.8 or higher
92
  - [UV](https://github.com/astral-sh/uv) package manager (for dependency management)
 
136
 
137
  Or you can add your secrets directly to the Hugging Face Space Settings if you are deploying the application on Hugging Face.
138
 
139
+ 6. To launch the application locally with streamlit, you can run:
140
  ```bash
141
  streamlit run app.py
142
  ```
143
 
144
  ## Using the Application
 
145
  ### Manual Trading
146
  1. **Enter a Stock Symbol**: Type a valid stock ticker symbol (e.g., AAPL, MSFT) in the sidebar.
147
 
 
162
  - Hover over data points for precise values
163
 
164
  ### Automated Trading
165
+ The application includes an automated trading feature that runs in the background in a loop. You can open up the Logs on the Hugging Face Spaces app if you have deployed it there, or look at the terminal output if you deployed it locally.
166
+
167
+ 1. Analyzes sentiment for top 10 volume stocks
168
  2. Executes buy orders for stocks with positive sentiment (if there is sufficient buying power)
169
  3. Executes sell orders for stocks with negative sentiment (if a position is held)
170
  4. Holds positions for stocks with neutral sentiment
171
 
 
 
172
  ### Common Issues
173
+ - **API Rate Limits**: If charts or data fail to load, you may have exceeded API rate limits.
174
+ - **News API**: Limited to 100 requests per day on the free tier
175
+ - **Alpha Vantage**: Limited to 5 API requests per minute and 500 requests per day on the free tier
176
  - **Invalid Stock Symbols**: Ensure you're entering valid ticker symbols when trading.
177
+ - **Market Hours**: Some features may behave differently when markets are closed, though you should be able to still buy and sell stocks. The actual execution of the trade will only occur once the market opens again.
178
+
179
+ ### Follow Up
180
+
181
+ Connect to LLMs on Intel® Gaudi® accelerators with just an endpoint and an OpenAI-compatible API key, courtesy of cloud-provider Denvr Dataworks: https://www.denvrdata.com/intel
182
 
183
+ Chat with 6K+ fellow developers on the Intel DevHub Discord: https://discord.gg/kfJ3NKEw5t
 
 
184
 
185
+ Connect with me on LinkedIn: https://linkedin.com/in/bconsolvo