Trading task guide

Backtest a fixed MSFT strategy with VS Code Copilot

Define a MSFT price/SMA experiment, submit one historical test and inspect returned status, history and a frozen unseen window.

As of 2026-10-10

Example asset
MSFT
Evidence
Proposed experiment inputs
Account mode
Historical simulation

1. Connect the tools in your workspace

Open NexusTrade Developers and choose Add to VS Code, or run MCP: Add Server from the Command Palette. Select the hosted HTTP server and save a portable .mcp.json at the workspace root. Trust/start the server, complete NexusTrade OAuth and open Chat > Configure Tools to enable the required tools.

This is the Copilot MCP connection. The Codex extension has a separate setup. Existing .vscode/mcp.json uses servers rather than the portable mcpServers object below. Inspect the server error and pending sign-in if tools fail to appear.

Portable workspace configuration

json
{
  "mcpServers": {
    "nexustrade": {
      "type": "http",
      "url": "https://nexustrade.io/api/mcp"
    }
  }
}

2. Check the returned account tools

The result is a paginated object with portfolios, total and totalPages. Walk pages when necessary. A new account may return an empty list. Keep authentication errors and missing results separate. Do not infer a successful connection from a tool list alone.

text
Use fetch_portfolios with the JSON below. Read a portfolioId returned by that call with get_portfolio, setting its portfolio_id argument to the same value. Compare the name, type and strategies with the intended NexusTrade account. If no portfolio exists, keep the empty result and continue to the new draft preview below. Do not create anything during this check.

{
  "include_paper": true,
  "include_live": false,
  "include_chat_portfolios": true,
  "include_positions": false,
  "limit": 20,
  "page": 1
}

Confirm permission for this task

Discover build_portfolio, create_portfolio, get_portfolio and backtest_portfolio, query_backtest_status and query_backtest_history in the current connection. Check that the granted app actions allow this task before submitting anything. A plugin listing or successful read does not grant write access. Keep approvals enabled for saving and account changes.

3. Freeze this proposed rule before submitting anything

This teaching example uses MSFT only, no leverage and a $10,000 starting balance. At each daily evaluation, compare Price with its 200-period SimpleMovingAverage using a Day window. Target 25% of portfolio value in MSFT when price is above the average, 0% when below it, and keep the prior target at equality. Leave the rest in cash. Review the returned strategy JSON for these rules and for repeated-buy protection.

Use 2021-01-01 through 2024-12-31 for the first historical window. Keep 2025-01-01 through 2025-12-31 unopened until the exact rule and evaluation criteria are frozen. The dates and allocation are proposed inputs, not a performance result. Choosing after seeing that period would make it retrospective validation and would no longer test an unseen period.

4. Author and read back a new candidate

Use structured strategy objects after reviewing them. Read condition/action fields rather than relying on a strategy name. A saved chat candidate is a draft, not a running paper portfolio. For VS Code, keep the exact returned configuration in the proposed JSON file before reviewing the diff.

Read get_portfolio structured output under portfolio: portfolioId, type, isActive, strategies, initialValue and deployment. Resolve a mismatch before using that ID in another operation.

text
Draft a NEW chat portfolio named MSFT SMA200 25pct v1 with initialValue 10000 and dividendPolicy reinvest. Author two explicit strategies for the daily MSFT Price versus 200-Day SimpleMovingAverage target rule above, capped at 25% long exposure with remaining cash. Show complete condition and action objects, sizing, evaluation schedule and orderExecution before saving. Call build_portfolio with the full structured draft first. Inspect valid, the canonical portfolio and every reported issue. Fix issues and repeat the preview; it does not persist a candidate. After I approve the definition, use create_portfolio structured name, initialValue, dividendPolicy and strategies fields. Read the returned chat portfolio with get_portfolio using its actual portfolio_id. Retain research/MSFT.md, strategies/msft-sma-v1.json and experiments/msft-sma-v1.md in your workspace. Stop after saving; do not backtest or deploy yet.

5. Review the inputs, then submit one backtest

Replace the ID placeholder with the exact candidate ID returned by your account. Review this backtest_portfolio argument object before approving submission. Zero stock commissions are an explicit teaching assumption, not a claim about brokerage costs. Change the fee contract if your experiment needs commissions.

Record indicator warmup and signal/fill timing from the returned rules and engine behavior. A daily test does not establish intraday fills, spread/slippage, liquidity or brokerage availability. Reinvestment makes the dividend assumption explicit for the benchmark comparison.

json
{
  "portfolio_id": "REPLACE_WITH_RETURNED_CHAT_ID",
  "start_date": "2021-01-01",
  "end_date": "2024-12-31",
  "interval": "Day",
  "initial_value": 10000,
  "baseline_symbol": "MSFT",
  "generate_events": false,
  "dividend_policy": "reinvest",
  "fee_config": {
    "Stock": {
      "amount": 0,
      "type": "dollars"
    }
  }
}

6. Recover the accepted job and inspect its history

Record the accepted backtest ID from the returned response text with its status and interval. A structured backtest_id field is not guaranteed. Call query_backtest_status with {"backtest_id": the returned ID}. PENDING or RUNNING means keep that ID and poll it. ERROR needs the reported failure resolved. Read completed statistics and warnings, then query_backtest_history with the same backtest_id, page:1 and page_size:500; continue pages for the chosen period.

If a response is interrupted after submission, recover the accepted job from the account or recorded operation before considering another submission. Do not launch a duplicate because the history is empty while the job runs. Preserve returned IDs in the experiment record.

value and comparisonValueCandidate and benchmark share the same dates/capital
cash and positionValueExposure stays within the saved rule
reservedCollateralNull means unrecorded, not zero
Status and warningsOnly report completed data, with failures/missing coverage retained

7. Run the frozen unseen window once

After reviewing and freezing the candidate, submit a separate backtest with the same saved rule, capital, Day interval, benchmark and cost/dividend assumptions, changing only dates to 2025-01-01 and 2025-12-31. Retain both IDs. Inspect drawdown, exposure, activity, missing data and benchmark history before comparing returns. Editing after reading this window creates a new candidate that needs another genuinely unseen evaluation.

The tool sequence

Inspect the discovered inputs before submitting a call. For a new candidate, validate and save it first; for a saved candidate, start with get_portfolio. Record the portfolio and backtest identifiers returned by the account tools.

Validate a new candidatebuild_portfolioCanonical configuration and component issues; nothing is saved
Save the validated draftcreate_portfolioUse the reviewed configuration and retain the returned chat portfolio ID
Read the saved bookget_portfolioExact strategies, action sizing, and portfolio identity
Submit the historical testbacktest_portfolioExplicit dates, interval, capital and benchmark
Poll the same operationquery_backtest_statusTerminal state and warnings; do not resubmit while running
Inspect the curvequery_backtest_historyHistorical values for the returned backtest_id
Compare candidatescompare_backtestsIdentical period and assumptions, with activity and risk

Continue exploring