public static void AddToPosition(this SystemState systemState, int positionIndex, DateTime ts, float price, float volume, Signal signal, ISlippage slippage, ICommission commission) { Position pos = systemState.PositionsActive[positionIndex]; systemState.Close(positionIndex, ts, price, slippage, commission); if (pos.Volume + volume > 0) { float openPrice = systemState.CalculateSlippageOpen(slippage, ts, signal, price); systemState.Open(signal.Stock, pos.Direction, ts, openPrice, pos.Volume + volume, systemState.CalculateCommission(commission, signal, openPrice), signal.DataRange, signal.IntradayInterval, signal); } }
public static void Close(this SystemState systemState, int positionIndex, DateTime ts, float price, ISlippage slippage, ICommission commission) { float closePrice = systemState.CalculateSlippageClose(slippage, ts, positionIndex, price); systemState.Close(positionIndex, ts, closePrice, systemState.CalculateCommission(commission, positionIndex, closePrice)); }
public static float CalculateCommission(this SystemState systemState, ICommission commission, Signal signal, float price) { return(systemState.CalculateCommission(commission, signal.Stock.Type, signal.Volume, price)); }
public static void Open(this SystemState systemState, DateTime ts, PositionDir dir, float price, float volume, StockDefinition stock, Signal signal, ISlippage slippage, ICommission commission) { float openPrice = systemState.CalculateSlippageOpen(slippage, stock.Type, ts, signal.Direction, price); systemState.Open(stock, dir, ts, openPrice, volume, systemState.CalculateCommission(commission, stock.Type, signal.Volume, openPrice), signal.DataRange, signal.IntradayInterval, signal); }
public static float CalculateCommission(this SystemState systemState, ICommission commission, int positionIndex, float price) { return(systemState.CalculateCommission(commission, systemState.PositionsActive[positionIndex].Stock.Type, systemState.PositionsActive[positionIndex].Volume, price)); }