Skip to content

Turn the Full Featured example into a believable simulated stock market - #57

Open
JanGoebelsBot wants to merge 6 commits into
conformance-serverfrom
stock-example-market-news
Open

JanGoebelsBot wants to merge 6 commits into
conformance-serverfrom
stock-example-market-news

Conversation

@JanGoebelsBot

@JanGoebelsBot JanGoebelsBot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Builds on #56 (conformance-server); review and merge the series #53–#56 first. This description lists only the changes on top of it.

Summary

The Full Featured example ("Simulated Stock Broker") is the demo people try first, but its market was a plain random walk with negative prices, every stock looked alike, and buy_stock never bought anything. It is now a small simulated market a model can actually trade on: companies with descriptions that hint at their quality, news and multi-step stories that move prices, and buy/sell that work. main.vi stays small; the engine sits behind one VI.

Before After
buy_stock answered "purchased for 0€", nothing changed buys quantity shares, refuses unknown names and orders the wallet cannot cover (isError with a reason)
prices additive random walk, down to -1400 € multiplicative, always positive; 4 clear risers, 4 clear fallers, 12 wanderers
what the model can read names and prices descriptions, sectors, news with the move of every affected stock, market summary, portfolio value
get_history_chart ignored duration shows the last duration seconds
tools 6 10 (get_stock_info, get_news, get_market_summary, sell_stock added)
a request every 200 ms for 30 s market froze (0 of 20 stocks moved) market keeps its one-second pace (all 20 moved)
repeated splits (no splits) holdings are I64 and capped at 10^18 shares; a buy past the cap is refused
out-of-range time / count (not checked) refused with a message and isError; tools/list shows the ranges
front panel MCP log (grew without limit) last 200 lines, each cut at 300 characters; request time flat at about 130 ms

Changes

  • main.vi — edited in place: Start Market.vi and Advance Market.vi replace the FGV calls; news ticker on the panel; four new tools registered. The event structure waits only until the next market second (Market Clock.vi), so steady requests no longer stop the market; Trim MCP Log.vi keeps the panel's MCP log short.
  • Market\ — new, 35 VIs: stock, event and story catalogues as data; tick steps (mood, random events, stories, earnings, price moves, splits/insolvency); helpers. Typedefs Market State.ctl, Market Mode.ctl, Stock Entry.ctl, Event Template.ctl, Story Step.ctl, News Item.ctl. Holdings are I64; a split caps a position at 10^18 shares.
  • Market\Market Clock.vi — new: keeps the time of the next market second and tells main.vi how long to wait.
  • Start Market.vi, Advance Market.vi — new; the only interface main.vi uses. Advance Market.vi simulates every tick that is due, at most 5 at once after a pause.
  • Trim MCP Log.vi — new: keeps the last 200 lines of the panel's MCP log and cuts lines over 300 characters (base64 chart images).
  • Server FGV.vi — holds the market state (modes Get, Init, Advance, Buy, Sell).
  • Tool VIs — Buy Stock.vi, Get History Chart.vi, Get Owned Stocks.vi, Get Stock Names.vi, Get Stock Prices.vi, Get Wallet.vi reworked; Sell Stock.vi, Get Stock Info.vi, Get News.vi, Get Market Summary.vi new. get_stock_prices refuses a time below 0 or older than the history, get_news a count outside 1..50, buy_stock a buy past the holding limit ("Holding limit: ... Buy at most N."); Data Entry limits make tools/list show the ranges (quantity >= 1, count 1..50, time 0..7199).
  • Prompts — Buy Any.vi, Find Best Trending Stock.vi tell the model to read descriptions, news and history before deciding. resources\Stockmarket Expert.txt — two lines on news and descriptions.
  • Removed — Add Stock Price.vi, Server Data.ctl, Server FGV Modes.ctl.
  • readme.md, docs/images/full-featured-panel.png, docs/images/full-featured-main.png — new text and pictures.

Story arcs

Takeover, product launch, audit, supply shortage, tender, change at the top, patent suit, standards vote, interest rate decision, short-seller attack. Each has a lead-up of one or two news items and an outcome drawn with odds that lean with the company's quality; at most three run at once.

Code summary

Orange numbered boxes match the numbered points. Click a picture for full size. Every changed spot and every case frame is in the detailed VI diff report; this section shows only what the latest push (52ce34c) changed in main.vi and the two VIs it added.

