Fix dictionary access.
This commit is contained in:
@@ -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<count;slotIndex++)
|
||||
List<int> keys = new List<int>(Keys);
|
||||
for(int index=0;index<keys.Count;index++)
|
||||
{
|
||||
List<Position> positions=this[slotIndex];
|
||||
List<Position> 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<int> keys = new List<int>(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<count;slotIndex++)
|
||||
List<int> keys=new List<int>(this.Keys);
|
||||
for(int index=0;index<keys.Count;index++)
|
||||
{
|
||||
List<Position> positions=this[slotIndex];
|
||||
List<Position> 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<count;slotIndex++)
|
||||
|
||||
List<int> keys = new List<int>(this.Keys);
|
||||
for(int index=0;index<keys.Count;index++)
|
||||
{
|
||||
List<Position> positions=this[slotIndex];
|
||||
List<Position> 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<Count;slotIndex++)
|
||||
List<int> keys = new List<int>(this.Keys);
|
||||
for(int index=0;index<keys.Count;index++)
|
||||
{
|
||||
Positions positions=this[slotIndex];
|
||||
Positions positions=this[keys[index]];
|
||||
DateTime purchaseDate=(from Position position in positions select position.PurchaseDate).Distinct().FirstOrDefault();
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("******************* B U Y S F O R {0} *****************",Utility.DateTimeToStringMMHDDHYYYY(purchaseDate)));
|
||||
positions.Display();
|
||||
@@ -145,12 +163,12 @@ namespace MarketData.Generator.Momentum
|
||||
}
|
||||
public List<NVPCollections> ToNVPCollections()
|
||||
{
|
||||
List<int> slots=new List<int>(Keys);
|
||||
List<int> keys=new List<int>(Keys);
|
||||
List<NVPCollections> nvpCollectionsList=new List<NVPCollections>();
|
||||
foreach(int slot in slots)
|
||||
for(int index=0;index<keys.Count;index++)
|
||||
{
|
||||
Positions positions=this[slot];
|
||||
SlotPositions slotPositions=new SlotPositions(slot,positions);
|
||||
Positions positions=this[keys[index]];
|
||||
SlotPositions slotPositions=new SlotPositions(keys[index],positions);
|
||||
NVPCollections nvpCollections=slotPositions.ToNVPCollections();
|
||||
nvpCollectionsList.Add(nvpCollections);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user