Repository navigation
Turn the Full Featured example into a believable simulated stock market - #57
Open
JanGoebelsBot wants to merge 6 commits into
Open
JanGoebelsBot wants to merge 6 commits into
JanGoebelsBot wants to merge 6 commits into
Conversation
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>
Collaborator
Author
TestsCaraya suite not rerun on this tip; VI changesVIs: 10 modified, 48 added, 3 deleted 4 more modified VIsAdded VIs (48)Deleted: 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. |
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>
Collaborator
Author
Update: review fixes pushedNew commit: 52ce34c (and the merges 5c67679, e5726e1, 420c66d, 0f1cf3c of the review fixes of #53 to #56).
Tests: Caraya suite not rerun on this tip; Still open: the Caraya run on this tip; fractional integer inputs (toolkit change, separate pull request). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


























































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_stocknever 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.vistays small; the engine sits behind one VI.buy_stockquantityshares, refuses unknown names and orders the wallet cannot cover (isErrorwith a reason)get_history_chartdurationdurationsecondsget_stock_info,get_news,get_market_summary,sell_stockadded)time/countisError;tools/listshows the rangesChanges
main.vi— edited in place:Start Market.viandAdvance Market.vireplace 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.vikeeps 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. TypedefsMarket 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 tellsmain.vihow long to wait.Start Market.vi,Advance Market.vi— new; the only interfacemain.viuses.Advance Market.visimulates 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).Buy Stock.vi,Get History Chart.vi,Get Owned Stocks.vi,Get Stock Names.vi,Get Stock Prices.vi,Get Wallet.vireworked;Sell Stock.vi,Get Stock Info.vi,Get News.vi,Get Market Summary.vinew.get_stock_pricesrefuses a time below 0 or older than the history,get_newsa count outside 1..50,buy_stocka buy past the holding limit ("Holding limit: ... Buy at most N."); Data Entry limits maketools/listshow the ranges (quantity >= 1, count 1..50, time 0..7199).Buy Any.vi,Find Best Trending Stock.vitell the model to read descriptions, news and history before deciding.resources\Stockmarket Expert.txt— two lines on news and descriptions.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
main.viStart Market.vi/Advance Market.vi; waits only until the next market second; trims the MCP logMarket Clock.viAdvance Market.viTrim MCP Log.viServer FGV.vi,Market\(35 VIs), typedefs, promptsmain.vi— modifiedStarts the server, registers ten tools, two prompts and the resource, then runs an event loop. No simulation logic on this diagram.
Advance Market.visimulates every tick that is due and returns prices and news for the panel.Market Clock.viat the end of each iteration tells the timeout how long to wait."MCP Events.onRpc" frame:
Trim MCP Log.vikeeps the panel's MCP log short (base64 chart images made it grow without limit, and request time with it).Market Clock.vi— addedtake due ticks?FALSE nothing is taken (read only).ms to next tickfor the event timeout, 0 when a tick is due now.Advance Market.vi— addedMarket Clock.visays how many ticks are due.AdvanceofServer FGV.viper due tick; afterwards the market is read once for the panel (price history, news ticker).Trim MCP Log.vi— addedVerified
isErrorwith a reason; chart withduration120; prices never at or below 0.tools/test/Test-McpServer.ps1: 26 of 26 required checks, also on 52ce34c.Not verified
src/ortests/changed in this pull request (the merged base was run on Pass the official MCP conformance suite: completion, resource URIs, example server #56: 77 of 77, 304 assertions).Known rough edges
"error_out": {"status": false, ...}. Leavingerror outout withIgnoredwould also dropisErroron refusals, because the toolkit decidesisErrorfrom that output. A toolkit change could separate the two (separate PR).main.vithe wire fromMarket Clock.vito the event timeout runs along the top border of the event structure and is hard to see.🤖 Generated with Claude Code