VI Status Change in one line
main.vi modified engine behind Start Market.vi / Advance Market.vi; waits only until the next market second; trims the MCP log
Market Clock.vi added keeps the time of the next market second: ticks due now, ms to wait
Advance Market.vi added simulates every due tick (at most 5 at once), then reads the market
Trim MCP Log.vi added last 200 lines, each cut at 300 characters
Tool VIs, Server FGV.vi, Market\ (35 VIs), typedefs, prompts modified / added the simulated market itself; see Changes and the detailed report

main.vi — modified

Starts the server, registers ten tools, two prompts and the resource, then runs an event loop. No simulation logic on this diagram.

Event loop, "Timeout" frame Right end of the loop
  1. Changed: the event timeout is no longer a constant 1000 ms but the wait until the next market second (wire along the top of the event structure, from 3). Before, every request restarted the full second, so steady requests froze the market.
  2. Advance Market.vi simulates every tick that is due and returns prices and news for the panel.
  3. New: Market Clock.vi at the end of each iteration tells the timeout how long to wait.

"MCP Events.onRpc" frame:

  1. New: Trim MCP Log.vi keeps the panel's MCP log short (base64 chart images made it grow without limit, and request time with it).

Market Clock.vi — added

  1. The tick count is compared with the time of the next market second, kept in the shift register.
  2. Ticks due: the whole seconds passed, at most 5 at once (after a pause the market catches up 5 seconds, not hours). With take due ticks? FALSE nothing is taken (read only).
  3. ms to next tick for the event timeout, 0 when a tick is due now.

Advance Market.vi — added

  1. New: Market Clock.vi says how many ticks are due.
  2. One Advance of Server FGV.vi per due tick; afterwards the market is read once for the panel (price history, news ticker).

Trim MCP Log.vi — added

  1. Splits the log into lines and keeps the last 200.
  2. Cuts every line longer than 300 characters and notes how many were left out ("... [N more characters]").

Verified

  • LabVIEW 2026 64-bit: all 50 example VIs executable, saved as 20.0 from the example project, Automatic Error Handling off.
  • Over HTTP against the running example: all ten tools; buy 3 / sell 1 with correct wallet; refusals (unknown stock, too expensive, overselling, quantity 0) answer isError with a reason; chart with duration 120; prices never at or below 0.
  • tools/test/Test-McpServer.ps1: 26 of 26 required checks, also on 52ce34c.
  • On 52ce34c, against the running example: a request every 200 ms for 30 s moved all 20 stocks (before 0); 2 x 300 requests kept the request time flat at about 130 ms (before it grew from 160 to 245 ms).
  • Trend classes over 10 runs of 600 ticks on the LabVIEW engine: neutral within ±15 % in 88 % of cases; risers all up, 68 % within +15…+40 % (misses mostly above +40 % after good stories); fallers all down, 75 % within −40…−15 %.
  • Connected Claude Code and called the tools as an MCP client.

Not verified

Known rough edges

  • Every successful result carries "error_out": {"status": false, ...}. Leaving error out out with Ignored would also drop isError on refusals, because the toolkit decides isError from that output. A toolkit change could separate the two (separate PR).
  • The panel chart shows each stock indexed to 100 over the last ten minutes, not euros (prices range from about 2 € to 800 €); tick rate is one second instead of 100 ms.
  • A fraction for an integer input is still rounded by the toolkit (quantity 1.7 buys 2); refusing it is a toolkit change (separate PR).
  • In main.vi the wire from Market Clock.vi to the event timeout runs along the top border of the event structure and is hard to see.
  • The catalogue constants show collapsed on their diagrams; their data is readable through the typedefs. New diagrams were laid out automatically.

🤖 Generated with Claude Code

The Full Featured example is the demo users try first, so it now gives
a model something real to decide on:

- 20 stocks in five sectors, each with a short description that hints
  at the company's quality without saying buy or sell. Four rise and
  four fall clearly over a few minutes; the others wander.
- Prices move multiplicatively (never zero or below) with market and
  sector mood, nervous and calm phases, and different personalities per
  stock.
- Random news (34 templates), earnings items, and ten story arcs that
  unfold over several minutes (takeover, product launch, audit, supply
  shortage, tender, change at the top, patent suit, standards vote,
  interest rate decision, short-seller attack), each with an uncertain
  outcome. News of good companies ends well more often, not always.
- New tools get_stock_info, get_news (each item with the move of every
  affected stock since), get_market_summary and sell_stock; buy_stock
  takes a quantity and refuses orders it cannot fill with a message the
  model can act on; get_owned_stocks returns holdings and their value.
