using MarketData.Utils; using System; using System.Collections.Generic; using System.Linq; namespace MarketData.Generator.MGSHMomentum { public class MGSHActivePositions : Dictionary { public MGSHActivePositions() { } public int GetMaxSlotNumber() { List keys = new List(Keys); if(0 == keys.Count) { return -1; // if there are no slots then return -1 } return keys.Max(); } public int GetCount() { int positionCount=0; List keys = new List(Keys); for(int index=0;index positions=this[keys[index]]; if(null==positions||0==positions.Count)continue; positionCount+=positions.Count; } return positionCount; } public double GetExposure() { double exposure=0.00; List keys = new List(Keys); for(int index=0;index positions=this[keys[index]]; if(null==positions||0==positions.Count)continue; exposure+=(from MGSHPosition position in positions select position.Exposure).Sum(); } return exposure; } public List GetSymbols() { return SymbolsHeld(); } public MGSHPosition FindPosition(String symbol,DateTime purchaseDate) { MGSHPosition foundPosition=null; List keys=new List(this.Keys); for(int index=0;index keys=new List(this.Keys); for(int index=0;index keys = new List(this.Keys); for (int index = 0; index < keys.Count; index++) { MGSHPositions positions = this[keys[index]]; foreach (MGSHPosition slotPosition in positions) { if (slotPosition == searchPosition) { positions.Remove(searchPosition); return true; } } } return false; } public MGSHPositions GetPositions() { MGSHPositions positionsCollection=new MGSHPositions(); List keys=new List(this.Keys); Dictionary symbols=new Dictionary(); for(int index=0;index SymbolsHeld() { List keys = new List(this.Keys); Dictionary symbols = new Dictionary(); for (int index = 0; index < keys.Count; index++) { MGSHPositions positions = this[keys[index]]; foreach (MGSHPosition position in positions) { if (!symbols.ContainsKey(position.Symbol)) symbols.Add(position.Symbol, position.Symbol); } } return new List(symbols.Keys); } public double GetMarketValue() { double marketValue=0.00; List keys=new List(this.Keys); for(int index=0;index positions=this[keys[index]]; if(null==positions||0==positions.Count)continue; marketValue+=(from MGSHPosition position in positions select position.MarketValue).Sum(); } return marketValue; } public double GetGainLoss() { double marketValue=0.00; double exposure=0.00; List keys = new List(this.Keys); for(int index=0;index positions=this[keys[index]]; if(null==positions||0==positions.Count)continue; exposure+=(from MGSHPosition position in positions select position.Exposure).Sum(); marketValue+=(from MGSHPosition position in positions select position.MarketValue).Sum(); } return marketValue-exposure; } public double GetGainLossPercent() { double exposure=GetExposure(); double marketValue=GetMarketValue(); if(0.00==exposure)return exposure; return (marketValue-exposure)/exposure; } public void Display() { List keys = new List(this.Keys); for(int index=0;index ToNVPCollections() { List keys=new List(Keys); List nvpCollectionsList=new List(); for(int index=0;index