- ago
Hello,

I am running into an issue when trying to work with certain strategies. When a strategy requires a certain number of bars of data to determine the entry point or some particular indicator it is using, it will enter the trade but with a data point containing "NaN". In the screenshot, it gives NaN for the entry price. This causes the strategy to give no further positions as it cannot calculate the P/L from that first entry.

I am using a workaround by using a date filter and loading more data beyond the first trade allowed. This fixes the problem but it is a very clunky solution because I have to manually change the date whenever I want to look at different windows in time.

Is there some setting or method I am not using that will clear up this problem?

Curiously, I was not encountering this problem until today even though I am working with many of the same strategies. For example, a previous version of a MetaStrategy works just fine but when I created a new MetaStrategy with the same strategies it is giving me this error.

0
481
9 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.27% )
- ago
#1
It looks like what is happening is the WFO is assigning a period that is greater than the default value of the parameter.

The generated code is setting StartIndex based on the default value.

Are you running this with WFO parameters enabled?

Let me think about this, we'll probably need to change how the code is generated to consider the WFO parameters.

But a workaround for now would be to set a default value that's at least as large as the WFO parameter.
0
Glitch8
 ( 11.27% )
- ago
#2
I've been trying to get a Strategy to issue a NaN trade like this, even a MetaStrategy, but haven't been able to so far. If you have a minimal example that's doing it, email it over to us if possible support@wealth-lab.com.
0
- ago
#3
Sure. I just emailed a strategy over.

Yes I believe it is related to the WFO settings. The NaN appears only for certain time periods, as those time periods change the parameters based on the WFO.

This may be why I am running into this problem today, because I was working in some strategies that had different timeframes and periods I tested them on, and so I was using different dates than those I had originally built the WFO parameters on (I believe I still was using dates within the window of the WFO, so that it would have meaningful results. As in, I did not go back before the period of the strategies' WFO).
0
Cone8
 ( 4.92% )
- ago
#4
I'm not on the receiving end of the email, but if it's not a block strategy, may you haven't implemented NewWFOInterval(). Could that be it?

fwiw, it's a good habit for WFO-ers to assign indicators in NewWFOInterval() and call it from Initiialize() to avoid repetitive code.

Example -

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript4 { public class MyStrategy : UserStrategyBase {       public MyStrategy()       {          _period = AddParameter("Period", ParameterType.Int32, 10, 5, 20, 1);       } public override void Initialize(BarHistory bars) {          StartIndex = _period.AsInt;          NewWFOInterval(bars);          PlotIndicator(_ma); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) {             if (bars.Close.CrossesOver(_ma, idx))             {                Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market);                             } } else {             Position p = LastPosition;             if (idx - p.EntryBar + 1 > 10)                ClosePosition(p, OrderType.Market); } } public override void NewWFOInterval(BarHistory bars) { _ma = SMA.Series(bars.Close, _period.AsInt); } Parameter _period;       SMA _ma; } }
0
Cone8
 ( 4.92% )
- ago
#5
It just occurred to me that maybe StartIndex needs to be assigned the same way.
0
- ago
#6
Sorry I realized I didn't respond to you Cone. Unfortunately I am only using Block strategies.

I am running into this problem a great deal when I am trying to look at different time periods with my meta strategy. My meta strategy uses block strategies with WFO parameters. Basically I can't get any results because a "NaN" positions shows up and gives NSF positions (no matter how much starting capital I give it).

Luckily, there are some time periods that don't give NaN positions, but for me it it most of the time periods I try to run.
0
Cone8
 ( 4.92% )
- ago
#7
I think I got it with my comment in Post #5, but sorry I didn't follow up.
I'll log it now.
1
- ago
#8
This is the first time I have gotten this error when running a WFO.

0
- ago
#9
I should clarify, I have never seen NaN on the tabular of a completed WFO
0

Reply

Bookmark

Sort