internal void AddPosition(Position pos) {//build position collections incrementally if (pos.TradeType == TradeType.Buy) { LongPositions.Add(pos); } else { ShortPositions.Add(pos); } }
internal void UpdateAll() { foreach (var pos in CompositePositions) { //in case CompositePositions is null such as when building via AddPosition() if (CompositePositions == null) { CompositePositions = (List <Position>)ShortPositions.Concat(LongPositions); } //all positions in compositePositions list should be of same symbol if (this.Symbol == null) { this.Symbol = pos.SymbolCode; } if (this.Symbol != pos.SymbolCode) { throw new InvalidOperationException("symbol mismatch in compositePos. list"); } //add pos to approp. list, sum vol & avg. prc. if (pos.TradeType == TradeType.Buy) { LongPositions.Add(pos); LongExposureVol += pos.Volume; VolWdEntryPrcLong += pos.EntryPrice * (double)pos.Volume; } else { ShortPositions.Add(pos); ShortExposureVol += pos.Volume; VolWdEntryPrcShort += pos.EntryPrice * (double)pos.Volume; } //foreach } VolWdEntryPrcLong /= LongExposureVol; VolWdEntryPrcShort /= ShortExposureVol; //UpdateAll() }