【问题标题】:Unable to add this custom metric to Amibroker backtest report无法将此自定义指标添加到 Amibroker 回测报告
【发布时间】:2018-07-31 08:14:32
【问题描述】:

我想在回测报告中添加一个额外的列来指示波动性。

这是我的代码。额外的列volatility_recent 出现,但列中没有值出现。但是,如果我使用注释行trade.AddCustomMetric( "proceeds", trade.Shares*trade.ExitPrice );,列中会出现一些数值。

代码有什么问题?

if ( Status( "action" ) == actionPortfolio )
{
    bo = GetBacktesterObject();
    // run default backtest procedure without generating the trade list
    bo.Backtest( True );

    volatility_recent = ATR(30);

    // iterate through closed trades
    for ( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
    {
        trade.AddCustomMetric( "volatility_recent", volatility_recent );
        //trade.AddCustomMetric( "proceeds", trade.Shares*trade.ExitPrice );
    }

    // iterate through open positions
    for ( trade = bo.GetFirstOpenPos( ); trade; trade = bo.GetNextOpenPos( ) )
    {       

        trade.AddCustomMetric( "volatility_recent", volatility_recent );
        //trade.AddCustomMetric( "proceeds", trade.Shares*trade.ExitPrice );
    }

    // generate trade list
    bo.ListTrades( );
}

【问题讨论】:

    标签: amibroker


    【解决方案1】:

    我发现你在不提供参考的情况下逐行复制文本和代码解决方案其他人真的很有趣。

    您在 stackoverflow 上的第二篇文章是 Tomasz 和我在 forum.amibroker.com 上逐行复制对您的回复

    https://forum.amibroker.com/t/unable-to-add-this-custom-metric-to-backtest-report/7153

    【讨论】:

    • 嗨 fxshrat,不留下参考资料是不礼貌的。我已经编辑了原始答案,以表明功劳是你的。我也赞成并将您的答案标记为答案。原始答案张贴在这里作为参考其他人。无意拿走你的功劳。对不起。您可以将遗漏参考资料视为懒惰和不礼貌。我已经纠正了不礼貌的行为。
    【解决方案2】:

    自定义指标需要是标量(数字),而不是数组。 ATR(30) 是一个数组。因此,使用LastValue 获取数组的最后一个值,或者使用 Lookup 获取指定柱的值。通过静态变量将 ATR 符号数组从回测的第一阶段传递到第二阶段。然后在自定义指标行中使用查找在特定日期时间提取数组元素(trade.EntryDateTime 或trade.ExitDateTime)。

    StaticVarSet( "CBT_ATR_" + Name(), ATR(30) );
    
    if ( Status( "action" ) == actionPortfolio )
    {
        bo = GetBacktesterObject();
        // run default backtest procedure without generating the trade list
        bo.Backtest( True );    
    
        // iterate through closed trades
        for ( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
        {
            trade.AddCustomMetric( "volatility_recent", Lookup( StaticVarGet( "CBT_ATR_" + trade.Symbol ), trade.ExitDateTime ) );
            //trade.AddCustomMetric( "proceeds", trade.Shares*trade.EntryPrice );
        }
    
        // iterate through open positions
        for ( trade = bo.GetFirstOpenPos( ); trade; trade = bo.GetNextOpenPos( ) )
        {       
    
            trade.AddCustomMetric( "volatility_recent", Lookup( StaticVarGet( "CBT_ATR_" + trade.Symbol ), Trade.ExitDateTime ) );
            //trade.AddCustomMetric( "proceeds", trade.Shares*trade.EntryPrice );
        }
    
        // generate trade list
        bo.ListTrades( );
    }
    

    编辑:功劳归于 fxshrat,他在https://forum.amibroker.com/t/unable-to-add-this-custom-metric-to-backtest-report/7153/2 上发布了答案 他的答案张贴在这里,在没有参考的情况下发布是不礼貌的。向 fxshrat 和 Tomasz 道歉。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      相关资源
      最近更新 更多