בס״ד

MIS ARCHITECT: MASTER CONTEXT & DEVELOPER RULES

docs/MIS_PHASE2_BLUEPRINT.md · last changed (pre-VM history) · rendered from GitHub master

MIS ARCHITECT: MASTER CONTEXT & DEVELOPER RULES

Phase 2 Blueprint — drafted Session 8 (2026-04-15)

🪦 SUPERSEDED 2026-04-28 by docs/MIS_FSE_ARCHITECTURE.md (FSE = FINAL_STATE_ENGINE arch). FSE doc explicitly supersedes Phase 2 — see FSE doc §11. Phase 2 prescribed a Yahoo Finance + JS-only Microservices rewrite that diverged into the Architect V11 sandbox sheet — that diverged sheet is what creates the surface conflicts FSE is built to solve. Read FSE doc first for current MIS architecture. This file kept as historical context for the Microservices intent.


1. System Philosophy & Architecture

MIS Architect is a quantitative, market-aware technical screening engine designed for 3:00 PM Power Hour execution. It operates on a Microservices Architecture.


2. The Math Engine (Phase 1.5 — COMPLETED)

All logic calculated in-memory via JavaScript arrays using Yahoo Finance REST API.

Reference code: V10.5 Perfect Presentation engine (ingested Session 8)


3. The Reality Layer (Phase 2 — CURRENT OBJECTIVE)

Transition from paper money to broker-aware logic. Implement legacy mechanisms without cell formulas.

3a. Trade Planner (Open Positions DB)

Tab: Trade_Planner
Columns: Date | Account (Schwab/Fidelity) | Ticker | Side | Entry | Stop | Target | Shares | Status
- Account values: Invest n Save (Z29720600) | Joint Brok (Z29835692)
- Youth account Z27934073 excluded at ingestion
- Script builds tab if missing; never overwrites existing rows

3b. Holdings PnL Tracker

Tab: Holdings
- Reads Trade_Planner for open positions
- Fetches live price via existing fetchSingleTickerData() API call (no GOOGLEFINANCE)
- Writes static arrays: Ticker | Account | Shares | Entry | Live Price | Unrealized $ | Unrealized %
- Refreshes on each Power Hour run

3c. Position Overlap Block (TWO GATES)

Gate 1: If ticker already in Trade_Planner at max allocation → Hard Block new setup for that ticker
Gate 2: Total open risk across ALL positions must not exceed 6% of portfolio (6 × $250 = $1,500 total book risk)
- Helper: isTickerHeld_(ticker, tradePlanner) → returns boolean
- Called in evaluateTicker() before SACS calculation

3d. Bracket Order Playbook

Email output format per trade:

BUY LMT  [TICKER]  [SHARES] shares @ $[ENTRY]
STOP     $[STOP]   (1.3 ATR = $[STOP_DISTANCE])
TARGET   $[TARGET] (2.5R = $[TARGET_GAIN])
RISK     $[DOLLAR_RISK] ([RISK_PCT]% of portfolio)

3e. Earnings Quarter-Roll (Finnhub)


4. New Module: portfolio-sync.js

Standalone Apps Script file to add alongside existing engine. Functions:

buildTradePlannerTab(ss)        // Auto-creates clean Trade_Planner if missing
syncHoldingsPnL(ss)             // Reads Trade_Planner, fetches live prices, writes Holdings
isTickerHeld_(ticker, ss)       // Returns true if ticker in Trade_Planner (open status)
getTotalBookRisk_(ss)           // Returns sum of all open position dollar risks
buildEarningsOverlay(tickers)   // Fetches Finnhub dates, rolls past dates forward 91 days

Integration point in main engine — in evaluateTicker(), after lethalBlocks init:

if (isTickerHeld_(ticker, ss)) lethalBlocks.push('ALREADY_HELD');
if (getTotalBookRisk_(ss) >= CONFIG.portfolioSize * 0.06) lethalBlocks.push('BOOK_RISK_MAX');

5. Strict AI Developer Directives

  1. Never break Phase 1.5: Do not alter core SACS math, risk sizing, or HTML email output
  2. Zero hardcoding of API keys: Use PropertiesService.getScriptProperties() for Finnhub, Schwab tokens
  3. No 2D array mismatches: All sheet write arrays must be perfectly rectangular
  4. No PDF exports until Playbook_V2 tab logic is rebuilt (currently shows all tickers as LEAN IN regardless of signal)
  5. Account masking in all outputs: Display as Invest n Save (...0600) never raw account numbers

6. Known Bugs Fixed This Session (Session 8)

Bug Fix
VIX shows 1899 in trajectory misReadVIXHistory_() now handles Date objects in Slot column
Playbook PDFs show all tickers as LEAN IN MAX PDF attachments removed from 2:05 PM and 3:00 PM emails
92 Authorized Trades (no portfolio gate) V10.5 engine has maxLeanIn:5, maxStarter:5 caps
SACS all at 100 V10.5 has layered adjustments + relStrength30 tiebreaker

7. Session Handoff Prompt (for next Claude session)

Role: Lead Systems Architect, Senior Google Apps Script Developer.
Project: MIS Architect Phase 2 — The Reality Layer.
Files to attach:
1. MIS_PHASE2_BLUEPRINT.md — architectural rules (read first)
2. emailDailySnapshot.js — current working Phase 1.5 engine (do not break core math)
3. Code.js — legacy tab builder (extract Trade_Planner, Holdings, Finnhub logic only)

Task: Write portfolio-sync.js — a modular Apps Script file that:
1. Auto-builds Trade_Planner tab for manual entry of open trades (Schwab/Fidelity)
2. Auto-builds Holdings tab reading Trade_Planner, uses fetchSingleTickerData() for live prices, writes static PnL arrays (no GOOGLEFINANCE)
3. Provides isTickerHeld_() and getTotalBookRisk_() helpers for overlap/book-risk gating
4. Provides buildEarningsOverlay() with Finnhub + 91-day quarter-roll fallback

Output: portfolio-sync.js code + exact insertion points in main engine.

Source trail · docs/MIS_PHASE2_BLUEPRINT.md @ master · rendered 2026-07-02 7:23 PM EDT by scripts/build-docs.py · the .md in the repo is the truth; this page is the phone-readable view