market-brief 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- market_brief-1.0.2/.env.example +10 -0
- market_brief-1.0.2/.github/workflows/publish.yml +37 -0
- market_brief-1.0.2/.github/workflows/tests.yml +19 -0
- market_brief-1.0.2/.gitignore +20 -0
- market_brief-1.0.2/LICENSE +21 -0
- market_brief-1.0.2/PKG-INFO +262 -0
- market_brief-1.0.2/README.md +243 -0
- market_brief-1.0.2/img/sample_card.png +0 -0
- market_brief-1.0.2/logs/.gitkeep +0 -0
- market_brief-1.0.2/main.py +12 -0
- market_brief-1.0.2/market_brief/__init__.py +1 -0
- market_brief-1.0.2/market_brief/ai.py +70 -0
- market_brief-1.0.2/market_brief/cli.py +110 -0
- market_brief-1.0.2/market_brief/config.py +65 -0
- market_brief-1.0.2/market_brief/home.py +39 -0
- market_brief-1.0.2/market_brief/market.py +272 -0
- market_brief-1.0.2/market_brief/notify.py +164 -0
- market_brief-1.0.2/market_brief/portfolio.py +34 -0
- market_brief-1.0.2/market_brief/recommendations.py +168 -0
- market_brief-1.0.2/market_brief/render.py +217 -0
- market_brief-1.0.2/market_brief/summary.py +62 -0
- market_brief-1.0.2/market_brief/templates/env.example +10 -0
- market_brief-1.0.2/market_brief/templates/portfolio.example.csv +11 -0
- market_brief-1.0.2/market_brief/trading_day.py +26 -0
- market_brief-1.0.2/market_brief.egg-info/PKG-INFO +262 -0
- market_brief-1.0.2/market_brief.egg-info/SOURCES.txt +40 -0
- market_brief-1.0.2/market_brief.egg-info/dependency_links.txt +1 -0
- market_brief-1.0.2/market_brief.egg-info/entry_points.txt +2 -0
- market_brief-1.0.2/market_brief.egg-info/requires.txt +9 -0
- market_brief-1.0.2/market_brief.egg-info/scm_file_list.json +36 -0
- market_brief-1.0.2/market_brief.egg-info/scm_version.json +8 -0
- market_brief-1.0.2/market_brief.egg-info/top_level.txt +1 -0
- market_brief-1.0.2/portfolio/portfolio.example.csv +11 -0
- market_brief-1.0.2/pyproject.toml +41 -0
- market_brief-1.0.2/requirements-dev.txt +2 -0
- market_brief-1.0.2/requirements.txt +6 -0
- market_brief-1.0.2/setup.cfg +4 -0
- market_brief-1.0.2/tests/conftest.py +8 -0
- market_brief-1.0.2/tests/test_home.py +34 -0
- market_brief-1.0.2/tests/test_market.py +37 -0
- market_brief-1.0.2/tests/test_notify.py +55 -0
- market_brief-1.0.2/tests/test_portfolio.py +45 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Required
|
|
2
|
+
GEMINI_API_KEY=your_key_here
|
|
3
|
+
DISCORD_WEBHOOK=https://discord.com/api/webhooks/...
|
|
4
|
+
|
|
5
|
+
# Optional (defaults shown)
|
|
6
|
+
GEMINI_MODELS=gemini-3.5-flash-lite,gemini-3.1-flash-lite,gemini-3.6-flash
|
|
7
|
+
HOLDINGS_FILE=portfolio/portfolio.csv
|
|
8
|
+
BENCHMARK=SPY
|
|
9
|
+
RECOMMENDATIONS=1
|
|
10
|
+
SUGGESTIONS=stocks
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
# Runs when you publish a GitHub Release. Builds the package from the release's
|
|
4
|
+
# tag and uploads it to PyPI using Trusted Publishing (no API tokens stored).
|
|
5
|
+
on:
|
|
6
|
+
release:
|
|
7
|
+
types: [published]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
with:
|
|
15
|
+
fetch-depth: 0 # tags are needed for the version number
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.11"
|
|
19
|
+
- run: pip install build
|
|
20
|
+
- run: python -m build # makes dist/*.whl and dist/*.tar.gz
|
|
21
|
+
- uses: actions/upload-artifact@v4
|
|
22
|
+
with:
|
|
23
|
+
name: dist
|
|
24
|
+
path: dist/
|
|
25
|
+
|
|
26
|
+
publish:
|
|
27
|
+
needs: build
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
environment: pypi # must match the environment name set on PyPI
|
|
30
|
+
permissions:
|
|
31
|
+
id-token: write # lets PyPI verify this workflow; no secrets needed
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/download-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
name: dist
|
|
36
|
+
path: dist/
|
|
37
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
with:
|
|
13
|
+
fetch-depth: 0 # full history + tags, so the version comes from the latest tag
|
|
14
|
+
- uses: actions/setup-python@v5
|
|
15
|
+
with:
|
|
16
|
+
python-version: "3.11"
|
|
17
|
+
cache: pip
|
|
18
|
+
- run: pip install -e ".[dev]" # also proves the package installs
|
|
19
|
+
- run: pytest -q
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# secrets
|
|
2
|
+
.env
|
|
3
|
+
|
|
4
|
+
# your real holdings (the example file is committed)
|
|
5
|
+
portfolio/*
|
|
6
|
+
!portfolio/portfolio.example.csv
|
|
7
|
+
|
|
8
|
+
# generated output
|
|
9
|
+
img/brief_card.png
|
|
10
|
+
logs/*
|
|
11
|
+
!logs/.gitkeep
|
|
12
|
+
|
|
13
|
+
# python
|
|
14
|
+
.venv/
|
|
15
|
+
__pycache__/
|
|
16
|
+
.pytest_cache/
|
|
17
|
+
# packaging
|
|
18
|
+
*.egg-info/
|
|
19
|
+
build/
|
|
20
|
+
dist/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pulse Robotics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: market-brief
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Daily portfolio brief for Discord: Yahoo Finance data, Gemini commentary, sector and market-cap balance.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Repository, https://github.com/Pulse-Robotics/market_brief
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: google-genai
|
|
11
|
+
Requires-Dist: yfinance
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
Requires-Dist: python-dotenv
|
|
14
|
+
Requires-Dist: matplotlib>=3.9
|
|
15
|
+
Requires-Dist: pandas_market_calendars
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Market Brief
|
|
21
|
+
|
|
22
|
+
[](https://github.com/Pulse-Robotics/market_brief/actions/workflows/tests.yml)
|
|
23
|
+
|
|
24
|
+
A daily portfolio brief posted to Discord before the US market opens.
|
|
25
|
+
|
|
26
|
+
Each weekday morning it:
|
|
27
|
+
|
|
28
|
+
1. Reads your holdings from a Yahoo Finance portfolio export
|
|
29
|
+
2. Pulls fresh prices, previous closes and company-specific headlines from Yahoo
|
|
30
|
+
3. Has Gemini write one short note per holding explaining the move, using only the headlines
|
|
31
|
+
4. Breaks down your **sector** mix vs the S&P 500 and your **large / mid / small cap** mix
|
|
32
|
+
5. Suggests stocks to research in each cap tier that would fill your gaps
|
|
33
|
+
6. Posts one Discord message with the commentary and an image of the tables
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
*Sample made from the example portfolio with placeholder prices.*
|
|
38
|
+
|
|
39
|
+
The message text looks like this:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
## 📈 Morning Brief · Tue Nov 24
|
|
43
|
+
> $21,800.66 · 🔴 -$247.86 (-1.12%) last session · 🟢 +$8,523.96 (+64.20%) total
|
|
44
|
+
|
|
45
|
+
Mega-cap tech led while banks and the broad index slipped.
|
|
46
|
+
|
|
47
|
+
- 🔺 MSFT +0.52% · No specific news.
|
|
48
|
+
- 🔻 NVDA -7.72% · Questions over management persist after a leadership change.
|
|
49
|
+
- 🔻 JPM -0.69% · Cut net interest income guidance at an investor conference.
|
|
50
|
+
...
|
|
51
|
+
|
|
52
|
+
### ⚖️ Balance
|
|
53
|
+
- Tech at 54% vs 38% market while the sector ETF fell 17% this month.
|
|
54
|
+
|
|
55
|
+
### 💡 Ideas to research
|
|
56
|
+
Large cap
|
|
57
|
+
- UNH · Adds healthcare; largest US health insurer.
|
|
58
|
+
Mid cap
|
|
59
|
+
- ...
|
|
60
|
+
Small cap
|
|
61
|
+
- ...
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> This is a personal tool. Summaries and ideas are AI-generated from limited data (prices,
|
|
65
|
+
> headlines and sector weights, no fundamentals) and are **not financial advice**.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/Pulse-Robotics/market_brief.git
|
|
73
|
+
cd market_brief
|
|
74
|
+
python3 -m venv .venv
|
|
75
|
+
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
|
|
76
|
+
pip install -r requirements.txt
|
|
77
|
+
|
|
78
|
+
cp .env.example .env # add your Gemini key and Discord webhook
|
|
79
|
+
# export your Yahoo Finance portfolio to portfolio/portfolio.csv
|
|
80
|
+
|
|
81
|
+
python main.py --dry-run # print the brief, save img/brief_card.png
|
|
82
|
+
python main.py # post to Discord
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
If PowerShell blocks activation, run `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass`
|
|
86
|
+
first, or skip activation and use `.venv\Scripts\python main.py`.
|
|
87
|
+
|
|
88
|
+
### Install as a package
|
|
89
|
+
|
|
90
|
+
You can also install it with pip:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install market-brief # latest release from PyPI (or pin: "market-brief==1.0.2")
|
|
94
|
+
|
|
95
|
+
mkdir my-brief && cd my-brief
|
|
96
|
+
market-brief init # creates .env, portfolio/, img/, logs/ here (never overwrites)
|
|
97
|
+
# fill in .env, export your Yahoo portfolio to portfolio/portfolio.csv
|
|
98
|
+
market-brief --dry-run
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Or straight from GitHub at a release tag:
|
|
102
|
+
`pip install "market-brief @ git+https://github.com/Pulse-Robotics/market_brief.git@v1.0.2"`
|
|
103
|
+
|
|
104
|
+
When installed this way, `.env`, `portfolio/`, `img/` and `logs/` are read from the current directory,
|
|
105
|
+
or from `MARKET_BRIEF_HOME` if you set it. In cron, `cd` into that folder first
|
|
106
|
+
(`cd /path/to/my-brief && /path/to/venv/bin/market-brief`). The modules can also be imported as a library
|
|
107
|
+
(`from market_brief import market, ai`).
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Setup
|
|
112
|
+
|
|
113
|
+
### Discord webhook
|
|
114
|
+
|
|
115
|
+
In your server, open a channel's settings and go to **Integrations → Webhooks → New Webhook → Copy Webhook URL**.
|
|
116
|
+
Treat the URL like a password: anyone who has it can post to the channel. If it leaks, delete the webhook
|
|
117
|
+
and make a new one.
|
|
118
|
+
|
|
119
|
+
### Gemini API key
|
|
120
|
+
|
|
121
|
+
Create one at [aistudio.google.com/apikey](https://aistudio.google.com/apikey). Check in AI Studio which
|
|
122
|
+
Flash / Flash-Lite models are currently free, since model names change over time.
|
|
123
|
+
|
|
124
|
+
The free tier often returns `503` at busy times, and Google may use free-tier prompts to improve its
|
|
125
|
+
products. Linking billing moves you to the paid tier, which gets priority. Google AI Pro subscribers
|
|
126
|
+
get monthly Cloud credits that cover this many times over. Either way, the script sends Gemini only
|
|
127
|
+
percent changes, weights and headlines, never dollar amounts or share counts.
|
|
128
|
+
|
|
129
|
+
### `.env`
|
|
130
|
+
|
|
131
|
+
| Variable | Required | Default | Purpose |
|
|
132
|
+
|---|---|---|---|
|
|
133
|
+
| `GEMINI_API_KEY` | yes | — | Gemini API key |
|
|
134
|
+
| `DISCORD_WEBHOOK` | yes* | — | Discord webhook URL (*not needed for `--dry-run`) |
|
|
135
|
+
| `GEMINI_MODELS` | no | `gemini-3.5-flash-lite,gemini-3.1-flash-lite` | Models to try, in order. The rest are fallbacks |
|
|
136
|
+
| `HOLDINGS_FILE` | no | `portfolio/portfolio.csv` | Portfolio export, relative to the repo root |
|
|
137
|
+
| `BENCHMARK` | no | `SPY` | Fund whose sector mix counts as "the market" |
|
|
138
|
+
| `RECOMMENDATIONS` | no | `1` | `0` turns off sector/cap analysis and ideas |
|
|
139
|
+
| `SUGGESTIONS` | no | `stocks` | Kind of ideas: `stocks`, `etfs` or `mixed` |
|
|
140
|
+
|
|
141
|
+
### Portfolio file
|
|
142
|
+
|
|
143
|
+
In Yahoo Finance, open your portfolio, choose **Export**, and save the file as `portfolio/portfolio.csv`.
|
|
144
|
+
See [`portfolio/portfolio.example.csv`](https://github.com/Pulse-Robotics/market_brief/blob/main/portfolio/portfolio.example.csv) for the format.
|
|
145
|
+
|
|
146
|
+
- Only `Symbol`, `Purchase Price` and `Quantity` are read. Prices in the export are ignored, because they're frozen at export time.
|
|
147
|
+
- Multiple lots of the same ticker are combined, with a weighted cost basis.
|
|
148
|
+
- Rows with no quantity (watchlist-only symbols) are skipped.
|
|
149
|
+
- Comma- and tab-separated files both work.
|
|
150
|
+
|
|
151
|
+
**Re-export after every buy, sell or stock split.** Yahoo lots are entered by hand and don't always adjust
|
|
152
|
+
for splits. Your real `portfolio/portfolio.csv` is git-ignored.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Usage
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
python main.py --dry-run # print the text and save img/brief_card.png, post nothing
|
|
160
|
+
python main.py # build and post to Discord
|
|
161
|
+
python main.py --force # run even if the market is closed today
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- **Market holidays and weekends** are skipped using the NYSE calendar. Early-close days get a note in the header.
|
|
165
|
+
- **If a run crashes**, it posts a short **⚠️ Market brief failed** message to the same channel, with the webhook token redacted.
|
|
166
|
+
- **If Gemini is down**, the brief still posts with the numbers and no commentary.
|
|
167
|
+
|
|
168
|
+
### Schedule it (Linux)
|
|
169
|
+
|
|
170
|
+
Every weekday at 9:00 AM Eastern, 30 minutes before the open:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
crontab -e
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
CRON_TZ=America/New_York
|
|
178
|
+
0 9 * * 1-5 cd /path/to/market_brief && .venv/bin/python main.py >> logs/brief.log 2>&1
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`CRON_TZ` keeps it at 9:00 Eastern through daylight-saving changes. `logs/` is git-ignored.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Project layout
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
market_brief/
|
|
189
|
+
├── main.py # entry point from a checkout (pip install gives `market-brief`)
|
|
190
|
+
├── pyproject.toml # packaging: pip install, `market-brief` command
|
|
191
|
+
├── market_brief/ # the package
|
|
192
|
+
│ ├── cli.py # command-line entry point (`market-brief`, `market-brief init`)
|
|
193
|
+
│ ├── home.py # `init`: sets up a working folder for pip installs
|
|
194
|
+
│ ├── templates/ # .env and portfolio examples bundled for `init`
|
|
195
|
+
│ ├── config.py # .env settings and setup checks
|
|
196
|
+
│ ├── portfolio.py # parses the Yahoo portfolio export
|
|
197
|
+
│ ├── market.py # Yahoo Finance: prices, headlines, sectors, cap tiers, momentum
|
|
198
|
+
│ ├── ai.py # Gemini: retries, model fallback, JSON mode
|
|
199
|
+
│ ├── summary.py # per-holding commentary
|
|
200
|
+
│ ├── recommendations.py # sector + cap balance, ideas by tier
|
|
201
|
+
│ ├── render.py # draws the table image
|
|
202
|
+
│ ├── notify.py # Discord message, image upload, failure alerts
|
|
203
|
+
│ └── trading_day.py # NYSE holidays and early closes
|
|
204
|
+
├── portfolio/ # your export goes here (git-ignored); example included
|
|
205
|
+
├── img/ # generated image (git-ignored) + README sample
|
|
206
|
+
├── logs/ # cron logs (git-ignored)
|
|
207
|
+
├── tests/ # pytest
|
|
208
|
+
├── requirements.txt
|
|
209
|
+
├── requirements-dev.txt # adds pytest
|
|
210
|
+
└── .env.example
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### How it works
|
|
214
|
+
|
|
215
|
+
- **Prices** come from Yahoo's quote fields (`regularMarketPrice` / `regularMarketPreviousClose`). These
|
|
216
|
+
are split-aware. Daily history is used only as a fallback, because it can have gaps around corporate actions.
|
|
217
|
+
- **Headlines** are filtered to ones that mention the ticker or the company name, because Yahoo's per-ticker
|
|
218
|
+
news often includes unrelated stories.
|
|
219
|
+
- **Commentary**: Gemini returns one note of up to 12 words per ticker as JSON. Python builds the bullets, so
|
|
220
|
+
every holding appears exactly once, in weight order, with numbers from the data and not the model. The prompt
|
|
221
|
+
forbids inventing causes that aren't in a headline. Temperature is 0.2 so runs stay consistent.
|
|
222
|
+
- **Sectors**: stocks use Yahoo's sector, and ETFs are looked through to their holdings. The benchmark's sector
|
|
223
|
+
mix is pulled live. Sentiment uses each SPDR sector ETF's 1-month move.
|
|
224
|
+
- **Market cap**: large is over $10B, mid $2–10B, small $300M–2B. Funds use Yahoo's category ("Large Blend", ...).
|
|
225
|
+
Size sentiment uses SPY / MDY / IWM.
|
|
226
|
+
- **Ideas**: Gemini proposes 3 per tier. Each one is checked on Yahoo and filed under its *actual* market-cap
|
|
227
|
+
tier, and 2 per tier are kept. Tickers that don't exist, that you already own, micro caps, and the wrong type
|
|
228
|
+
(e.g. ETFs when `SUGGESTIONS=stocks`) are dropped.
|
|
229
|
+
- **Resilience**: busy and rate-limit errors are retried (5s, 15s, 45s) before moving to the next model. If
|
|
230
|
+
every model fails, later calls in the same run skip straight to the fallback.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Development
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
pip install -e ".[dev]"
|
|
238
|
+
pytest -q
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Versions come from git tags (`v1.0.2` → `1.0.2`) via setuptools-scm. Publishing a GitHub Release from a
|
|
242
|
+
tag builds the package and uploads it to PyPI automatically (`.github/workflows/publish.yml`).
|
|
243
|
+
|
|
244
|
+
The tests cover portfolio parsing, cap tiers, headline matching, message splitting and token redaction.
|
|
245
|
+
They run on every push through GitHub Actions, which also checks that the package installs.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Troubleshooting
|
|
250
|
+
|
|
251
|
+
| Symptom | Cause / fix |
|
|
252
|
+
|---|---|
|
|
253
|
+
| `Can't run yet: Missing in .env ...` | Copy `.env.example` to `.env` and fill in the values |
|
|
254
|
+
| `Portfolio file not found` | Export from Yahoo to `portfolio/portfolio.csv` |
|
|
255
|
+
| `API key not valid` | Wrong key in `.env`. The file always overrides terminal variables |
|
|
256
|
+
| `503 UNAVAILABLE` retries | Gemini's free tier is busy. It retries automatically. Linking billing fixes it for good |
|
|
257
|
+
| `model not found` | Update `GEMINI_MODELS` to names AI Studio currently lists |
|
|
258
|
+
| `No price data from Yahoo: XYZ` | `pip install -U yfinance`. Yahoo changes its API often |
|
|
259
|
+
| Wrong daily % right after a split | Re-export the portfolio and check share counts against your brokerage |
|
|
260
|
+
| `SSL handshake failure` posting to Discord | Your network (often a firewall) blocks Discord. Run from another network |
|
|
261
|
+
| Nothing posted on a weekday | Check whether it was an NYSE holiday (the log says "Market closed today") |
|
|
262
|
+
| Nothing posts from cron | Check `logs/brief.log`, and confirm the cron line `cd`s into the repo and uses `.venv/bin/python` |
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Market Brief
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Pulse-Robotics/market_brief/actions/workflows/tests.yml)
|
|
4
|
+
|
|
5
|
+
A daily portfolio brief posted to Discord before the US market opens.
|
|
6
|
+
|
|
7
|
+
Each weekday morning it:
|
|
8
|
+
|
|
9
|
+
1. Reads your holdings from a Yahoo Finance portfolio export
|
|
10
|
+
2. Pulls fresh prices, previous closes and company-specific headlines from Yahoo
|
|
11
|
+
3. Has Gemini write one short note per holding explaining the move, using only the headlines
|
|
12
|
+
4. Breaks down your **sector** mix vs the S&P 500 and your **large / mid / small cap** mix
|
|
13
|
+
5. Suggests stocks to research in each cap tier that would fill your gaps
|
|
14
|
+
6. Posts one Discord message with the commentary and an image of the tables
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
*Sample made from the example portfolio with placeholder prices.*
|
|
19
|
+
|
|
20
|
+
The message text looks like this:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
## 📈 Morning Brief · Tue Nov 24
|
|
24
|
+
> $21,800.66 · 🔴 -$247.86 (-1.12%) last session · 🟢 +$8,523.96 (+64.20%) total
|
|
25
|
+
|
|
26
|
+
Mega-cap tech led while banks and the broad index slipped.
|
|
27
|
+
|
|
28
|
+
- 🔺 MSFT +0.52% · No specific news.
|
|
29
|
+
- 🔻 NVDA -7.72% · Questions over management persist after a leadership change.
|
|
30
|
+
- 🔻 JPM -0.69% · Cut net interest income guidance at an investor conference.
|
|
31
|
+
...
|
|
32
|
+
|
|
33
|
+
### ⚖️ Balance
|
|
34
|
+
- Tech at 54% vs 38% market while the sector ETF fell 17% this month.
|
|
35
|
+
|
|
36
|
+
### 💡 Ideas to research
|
|
37
|
+
Large cap
|
|
38
|
+
- UNH · Adds healthcare; largest US health insurer.
|
|
39
|
+
Mid cap
|
|
40
|
+
- ...
|
|
41
|
+
Small cap
|
|
42
|
+
- ...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
> This is a personal tool. Summaries and ideas are AI-generated from limited data (prices,
|
|
46
|
+
> headlines and sector weights, no fundamentals) and are **not financial advice**.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
git clone https://github.com/Pulse-Robotics/market_brief.git
|
|
54
|
+
cd market_brief
|
|
55
|
+
python3 -m venv .venv
|
|
56
|
+
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
|
|
57
|
+
pip install -r requirements.txt
|
|
58
|
+
|
|
59
|
+
cp .env.example .env # add your Gemini key and Discord webhook
|
|
60
|
+
# export your Yahoo Finance portfolio to portfolio/portfolio.csv
|
|
61
|
+
|
|
62
|
+
python main.py --dry-run # print the brief, save img/brief_card.png
|
|
63
|
+
python main.py # post to Discord
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If PowerShell blocks activation, run `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass`
|
|
67
|
+
first, or skip activation and use `.venv\Scripts\python main.py`.
|
|
68
|
+
|
|
69
|
+
### Install as a package
|
|
70
|
+
|
|
71
|
+
You can also install it with pip:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install market-brief # latest release from PyPI (or pin: "market-brief==1.0.2")
|
|
75
|
+
|
|
76
|
+
mkdir my-brief && cd my-brief
|
|
77
|
+
market-brief init # creates .env, portfolio/, img/, logs/ here (never overwrites)
|
|
78
|
+
# fill in .env, export your Yahoo portfolio to portfolio/portfolio.csv
|
|
79
|
+
market-brief --dry-run
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Or straight from GitHub at a release tag:
|
|
83
|
+
`pip install "market-brief @ git+https://github.com/Pulse-Robotics/market_brief.git@v1.0.2"`
|
|
84
|
+
|
|
85
|
+
When installed this way, `.env`, `portfolio/`, `img/` and `logs/` are read from the current directory,
|
|
86
|
+
or from `MARKET_BRIEF_HOME` if you set it. In cron, `cd` into that folder first
|
|
87
|
+
(`cd /path/to/my-brief && /path/to/venv/bin/market-brief`). The modules can also be imported as a library
|
|
88
|
+
(`from market_brief import market, ai`).
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Setup
|
|
93
|
+
|
|
94
|
+
### Discord webhook
|
|
95
|
+
|
|
96
|
+
In your server, open a channel's settings and go to **Integrations → Webhooks → New Webhook → Copy Webhook URL**.
|
|
97
|
+
Treat the URL like a password: anyone who has it can post to the channel. If it leaks, delete the webhook
|
|
98
|
+
and make a new one.
|
|
99
|
+
|
|
100
|
+
### Gemini API key
|
|
101
|
+
|
|
102
|
+
Create one at [aistudio.google.com/apikey](https://aistudio.google.com/apikey). Check in AI Studio which
|
|
103
|
+
Flash / Flash-Lite models are currently free, since model names change over time.
|
|
104
|
+
|
|
105
|
+
The free tier often returns `503` at busy times, and Google may use free-tier prompts to improve its
|
|
106
|
+
products. Linking billing moves you to the paid tier, which gets priority. Google AI Pro subscribers
|
|
107
|
+
get monthly Cloud credits that cover this many times over. Either way, the script sends Gemini only
|
|
108
|
+
percent changes, weights and headlines, never dollar amounts or share counts.
|
|
109
|
+
|
|
110
|
+
### `.env`
|
|
111
|
+
|
|
112
|
+
| Variable | Required | Default | Purpose |
|
|
113
|
+
|---|---|---|---|
|
|
114
|
+
| `GEMINI_API_KEY` | yes | — | Gemini API key |
|
|
115
|
+
| `DISCORD_WEBHOOK` | yes* | — | Discord webhook URL (*not needed for `--dry-run`) |
|
|
116
|
+
| `GEMINI_MODELS` | no | `gemini-3.5-flash-lite,gemini-3.1-flash-lite` | Models to try, in order. The rest are fallbacks |
|
|
117
|
+
| `HOLDINGS_FILE` | no | `portfolio/portfolio.csv` | Portfolio export, relative to the repo root |
|
|
118
|
+
| `BENCHMARK` | no | `SPY` | Fund whose sector mix counts as "the market" |
|
|
119
|
+
| `RECOMMENDATIONS` | no | `1` | `0` turns off sector/cap analysis and ideas |
|
|
120
|
+
| `SUGGESTIONS` | no | `stocks` | Kind of ideas: `stocks`, `etfs` or `mixed` |
|
|
121
|
+
|
|
122
|
+
### Portfolio file
|
|
123
|
+
|
|
124
|
+
In Yahoo Finance, open your portfolio, choose **Export**, and save the file as `portfolio/portfolio.csv`.
|
|
125
|
+
See [`portfolio/portfolio.example.csv`](https://github.com/Pulse-Robotics/market_brief/blob/main/portfolio/portfolio.example.csv) for the format.
|
|
126
|
+
|
|
127
|
+
- Only `Symbol`, `Purchase Price` and `Quantity` are read. Prices in the export are ignored, because they're frozen at export time.
|
|
128
|
+
- Multiple lots of the same ticker are combined, with a weighted cost basis.
|
|
129
|
+
- Rows with no quantity (watchlist-only symbols) are skipped.
|
|
130
|
+
- Comma- and tab-separated files both work.
|
|
131
|
+
|
|
132
|
+
**Re-export after every buy, sell or stock split.** Yahoo lots are entered by hand and don't always adjust
|
|
133
|
+
for splits. Your real `portfolio/portfolio.csv` is git-ignored.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Usage
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
python main.py --dry-run # print the text and save img/brief_card.png, post nothing
|
|
141
|
+
python main.py # build and post to Discord
|
|
142
|
+
python main.py --force # run even if the market is closed today
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- **Market holidays and weekends** are skipped using the NYSE calendar. Early-close days get a note in the header.
|
|
146
|
+
- **If a run crashes**, it posts a short **⚠️ Market brief failed** message to the same channel, with the webhook token redacted.
|
|
147
|
+
- **If Gemini is down**, the brief still posts with the numbers and no commentary.
|
|
148
|
+
|
|
149
|
+
### Schedule it (Linux)
|
|
150
|
+
|
|
151
|
+
Every weekday at 9:00 AM Eastern, 30 minutes before the open:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
crontab -e
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
CRON_TZ=America/New_York
|
|
159
|
+
0 9 * * 1-5 cd /path/to/market_brief && .venv/bin/python main.py >> logs/brief.log 2>&1
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`CRON_TZ` keeps it at 9:00 Eastern through daylight-saving changes. `logs/` is git-ignored.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Project layout
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
market_brief/
|
|
170
|
+
├── main.py # entry point from a checkout (pip install gives `market-brief`)
|
|
171
|
+
├── pyproject.toml # packaging: pip install, `market-brief` command
|
|
172
|
+
├── market_brief/ # the package
|
|
173
|
+
│ ├── cli.py # command-line entry point (`market-brief`, `market-brief init`)
|
|
174
|
+
│ ├── home.py # `init`: sets up a working folder for pip installs
|
|
175
|
+
│ ├── templates/ # .env and portfolio examples bundled for `init`
|
|
176
|
+
│ ├── config.py # .env settings and setup checks
|
|
177
|
+
│ ├── portfolio.py # parses the Yahoo portfolio export
|
|
178
|
+
│ ├── market.py # Yahoo Finance: prices, headlines, sectors, cap tiers, momentum
|
|
179
|
+
│ ├── ai.py # Gemini: retries, model fallback, JSON mode
|
|
180
|
+
│ ├── summary.py # per-holding commentary
|
|
181
|
+
│ ├── recommendations.py # sector + cap balance, ideas by tier
|
|
182
|
+
│ ├── render.py # draws the table image
|
|
183
|
+
│ ├── notify.py # Discord message, image upload, failure alerts
|
|
184
|
+
│ └── trading_day.py # NYSE holidays and early closes
|
|
185
|
+
├── portfolio/ # your export goes here (git-ignored); example included
|
|
186
|
+
├── img/ # generated image (git-ignored) + README sample
|
|
187
|
+
├── logs/ # cron logs (git-ignored)
|
|
188
|
+
├── tests/ # pytest
|
|
189
|
+
├── requirements.txt
|
|
190
|
+
├── requirements-dev.txt # adds pytest
|
|
191
|
+
└── .env.example
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### How it works
|
|
195
|
+
|
|
196
|
+
- **Prices** come from Yahoo's quote fields (`regularMarketPrice` / `regularMarketPreviousClose`). These
|
|
197
|
+
are split-aware. Daily history is used only as a fallback, because it can have gaps around corporate actions.
|
|
198
|
+
- **Headlines** are filtered to ones that mention the ticker or the company name, because Yahoo's per-ticker
|
|
199
|
+
news often includes unrelated stories.
|
|
200
|
+
- **Commentary**: Gemini returns one note of up to 12 words per ticker as JSON. Python builds the bullets, so
|
|
201
|
+
every holding appears exactly once, in weight order, with numbers from the data and not the model. The prompt
|
|
202
|
+
forbids inventing causes that aren't in a headline. Temperature is 0.2 so runs stay consistent.
|
|
203
|
+
- **Sectors**: stocks use Yahoo's sector, and ETFs are looked through to their holdings. The benchmark's sector
|
|
204
|
+
mix is pulled live. Sentiment uses each SPDR sector ETF's 1-month move.
|
|
205
|
+
- **Market cap**: large is over $10B, mid $2–10B, small $300M–2B. Funds use Yahoo's category ("Large Blend", ...).
|
|
206
|
+
Size sentiment uses SPY / MDY / IWM.
|
|
207
|
+
- **Ideas**: Gemini proposes 3 per tier. Each one is checked on Yahoo and filed under its *actual* market-cap
|
|
208
|
+
tier, and 2 per tier are kept. Tickers that don't exist, that you already own, micro caps, and the wrong type
|
|
209
|
+
(e.g. ETFs when `SUGGESTIONS=stocks`) are dropped.
|
|
210
|
+
- **Resilience**: busy and rate-limit errors are retried (5s, 15s, 45s) before moving to the next model. If
|
|
211
|
+
every model fails, later calls in the same run skip straight to the fallback.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Development
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
pip install -e ".[dev]"
|
|
219
|
+
pytest -q
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Versions come from git tags (`v1.0.2` → `1.0.2`) via setuptools-scm. Publishing a GitHub Release from a
|
|
223
|
+
tag builds the package and uploads it to PyPI automatically (`.github/workflows/publish.yml`).
|
|
224
|
+
|
|
225
|
+
The tests cover portfolio parsing, cap tiers, headline matching, message splitting and token redaction.
|
|
226
|
+
They run on every push through GitHub Actions, which also checks that the package installs.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Troubleshooting
|
|
231
|
+
|
|
232
|
+
| Symptom | Cause / fix |
|
|
233
|
+
|---|---|
|
|
234
|
+
| `Can't run yet: Missing in .env ...` | Copy `.env.example` to `.env` and fill in the values |
|
|
235
|
+
| `Portfolio file not found` | Export from Yahoo to `portfolio/portfolio.csv` |
|
|
236
|
+
| `API key not valid` | Wrong key in `.env`. The file always overrides terminal variables |
|
|
237
|
+
| `503 UNAVAILABLE` retries | Gemini's free tier is busy. It retries automatically. Linking billing fixes it for good |
|
|
238
|
+
| `model not found` | Update `GEMINI_MODELS` to names AI Studio currently lists |
|
|
239
|
+
| `No price data from Yahoo: XYZ` | `pip install -U yfinance`. Yahoo changes its API often |
|
|
240
|
+
| Wrong daily % right after a split | Re-export the portfolio and check share counts against your brokerage |
|
|
241
|
+
| `SSL handshake failure` posting to Discord | Your network (often a firewall) blocks Discord. Run from another network |
|
|
242
|
+
| Nothing posted on a weekday | Check whether it was an NYSE holiday (the log says "Market closed today") |
|
|
243
|
+
| Nothing posts from cron | Check `logs/brief.log`, and confirm the cron line `cd`s into the repo and uses `.venv/bin/python` |
|
|
Binary file
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Run the morning portfolio brief from a repo checkout.
|
|
2
|
+
|
|
3
|
+
python main.py # build and post to Discord
|
|
4
|
+
python main.py --dry-run # print text and save img/brief_card.png, post nothing
|
|
5
|
+
python main.py --force # run even if the market is closed today
|
|
6
|
+
|
|
7
|
+
Installed with pip? Use the `market-brief` command instead.
|
|
8
|
+
"""
|
|
9
|
+
from market_brief.cli import main
|
|
10
|
+
|
|
11
|
+
if __name__ == "__main__":
|
|
12
|
+
main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Daily portfolio brief: Yahoo Finance data, Gemini commentary, Discord delivery."""
|