You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-22Lines changed: 29 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@
8
8
9
9
# 💸 Investment Agent Patterns
10
10
11
-
This project shows how to use Microsoft Agent Framework for stock-market research. It downloads past prices, creates signals, tests simple strategies, and saves the results.
11
+
This project shows how to use Microsoft Agent Framework for stock-market research. Agents download past prices, write and execute a technical-analysis signal script, test the resulting strategy, and save the results.
12
12
13
13
> [!NOTE]
14
14
> Recommended first: Microsoft Agent Framework. It combines ideas from AutoGen and Semantic Kernel.
@@ -43,50 +43,56 @@ On PowerShell, use `Copy-Item .env.example .env` to copy the settings file. Then
43
43
|---|---|
44
44
|`AZURE_AI_PROJECT_ENDPOINT`| Address of the Azure AI Foundry project used by the main workflow. |
45
45
|`AZURE_AI_MODEL_DEPLOYMENT_NAME`| Name of the chat model deployed in that project. |
46
+
|`AZURE_OPENAI_ENDPOINT`| Optional direct Azure OpenAI endpoint for the Semantic Kernel workflow; otherwise it uses the Foundry project endpoint. |
47
+
|`AZURE_OPENAI_CHAT_DEPLOYMENT_NAME`| Optional direct Azure OpenAI deployment for the Semantic Kernel workflow. |
46
48
|`INVESTMENT_TICKER`| Stock symbol to study. The default is `MSFT`. |
47
49
|`INVESTMENT_START_DATE`, `INVESTMENT_END_DATE`| First and last dates for the past-price data. |
48
50
|`INVESTMENT_INITIAL_CAPITAL`| Pretend starting amount for the backtest. |
49
51
50
52
## Optional: Semantic Kernel variant
51
53
52
-
Use this command only when comparing the plugin-based variant. It creates the same type of charts, metrics, spreadsheets, and CSV files as the primary Agent Framework workflow, in its own output folder:
54
+
Use this command only when comparing the plugin-based agent variant. It reuses the configured Foundry project and model by default, then creates charts, metrics, spreadsheets, CSVs, and the generated signal script in its own output folder:
53
55
54
56
```bash
55
57
uv run python -m semantic_kernel.main
56
58
```
57
59
58
60
## Sample research output
59
61
60
-
These files were created by the main Agent Framework workflow for`MSFT`, using the default date range and a pretend $10,000 starting balance. They are examples only. Results can change when the workflow is run again because market data changes.
62
+
The following Agent Framework sample uses`MSFT` from 2020-01-01 through 2026-07-01 with a simulated $10,000 starting balance. It is historical research only; a later run can generate a different strategy and result.
61
63
62
-
### Input query
64
+
### Input
63
65
64
66
```text
65
-
Analyze MSFT from 2020-01-01 to 2026-07-01; generate MACD/RSI signals, backtest $10000, and report CAGR, total return, final value, drawdown, and Sharpe ratio.
67
+
Analyze MSFT from 2020-01-01 to 2026-07-01. Develop one transparent technical-analysis signal strategy as Python code, execute it, backtest $10000, and report CAGR, total return, final value, drawdown, and Sharpe ratio.
66
68
```
67
69
68
-
### Performance graph
70
+
### Generated signal
69
71
70
-
The top line shows how the pretend portfolio value changed over time. The shaded lower chart shows drawdown: how far the portfolio fell from its highest value at each point.
72
+
The sample agent generated a long-only trend-and-momentum signal using MSFT closing prices:
71
73
72
-
<imgsrc="output/agent_framework/trix_ultimateoscillator_reversal/stock_plot.png"alt="TRIX and Ultimate Oscillator cumulative returns and drawdown"width="500">
74
+
-**Buy:** the 50-day simple moving average is above the 200-day simple moving average and RSI(14) is above 50, after that combined condition was previously false.
75
+
-**Sell:** the combined condition becomes false: the 50-day average is at or below the 200-day average, or RSI(14) is at or below 50.
76
+
-**Hold:** no change in the combined condition.
77
+
-**Execution convention:** a close-based condition affects the next session's return, reducing same-close look-ahead bias.
73
78
74
-
### Backtest metrics
79
+
### Performance plot
80
+
81
+
The top panel shows cumulative strategy returns. The lower panel shows portfolio drawdown from its previous peak.
75
82
76
-
| Strategy | Cumulative return | CAGR | Maximum drawdown | Sharpe ratio | Final value |
> In this example run, the TRIX and Ultimate Oscillator strategy did better than the other two examples. A pretend $10,000 grew to $10,959.96, a 9.60% total gain. However, the portfolio also fell as much as 25.73% from an earlier high. One past result is not proof that a strategy will work in the future. Test it over other time periods and include trading fees, price changes during trades, and data checks before trusting the result.
95
+
See the full [backtest workbook](output/agent_framework/backtest_results.xlsx), [generated signal script](output/agent_framework/generated_signal_strategy.py), and [validated signals](output/agent_framework/stock_signals.csv).
90
96
91
97
## Repository layout
92
98
@@ -96,7 +102,7 @@ The top line shows how the pretend portfolio value changed over time. The shaded
96
102
|[semantic_kernel](semantic_kernel)| The Semantic Kernel version of the research workflow. |
97
103
|[autogen](autogen)| The AutoGen reference version, with its own Poetry environment. |
98
104
|[agent_framework_patterns](agent_framework_patterns)| Thirty small Agent Framework examples for investment research. |
99
-
|[tests](tests)| Offline tests for the Agent Framework patterns. |
105
+
|[tests](tests)| Offline tests for Agent Framework patterns and the REPL contracts. |
100
106
|[output](output)| Saved charts, metrics, and example pattern responses. |
101
107
|[docs](docs)| Guides for each implementation and framework comparison. |
102
108
@@ -106,12 +112,13 @@ The Agent Framework pattern tests run without Azure credentials or live market-d
106
112
107
113
```bash
108
114
uv run ruff check agent_framework semantic_kernel agent_framework_patterns tests
109
-
uv run pytest tests/agent_framework_patterns -q
115
+
uv run pytest tests -q
110
116
```
111
117
112
118
## Safety and limitations
113
119
114
120
- These results are for learning and research, not financial advice or a real trading system.
121
+
- Both workflows execute model-authored Python to create signals. Their validation is not a security sandbox; run them only in an isolated development environment without credentials or production data.
115
122
- Good results from the past do not mean the same strategy will work in the future.
116
123
- The examples use public market data and simple rules. They leave out trading fees, price changes that happen while a trade is being made, taxes, careful handling of stock splits and dividends, and checks for an individual investor's needs.
117
124
- Review AI responses, connected tools, and data licences before using this project outside a learning or research setting.
returnf"Analyze {ticker} from {start} to {end}; generate MACD/RSI signals, backtest ${capital}, and report CAGR, total return, final value, drawdown, and Sharpe ratio."
18
+
return (
19
+
f"Analyze {ticker} from {start} to {end}. Develop one transparent technical-analysis "
20
+
f"signal strategy as Python code, execute it, backtest ${capital}, and report CAGR, "
21
+
"total return, final value, drawdown, and Sharpe ratio."
0 commit comments