Reply

Do portfolio advanced money management through equity control

3 replies

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

8 years ago #114345

I was looking over the equity control code today.  I had a thought, maybe I could use it to test more advanced money management strategies for portfolios.

 

One strategy I want to test is to stop trading if reach x% loss in one day and then trade again next day. 

 

(I dont’ have the formal training to really understand classes, objects, etc.  So I am a little confused by the API page and how to find what I need)

 

What I need is the date (day).  I know I can get the open time of the trade in seconds, but I need to be able to stop trading until it is a new day.  In NT7 I would say something like:

 

if(Time[I-1].Day != Time[i].Day)

{

    TradingHasReachedDailyLimit = false; //reset the trigger that stops the trading until the next day

    TodaysLImitBalance = originalTrades[i].balanceOnOpen – ( originalTrades[i].balanceOnOpen * 0.05 )

}  

 

Then I would use the below copied from TrailingProfit:

 

“…trades[i].balanceOnOpen <= TodaysLImitBalance[i]…”

 

I appreciate the guidance and then I will attempt to make the code and most likely come back for more advice.  THAnks.

 

-Stearno

0

Tamas

Customer, bbp_participant, community, sq-ultimate, 73 replies.

Visit profile

8 years ago #133556

Hello Stearno,

use the SQTime class.

eg.

SQTime dt = new SQTime(trade.openTime);

dt.getDate();

or any other method

https://strategyquant.com/qa_api/com/strategyquant/lib/time/SQTime.html

Tom

0

Tamas

Customer, bbp_participant, community, sq-ultimate, 73 replies.

Visit profile

8 years ago #133633

Hello Stearno,

 

maybe this could work???

@Override
public double[] computeBalanceControlLine(Trade[] originalTrades) throws Exception {
  double[] controlLine = new double[originalTrades.length];

  int percent = getIntParameterValue("_PERCENT_");

  for(int i=0; i<originalTrades.length; i++)  {		
    if(i==0 || !SQTime.toDateString(originalTrades[i].openTime).equals(SQTime.toDateString(originalTrades[i-1].openTime))) {
      controlLine[i] = computdailyriskamout(originalTrades, i, percent);
    } else {
      controlLine[i] = controlLine[i-1];
    }
  }

  return controlLine;
}

private double computdailyriskamout(Trade[] trades, int i, int percent) {
  return trades[i].balanceOnOpen - (trades[i].balanceOnOpen * (percent/100) );
}

Best regards,

Tomas

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

8 years ago #133635

Thanks, Tomas.  It seems to work. Now that I can see the graph, I have other problems to figure out.  I will be back if I get stuck again.

 

-Stearno

0

Viewing 3 replies - 1 through 3 (of 3 total)