Sergey,
Thanks very much for the reply.
I should have been clearer; this PnL is sorted from smallest to largest. Please don’t be confused about that.
I was trying to show with that the “large” losses shouldn’t be happening. This model uses a $20,000 account with a fixed fractional position sizing algorithm of a 1% loss. Therefore, initially the losses shouldn’t exceed $200 (roughly, the spread sometimes makes the losses slightly larger).
The print is happening on the call to a method I’ve written which calculates the position size. See below. There is nothing proprietary there so I’m happy to share it.
I’ve done some further research; trying to narrow it down. I've got OQ doing a Console WriteLine on the results of GetValue, GetCoreEquity and GetTotalEquity. You can see the examples of the “bad” values from GetCoreEquity in the example below:
Current Account GetValue = 19401.6000000002
Current Account GetCoreEquity = 19377.1000000002
Current Account GetTotalEquity = 20077.8000000001
Current Account GetValue = 424352.3
Current Account GetCoreEquity = 19173.6000000002
Current Account GetTotalEquity = 19835.1000000002
Current Account GetValue = 424109.6
Current Account GetCoreEquity = 924144.1
Current Account GetTotalEquity = 19512.9000000001
Current Account GetValue = 470680.1
Current Account GetCoreEquity = 19353.6000000002
Current Account GetTotalEquity = 19483.1000000002
Current Account GetValue = 325388
Current Account GetCoreEquity = 18983.5000000002
Current Account GetTotalEquity = 18983.5000000002
Current Account GetValue = 18983.5000000002
Current Account GetCoreEquity = 18983.5000000002
Current Account GetTotalEquity = 18983.5000000002
Code:
public int PositionSize(double stopsize, double rpercent)
{
double CAccountSize = Portfolio.GetTotalEquity();
Console.WriteLine("Current Account GetCoreEquity = " + Portfolio.GetCoreEquity());
Console.WriteLine("Current Account GetTotalEquity = " + Portfolio.GetTotalEquity());
Console.WriteLine("Current Account GetValue = " + Portfolio.GetValue());
if (debug)
{
Console.WriteLine("Current Account Size = " + CAccountSize);
Console.WriteLine("Stop size " + stopsize);
}
// Check to see what we have been passed as stop size
// if it is in terms of an int i.e. 30.0 or is
// is it in pricing terms e.g. 0.0030 or 0.30
// N.B: For Yen crosses this is only robust
// for anything less than 100 yen i.e. 1.00
if (GetTickSize(Instrument) == 6)
{
stopsize = stopsize * 100;
}
else if (GetTickSize(Instrument) == 7)
{
stopsize = stopsize * 100;
}
else if (GetTickSize(Instrument) == 4)
{
stopsize = stopsize * 10;
}
else if (GetTickSize(Instrument) == 5)
{
stopsize = stopsize * 10000;
}
else if (GetTickSize(Instrument) == 3)
{
stopsize = stopsize * 100;
}
if (debug)
{
Console.WriteLine("Current Account Size = " + CAccountSize);
Console.WriteLine("Stop size " + stopsize);
}
double PSize = (double)Math.Round((CAccountSize * rpercent) / stopsize, 2);
// Can't trade less than a single lot
// This means that risk management has kicked in
// we need to reject this trade.
if (Instrument.Type == InstrumentType.FX)
{ // trade mini - lots
if (PSize <= 0.09)
{
PSize = 0;
return (int)PSize;
}
else
{
if (GetTickSize(Instrument) == 6)
{
PSize = (Math.Round(PSize, 0) * 1000);
}
else if (GetTickSize(Instrument) == 5)
{
PSize = (Math.Round(PSize, 0) * 10000);
}
else if (GetTickSize(Instrument) == 3)
{
PSize = (Math.Round(PSize, 0) * 100);
}
else if (GetTickSize(Instrument) == 4)
{
PSize = (Math.Round(PSize, 0) * 1000);
}
else if (GetTickSize(Instrument) == 2)
{
PSize = (Math.Round(PSize, 0) * 100);
}
return (int)PSize;
}
}
else if (Instrument.Type == InstrumentType.Stock)
{
if (PSize <= 0.09)
{
PSize = 0;
return (int)PSize;
}
else
{
PSize = (Math.Round(PSize, 1) * 100);
return (int)PSize;
}
}
else
{
Console.WriteLine("Error - unknown instrument type - 70 @ Risk Manager");
return (int)PSize;
}
//return 0.0;
}
Thanks for your help on this issue.
Kind regards,
drolles