From d882b10ec0e119e3663ad8135c79ba12018ddf93 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 7 Feb 2025 15:57:21 -0500 Subject: [PATCH] Fix dictionary access. --- .../Generator/Momentum/ActivePositions.cs | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/MarketDataLib/Generator/Momentum/ActivePositions.cs b/MarketDataLib/Generator/Momentum/ActivePositions.cs index c777432..24d22d0 100644 --- a/MarketDataLib/Generator/Momentum/ActivePositions.cs +++ b/MarketDataLib/Generator/Momentum/ActivePositions.cs @@ -1,12 +1,7 @@ -using MarketData.DataAccess; -using MarketData.MarketDataModel; -using MarketData.Utils; +using MarketData.Utils; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; namespace MarketData.Generator.Momentum { @@ -17,11 +12,11 @@ namespace MarketData.Generator.Momentum } public double GetExposure() { - int count=Count; double exposure=0.00; - for(int slotIndex=0;slotIndex keys = new List(Keys); + for(int index=0;index positions=this[slotIndex]; + List positions=this[keys[index]]; if(null==positions||0==positions.Count)continue; exposure+=(from Position position in positions select position.Exposure).Sum(); } @@ -62,6 +57,25 @@ namespace MarketData.Generator.Momentum } return -1; } + + public bool Remove(Position searchPosition) + { + List keys = new List(this.Keys); + for (int index = 0; index < keys.Count; index++) + { + Positions positions = this[keys[index]]; + foreach (Position slotPosition in positions) + { + if (slotPosition == searchPosition) + { + positions.Remove(searchPosition); + return true; + } + } + } + return false; + } + public Positions GetPositions() { Positions positionsCollection=new Positions(); @@ -95,9 +109,10 @@ namespace MarketData.Generator.Momentum { int count=Count; double marketValue=0.00; - for(int slotIndex=0;slotIndex keys=new List(this.Keys); + for(int index=0;index positions=this[slotIndex]; + List positions=this[keys[index]]; if(null==positions||0==positions.Count)continue; marketValue+=(from Position position in positions select position.MarketValue).Sum(); } @@ -108,9 +123,11 @@ namespace MarketData.Generator.Momentum int count=Count; double marketValue=0.00; double exposure=0.00; - for(int slotIndex=0;slotIndex keys = new List(this.Keys); + for(int index=0;index positions=this[slotIndex]; + List positions=this[keys[index]]; if(null==positions||0==positions.Count)continue; exposure+=(from Position position in positions select position.Exposure).Sum(); marketValue+=(from Position position in positions select position.MarketValue).Sum(); @@ -126,9 +143,10 @@ namespace MarketData.Generator.Momentum } public void Display() { - for(int slotIndex=0;slotIndex keys = new List(this.Keys); + for(int index=0;index ToNVPCollections() { - List slots=new List(Keys); + List keys=new List(Keys); List nvpCollectionsList=new List(); - foreach(int slot in slots) + for(int index=0;index