Setup:
Periodicity - 1 minutes
Walk forward setting
a. Easy mode (intraday)
b. Start/End same day e.g. 8/3/2020 - 8/3/2020
c. Step 1 day
b. Optimize target - Avg Profit/Loss
Observation:
Output from optimize shows Avg Profit/Loss has range of values (one day optimize 2020/8/3)
When walk forward testing is doing one day optimization, if the target has "-nan(ind)" , it is selected over other values (blue row, 2020/8/3)
I have tried using CBT to add a custom metric which is simply Nz of "AllAvgProfitLoss" and assign it as optimize target "EPY". (code at the end). It does circumvent -nan(ind) issue, but fails when walk forward tester evaluates market close days (e.g. Sat) saying target "EPY" is unavailable.
Questions / possible solutions:
- Is there a way to skip closed market days during walk forward test?
- Instead of setting custom metric, can I manually set performance stat? If so, I can just reset "AllAvgProfitLoss" with Nz and problem solved.
CBT code
// from https://www.amibroker.com/guide/a_custommetrics.html
/* First we need to enable custom backtest procedure and
** tell AmiBroker to use current formula
*/
SetCustomBacktestProc("");
/* Now custom-backtest procedure follows */
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(); // run default backtest procedure
st = bo.GetPerformanceStats(0); // get stats for all trades
// Here we add custom metric to backtest report
bo.AddCustomMetric( "EPY", Nz(st.GetValue("AllAvgProfitLoss")) );
}