- main.vi stays small: it starts the server, registers tools, prompts
  and the resource, and calls Advance Market.vi once per second. The
  engine lives in Market\ (34 small VIs, catalogues as data) with type
  definitions for the market state, the mode, stocks, events, story
  steps and news items. The panel shows the stocks indexed to 100 over
  the last ten minutes and a news ticker.

Fixed on the way: buy_stock never bought (Mode of Server FGV.vi was not
wired), prices went negative, get_history_chart ignored duration, and a
typo in the get_stock_prices description.

Add Stock Price.vi, Server Data.ctl and Server FGV Modes.ctl are
replaced by the Market\ VIs and typedefs. The readme pictures show the
new panel and diagram.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JanGoebelsBot

JanGoebelsBot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Tests

Caraya suite not rerun on this tip; Test-McpServer.ps1 26/26 required.

VI changes

Open the full VI diff

VIs: 10 modified, 48 added, 3 deleted

VI Changes Changed spot, now
Buy Any.vi
examples/Full Featured MCP Server
4
Buy Stock.vi
examples/Full Featured MCP Server
8
Find Best Trending Stock.vi
examples/Full Featured MCP Server
4
Get History Chart.vi
examples/Full Featured MCP Server
11
Get Owned Stocks.vi
examples/Full Featured MCP Server
8
Get Stock Names.vi
examples/Full Featured MCP Server
9
4 more modified VIs
VI Changes Changed spot, now
Get Stock Prices.vi
examples/Full Featured MCP Server
9
Get Wallet.vi
examples/Full Featured MCP Server
6
Server FGV.vi
examples/Full Featured MCP Server
10
main.vi
examples/Full Featured MCP Server
7
Added VIs (48)
VI Block diagram
Advance Market.vi
examples/Full Featured MCP Server
Get Market Summary.vi
examples/Full Featured MCP Server
Get News.vi
examples/Full Featured MCP Server
Get Stock Info.vi
examples/Full Featured MCP Server
Add News.vi
examples/Full Featured MCP Server/Market
Advance Stories.vi
examples/Full Featured MCP Server/Market
Append Price.vi
examples/Full Featured MCP Server/Market
Apply Event.vi
examples/Full Featured MCP Server/Market
Check Order.vi
examples/Full Featured MCP Server/Market
Corporate Actions.vi
examples/Full Featured MCP Server/Market
Draw Price Chart.vi
examples/Full Featured MCP Server/Market
Event Catalogue.vi
examples/Full Featured MCP Server/Market
Event Hits.vi
examples/Full Featured MCP Server/Market
Event Template.ctl
examples/Full Featured MCP Server/Market
Good Outcome.vi
examples/Full Featured MCP Server/Market
Indexed History.vi
examples/Full Featured MCP Server/Market
Initialise Market.vi
examples/Full Featured MCP Server/Market
Market Clock.vi
examples/Full Featured MCP Server/Market
Market Mode.ctl
examples/Full Featured MCP Server/Market
Market State.ctl
examples/Full Featured MCP Server/Market
Move Prices.vi
examples/Full Featured MCP Server/Market
News Impact.vi
examples/Full Featured MCP Server/Market
News Item.ctl
examples/Full Featured MCP Server/Market
News Ticker Text.vi
examples/Full Featured MCP Server/Market
Percent Change.vi
examples/Full Featured MCP Server/Market
Pick Other Stock.vi
examples/Full Featured MCP Server/Market
Price Return.vi
examples/Full Featured MCP Server/Market
Prices At.vi
examples/Full Featured MCP Server/Market
Publish Random Event.vi
examples/Full Featured MCP Server/Market
Random Chance.vi
examples/Full Featured MCP Server/Market
Random Integer.vi
examples/Full Featured MCP Server/Market
Report Earnings.vi
examples/Full Featured MCP Server/Market
Round To Cents.vi
examples/Full Featured MCP Server/Market
Schedule Step.vi
examples/Full Featured MCP Server/Market
Simulate Market Tick.vi
examples/Full Featured MCP Server/Market
Standard Normal.vi
examples/Full Featured MCP Server/Market
Start Story.vi
examples/Full Featured MCP Server/Market
Stock Catalogue.vi
examples/Full Featured MCP Server/Market
Stock Entry.ctl
examples/Full Featured MCP Server/Market
Stock Names.vi
examples/Full Featured MCP Server/Market
Story Catalogue.vi
examples/Full Featured MCP Server/Market
Story Step.ctl
examples/Full Featured MCP Server/Market
Trade Stock.vi
examples/Full Featured MCP Server/Market
Update Market Mood.vi
examples/Full Featured MCP Server/Market
Write Headline.vi
examples/Full Featured MCP Server/Market
Sell Stock.vi
examples/Full Featured MCP Server
Start Market.vi
examples/Full Featured MCP Server
Trim MCP Log.vi
examples/Full Featured MCP Server

