Reply

Snipped for whatif allow max simultainios trades per instrument

1 replies

mabi

Customer, bbp_participant, community, 261 replies.

Visit profile

5 years ago #238012

Today there is possibility to test max trades per day not sure that it works as said since even if You set to 1 trade per day there is some times 3 trades per day. When Building a portfolio correlation is always a problem on the same instrument. Trades are taken very close to each other but with different  exits which makes QA think that they are un correlated but they are infact very correlated especially during loosing periods. There is ways to avoid taking more then 1 trade on the same instrument simultaneously by using a copier but there is not a what if function in QA to check what the performance would be.

I hope someone can help with this function since I think it can be a feature that can greatly lower drawdown of large portfolios. I have been testing this on a live account for avail and what I can see is that the EQ curve becomes much more smooth and drawdown much smaller and profit better then on the account were it is not used.

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

2 years ago #270964

Here is code for limiting the number trades opened at one time in What-if Analysis.  I am not a coder, so its not the most efficient way and not the best way.  But it is a way that works, so I share it in case it helps anyone:

 

package com.strategyquant.extend.WhatIf;

import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.Arrays;

import com.strategyquant.lib.comparators.OrderComparatorByOpenTime;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.results.SQOrder;
import com.strategyquant.lib.results.SQOrderList;
import com.strategyquant.lib.snippets.WhatIf;
import com.strategyquant.lib.time.SQTime;

public class TakeMaxTradesAtOneTime extends WhatIf
{

public TakeMaxTradesAtOneTime()
{
setName(L.t(“Take maximum trades at one time”));

addIntParameter(“Trades”, L.t(“Trades”), 1, 1, Integer.MAX_VALUE, 1);
setFormatedName(L.t(“Take maximum {Trades} trades at one time”));
}

public void filter(SQOrderList originalOrders) throws Exception
{
int trades = getIntParameterValue(“Trades”);
long[] Closedatetime = new long[1];
int FirstRun = 0;

Collections.sort(originalOrders, new OrderComparatorByOpenTime());

for(Iterator<SQOrder> i = originalOrders.listIterator(); i.hasNext();)
{
SQOrder order = i.next();

if(order.isBalanceOrder())
continue;
long closedatetime = order.CloseTime;

if (FirstRun == 0)
{
Closedatetime[0] = closedatetime;
FirstRun = 1;
}
int count = Closedatetime.length;
if (count <= trades)
{
Closedatetime = Arrays.copyOf(Closedatetime, Closedatetime.length + 1);
Closedatetime[Closedatetime.length – 1] = closedatetime;
}
else
{
Arrays.sort(Closedatetime);
long opendatetime = order.OpenTime;
for (int j = 0; j < Closedatetime.length; j++)
{
if (opendatetime > Closedatetime[j])
Closedatetime = removeElement(Closedatetime,j);
}
count = Closedatetime.length;
if (count <= trades)
{
Closedatetime = Arrays.copyOf(Closedatetime, Closedatetime.length + 1);
Closedatetime[Closedatetime.length – 1] = closedatetime;
}
else
i.remove();
}
}
}

private long[] removeElement(long[] arr, int index)
{
long[] anotherArray = new long[arr.length – 1];
for (int l = 0, k = 0; l < arr.length; l++)
{
if (l == index)
continue;
anotherArray[k] = arr[l];
k++;
}
return anotherArray;
}
}

0

Viewing 1 replies (of 1 total)