|
Brian
2011-08-20 18:15:45
|
|
Hello, I am trying to backtest the money management functuionality that rejects non profitable positions. I am using the code (see below) but get the exact same results whether I use this code or I don't
My questions are...
1) Why is it not rejecting any trades?
2) How can I change this to base the rejection on the Sharpe ratio?
3) Is there a document of other ratios (Sortino, Ulcer, etc) that I can use to reject other trades if I wish.
Thank you
======= Code ==================
double pastdays = (double)Variables.GetVariable("Past Days");
double nbtrades = (double)Variables.GetVariable("Number of Trades");
MMPosition[] positions = Portfolio.GetClosedPositions(Divers.CurrentDate.AddDays(-pastdays));
int neg = 0;
for(int i=0;i<positions.Length;i++)
{
if(positions[i].Symbol == NewPosition.Symbol && positions[i].Performance < 0)
{
neg++;
if(neg >= nbtrades)
{
Divers.Output("Position Rejected: " + NewPosition.Symbol);
Functions.RejectPosition();
return;
}
}
|
|
|
|
QuantShare
2011-08-22 09:29:12
0
|
|
The above code rejects a position (trade) if there were at least "nbtrades" non profitable trades (Previous trades for the same stocks).
Is that what you want to do?
|
|
|
|
Brian
2011-08-22 11:19:31
0
|
|
Hello,
Yes, That is what I wish to do in my question 1. I am doing this to test the logic of this money management routine. In addition to getting the same results (using the lookback logic vs not using), I do not see any increase in the time for the backtesting to finish using the lookback logic vs not using.
Eventually I would like to substitute a different variable than "non profitable trades" like "Sharpe". That is the reason for my question 2 and 3 in the original post.
|
|
|
|
QuantShare
2011-08-23 07:22:16
0
|
|
Try setting a low value for "nbtrades" (Example: 1)
The reason you see no difference is maybe because each stock is traded only once.
|
|
|
|
Brian
2011-08-23 11:19:21
0
|
|
I tried a lower number of trades and no change. I then looked at the trade history for both backtesting runs (with lookback and without). Both trade histories were the same. I then ran another backtest (non lookback) using only 1 stock taken from the trade history from the lookback backtest. I found many stocks this way that had a negative profit and also less trades than the required criteria.
Please help.
Also, back to my question 2 and 3 in the original post...
2) How can I change this to base the rejection on the Sharpe ratio? Please give example.
3) Is there a document of other ratios (Sortino, Ulcer, etc) that I can use to reject other trades if I wish. If not, can you give example?
|
|
|
|
QuantShare
2011-08-24 08:00:52
0
|
|
Best Answer
1) The script works for me.
I have tried a simple trading system with the following settings:
- Past Days = 100 (Look for the past 100 days)
- Nb Trades = 1
2) You should replace "positions[i].Performance < 0":
You can change the previous line by:
TimeSeries ts = Data.ParseFormula("a = sharpe(close, 30);").GetTimeSeries(NewPosition.Symbol, "a");
if(positions[i].Symbol == NewPosition.Symbol && rs[0] > 1)
// Sharpe based on the previous 30 bars
3) You should create your own implementation of these ratios.
You can also hire one of our developers. If you are interested, please send me an email to support@quantshare.com
|
|
|
|