Deleted: examples/Full Featured MCP Server/Add Stock Price.vi, examples/Full Featured MCP Server/Server Data.ctl, examples/Full Featured MCP Server/Server FGV Modes.ctl

Produced locally (the pull request workflow has not run: the self-hosted runner is offline). VI comparison: LabVIEW 2026 32-bit. Report for commit 52ce34c.

JanGoebelsBot and others added 5 commits November 28, 2026 21:30
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The review of the Full Featured example found four problems, which are
fixed together because they touch the same VIs (main.vi, the market
state typedef and the tool VIs):

- Holdings overflowed: a split multiplied the int32 holding by 5 and
  wrapped negative after repeated splits. Holdings are now I64 (Market
  State.ctl), a split caps a position at 10^18 shares, and a buy that
  would pass the cap is refused with "Holding limit: ... Buy at most N."
  get_owned_stocks and get_stock_info report the I64 quantity.
- The market froze under steady requests, because it only advanced in
  the event structure's timeout, which every request restarts. The new
  Market Clock.vi keeps the time of the next market second; main.vi
  waits only until then, and Advance Market.vi simulates every tick that
  is due (at most 5 at once after a pause). Measured with a request every
  200 ms for 30 s: before 0 of 20 stocks moved, now all 20.
- Inputs out of range were answered silently: get_stock_prices refuses a
  time below 0 or older than the history, get_news refuses a count
  outside 1..50, both with a clear message and isError. Data Entry limits
  make tools/list show the ranges (quantity >= 1, count 1..50, time
  0..7199). A fraction for an integer input is still rounded by the
  toolkit (quantity 1.7 buys 2); refusing it is a toolkit change.
- The MCP log on the front panel grew without limit, base64 chart images
  included. The new Trim MCP Log.vi keeps the last 200 lines and cuts
  lines over 300 characters. Request time is now flat (about 130 ms over
  2 x 300 requests, before growing from 160 to 245 ms).

All other library members were re-saved by LabVIEW after the typedef
change; they have no functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JanGoebelsBot

Copy link
Copy Markdown
Collaborator Author

Update: review fixes pushed

New commit: 52ce34c (and the merges 5c67679, e5726e1, 420c66d, 0f1cf3c of the review fixes of #53 to #56).

  • Holdings no longer overflow: a split multiplied the int32 holding by 5 and wrapped negative after repeated splits. Holdings are now I64 (Market State.ctl), a split caps a position at 10^18 shares, and a buy past the cap is refused with "Holding limit: ... Buy at most N." get_owned_stocks and get_stock_info report the I64 quantity.
  • The market keeps moving under steady requests: it only advanced in the event structure's timeout, which every request restarts. The new Market Clock.vi keeps the time of the next market second; main.vi waits only until then, and Advance Market.vi simulates every tick that is due (at most 5 at once after a pause). With a request every 200 ms for 30 s: before 0 of 20 stocks moved, now all 20.
  • Inputs out of range are refused: get_stock_prices refuses a time below 0 or older than the history, get_news a count outside 1..50, both with a message and isError. Data Entry limits make tools/list show the ranges (quantity >= 1, count 1..50, time 0..7199). A fraction for an integer input is still rounded by the toolkit (quantity 1.7 buys 2); refusing it is a toolkit change.
  • The front panel log stays small: the new Trim MCP Log.vi keeps the last 200 lines and cuts lines over 300 characters (base64 chart images included). Request time is now flat, about 130 ms over 2 x 300 requests (before: growing from 160 to 245 ms).
  • All other library members were only re-saved by LabVIEW after the typedef change.
  • Review report comment, detailed VI diff and the description (Changes, Code summary, Verified) are refreshed for 52ce34c.

Tests: Caraya suite not rerun on this tip; Test-McpServer.ps1 26/26 required.

Still open: the Caraya run on this tip; fractional integer inputs (toolkit change, separate pull request).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant