Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasoukhov committed Aug 26, 2015
1 parent e4d6562 commit 0708b22
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Algo/Testing/ExecutionLogConverter.cs
Expand Up @@ -153,6 +153,7 @@ private IEnumerable<ExecutionMessage> GetDiff(DateTime time, IEnumerable<QuoteCh
QuoteChange currTo = null;

var mult = side == Sides.Buy ? -1 : 1;
bool? isSpread = null;

using (var fromEnum = from.GetEnumerator())
using (var toEnum = to.GetEnumerator())
Expand All @@ -164,7 +165,10 @@ private IEnumerable<ExecutionMessage> GetDiff(DateTime time, IEnumerable<QuoteCh
if (!fromEnum.MoveNext())
canProcessFrom = false;
else
{
currFrom = fromEnum.Current;
isSpread = isSpread == null;
}
}

if (canProcessTo && currTo == null)
Expand All @@ -187,7 +191,7 @@ private IEnumerable<ExecutionMessage> GetDiff(DateTime time, IEnumerable<QuoteCh
else
{
//diff.Add(currTo.Clone());
AddExecMsg(diff, time, currTo, currTo.Volume);
AddExecMsg(diff, time, currTo, currTo.Volume, false);
currTo = null;
}
}
Expand All @@ -198,7 +202,7 @@ private IEnumerable<ExecutionMessage> GetDiff(DateTime time, IEnumerable<QuoteCh
//var clone = currFrom.Clone();
//clone.Volume = -clone.Volume;
//diff.Add(clone);
AddExecMsg(diff, time, currFrom, -currFrom.Volume);
AddExecMsg(diff, time, currFrom, -currFrom.Volume, isSpread.Value);
currFrom = null;
}
else
Expand All @@ -210,23 +214,23 @@ private IEnumerable<ExecutionMessage> GetDiff(DateTime time, IEnumerable<QuoteCh
//var clone = currTo.Clone();
//clone.Volume -= currFrom.Volume;
//diff.Add(clone);
AddExecMsg(diff, time, currTo, currTo.Volume - currFrom.Volume);
AddExecMsg(diff, time, currTo, currTo.Volume - currFrom.Volume, isSpread.Value);
}

currFrom = currTo = null;
}
else if (currFrom.Price * mult > currTo.Price * mult)
{
//diff.Add(currTo.Clone());
AddExecMsg(diff, time, currTo, currTo.Volume);
AddExecMsg(diff, time, currTo, currTo.Volume, isSpread.Value);
currTo = null;
}
else
{
//var clone = currFrom.Clone();
//clone.Volume = -clone.Volume;
//diff.Add(clone);
AddExecMsg(diff, time, currFrom, -currFrom.Volume);
AddExecMsg(diff, time, currFrom, -currFrom.Volume, isSpread.Value);
currFrom = null;
}
}
Expand All @@ -239,15 +243,16 @@ private IEnumerable<ExecutionMessage> GetDiff(DateTime time, IEnumerable<QuoteCh

private readonly RandomArray<bool> _isMatch = new RandomArray<bool>(100);

private void AddExecMsg(List<ExecutionMessage> diff, DateTime time, QuoteChange quote, decimal volume)
private void AddExecMsg(List<ExecutionMessage> diff, DateTime time, QuoteChange quote, decimal volume, bool isSpread)
{
if (volume > 0)
diff.Add(CreateMessage(time, quote.Side, quote.Price, volume));
else
{
volume = volume.Abs();

if (volume > 1 && _isMatch.Next())
// matching only top orders (spread)
if (isSpread && volume > 1 && _isMatch.Next())
{
var tradeVolume = (int)volume / 2;

Expand Down

0 comments on commit 0708b22

Please sign in to comment.