- ago
bt.Metrics.GetMetric("Test") does work so why not SetMetric?

I know I can set a Metric in backtester object using
CODE:
bt.Metrics.Test = 10.0

But I'd like to be able to set them as well with generated name from a string with:
CODE:
bt.Metrics.SetMetric("Test", 10.0)

But this gives an Error: 'WealthLab.Backtest.MetricsBundle' does not contain a definition for 'SetMetric'




0
173
7 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.81% )
- ago
#1
It’s just not how the class works. It’s intended to be used in conjunction with the ScoreCard API.
0
- ago
#2
Yes, I want to use it on a custom ScoreCard.

CODE:
bt.Positions[0].SetMetric("Test", 10.0)


That does work so I wondered whether it would be very simple for you to support SetMetric on the bt.Metrics as well. Because from the outside those metrics objects look similar.
0
Glitch8
 ( 11.81% )
- ago
#3
In a ScoreCard you just assign a new metric by using a property name directly. There’s no need for a SetMetric.

CODE:
by.Metrics.Test = 10.0;
0
- ago
#4
This is getting me confused. Are we talking about setting a metric for a specific Position object or setting a dynamic "aggregation" metric for the final Metrics Report? This isn't clear to me.

The code below ...
CODE:
bt.Positions[0].SetMetric("Test", 10.0);
... looks like you're trying to set a metric for a specific Position object. You cannot do it that way with a ScoreCard object. That must be done in the Execute{block} using the Transaction object. And that will create and set that metric to that Position instance if/when that Position is created.

CODE:
   if (attribs.opportunityBar <= idx)    {       Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Stop, bars.Close[attribs.peak2Bar], "123pattn stop Buy");          t.SetPositionMetric("MySpecialMetric", atrMerit);    }
It's also possible to set it in an existing Position object as well, like when you sell the Position (but that's another issue). The Help docs for Transaction and Position discuss this.

The next question is what do you want to do with that Position metric? The Metrics Report only publishes "aggregated" metrics, not Position metrics. If you want to convert all your Position metrics to an aggregated metric for the Metrics Report, you need to write a ScoreCard object to do that with.

If you want to publish your Position metric in a Positions tabulation column, then you need to write a PositionsScoreCard object to do that with.

If you simply want to use your Position metric in a Performance Visualizer (such as Analysis Series), then you don't have to do anything--you're done. Performance Visualizers will automatically use your custom Position metric.

You need to be explicit about where you're going with this because the approach will be different depending on the final goal (which you never shared with us).
0
- ago
#5
Sorry for the confusion. I want to set the Metrics for the scorecard for the final metrics report.

The only reason I mentioned Positions[0].SetMetric is that Glitch replied to my original question that the Metrics class doesn't work that way. I mentioned it because from my viewpoint that also looks like a Metrics class object and that one does have the possibility to set the Metric using a string as a property. I don't want to do anything with the Positions[0].SetMetric. Just with the bt.Metrics in the scorecard.

I hope this clarifies the issue.
1
- ago
#6
As for the reason I'd like to have that possibility. I'm testing a new Metric and a dynamic way to set it would allow me to easily add a list of metrics calculated with slightly different values, so I could get a scorecard variations of my metric. Like:

MyMetric_10_1 x
MyMetric_11_2 x
MyMetric_12_1 x
MyMetric_10_2 x
MyMetric_14_3 x

etc

Where I generate the property name with $"MyMetric_{par1}_{par2}"

0
Glitch8
 ( 11.81% )
- ago
#7
I'll tag it as a FeatureRequest. We'd need to be careful that introducing a SetMetric would not interfere or cause any side effects with the overall metrics framework.
0

Reply

Bookmark

Sort