Skip to content

Overview

A strategy in Virtufin is the pair of morphisms (decide, execute) modelled coalgebraically (see the behaviour spec). This devkit provides the decide bridge and its supporting types.

In plain terms: a strategy watches the market and its own current holdings, and on each new piece of market data decides whether to submit an order. decide is the "watch and decide" half; execute is the separate, downstream half that actually places or simulates the order (a different process, connected by the pubsub-topics spec's trading events — not a function call in the same process). This devkit only implements decide; it hands off to execute by publishing an "Order submitted" event rather than calling anything directly.

Before wiring a strategy to real capital (act), see Strategy Author Guide §4: unit-test Step directly, backtest against a hyp.BACKTEST world, and shadow-trade with an ObserveOnlyExecutor before ever setting strategyworld = act. Nothing in this devkit certifies a strategy as safe to trade — it only provides the plumbing.

The coalgebra

decide is an IDecide<TState, TMarket, TPortfolio, TAction>:

public interface IDecide<TState, TMarket, TPortfolio, TAction>
    : IProcess<TState, (TMarket, TPortfolio), TAction[]>
    where TState : IStrategyState
    where TMarket : IMarketEvent
    where TPortfolio : IPortfolioState
    where TAction : ITradeAction
{ }
  • TState — hidden indicator state (the strategy owns it; the driver threads it, never the caller).
  • TMarket — the market observation (raw feed events or derived signals like candles, VWAP, volatility).
  • TPortfolio — the folded holdings the strategy observes — the loop's feedback edge: fills fold into positions, positions feed the next decision.
  • TAction[] — zero or more intents emitted per observation.

The two packages

Package Role Depends on
Virtufin.Strategy.DevKit runtime: StrategyWorkerBase, ConfigResolution, PortfolioState/PortfolioAlgebra .Events, Core, Base, Worker.DevKit
Virtufin.Strategy.DevKit.Events wire mapping: mappers, enrichment, AmountJson Core, Base

Indicators (SimpleMovingAverage<TTime,TValue>) live in Virtufin.Base.Behaviour (virtufin-dotnet), not in a strategy-devkit package.

The bridge (StrategyWorkerBase) implements the DevKit worker contract (IWorker.ProcessAsync(CloudEvent)) on top of any IDecide, dispatching each CloudEvent by type, folding position events into the portfolio, stepping market events through decide, and encoding the resulting actions into a response CloudEvent.

Next: Strategy Author Guide.