u33m2ha8
 ( 0.00% )
- ago
I have the following problem:

I have a simple rotation strategy that uses an indicator based on 255 bars. The strategy's start date is set to January 6, 2024. Logically, the first trade will be placed on February 3, 2025, and thus the benchmark's performance will be measured from February 3, 2025, to the present day.

Now, I'm creating a different strategy as code with the same parameters, and the strategy values ​​are the same. However, the benchmark's performance is almost twice as high. It can't be any other way than that, in this case, the benchmark's performance is calculated from the start date (January 6, 2024).

How can I align these? Is it normal for the benchmark's performance to be calculated differently when coding compared to a block or rotation strategy?

Or is there a setting for this?

Thanks!
0
317
1 Replies

Reply

Bookmark

Sort
- ago
#1
QUOTE:
However, the benchmark's performance [between block and coded strategy] is almost twice as high.

That's because you failed to set the StartIndex in your coded strategy. You need to be doing that so the trading and statistics only begin after the longest indicator becomes valid.
CODE:
      public override void Initialize(BarHistory bars)       {          IndicatorBase sma200 = SMA.Series(bars.Close, 200);          IndicatorBase sma50 = SMA.Series(bars.Close, 50);          StartIndex = System.Math.Max(sma200.FirstValidIndex,sma50.FirstValidIndex);       }
You really don't need the Math.Max statement here because you know the FirstValidIndex for sma200 will always be larger than that for sma50. But for many indicators, that distinction is not so obvious. For example, I have an indicator where the FirstValidIndex depends on the statistical behavior of the data, so it will always be different for each stock.

The StartIndex is set automatically in blocks.
0

Reply

Bookmark

Sort