mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-04 16:41:19 +00:00
Holding a book means carrying what it has taken on until carrying it costs more than closing it. Working out how much is uncovered, and producing the order that covers it, is the same arithmetic wherever the book is kept - and it was written inside one server's order router. The hedger holds, per instrument, what the book has taken on, what is actually held against it, and what is already on its way; the gap between them is what is uncovered. A gap within both the size and the money cap is carried. Crossing either closes the gap in full, not the excess, and the money cap measures the gap's worth rather than replacing the size cap. The gap is reserved when the order is produced rather than when a venue answers, so the next reading of the same position cannot send a second order for it, and the reservation is released when that order ends. An instrument nothing has been stated about yet is not hedged: there is nothing to subtract from. What stayed with the server is what was about that server: marking an order so its reports read as the broker's own, deciding whether hedging is on at all, refusing to hedge into the very book being hedged, and the sending itself. One of those was hiding inside the arithmetic - the mark was applied in the same return that built the order - so the hedger returns a plain order and the caller stamps it. Four things the move surfaced were wrong where it came from, and are fixed here rather than carried over. Both sides wrote one price. What the book took on and what was bought to cover it are worth different things, and whichever spoke last decided what the uncovered gap was measured at. The gap is the part of the exposure nothing covers yet, so it is worth what the exposure is worth; what the hedging portfolio paid prices the part already covered, and the two are held apart. A price stated as zero could not erase one already known, so a price that had stopped being true went on firing the money cap. A zero now says nothing is known, which is what it means. An instrument the limit table never names is not remembered at all. The table is read on every row, so one named later is hedged from the next row on. And the worst: a gap was reserved when its order went out and released only by that order's completion report. A lost report did not merely stop the instrument being hedged again - the reservation stayed while the position report brought the same fill in as held, so the same volume was counted twice and the gap flipped sign, and the hedger answered a covered position by selling it. What is held is stated every time it changes, and a holding that moved the way a hedge was sent is that hedge arriving; it releases that much reservation, oldest first, and only that much. Movement against the reservations releases nothing, because it came from elsewhere.
24 lines
883 B
C#
24 lines
883 B
C#
namespace StockSharp.Algo.PositionManagement;
|
|
|
|
/// <summary>
|
|
/// How far the uncovered net position in one instrument may run before <see cref="NetExposureHedger"/>
|
|
/// closes it.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The two caps are read together: whichever of them is crossed closes the whole uncovered position,
|
|
/// so <see cref="MaxNotional"/> caps <see cref="MaxVolume"/> rather than replacing it.
|
|
/// </remarks>
|
|
public sealed class NetExposureLimit
|
|
{
|
|
/// <summary>
|
|
/// The absolute volume of the uncovered position that may be carried. Anything past it is closed.
|
|
/// </summary>
|
|
public decimal MaxVolume { get; set; }
|
|
|
|
/// <summary>
|
|
/// What the uncovered position may be worth before it is closed, or <see langword="null"/> when
|
|
/// the instrument is capped by volume alone. Answers only while a price is known.
|
|
/// </summary>
|
|
public decimal? MaxNotional { get; set; }
|
|
}
|