- ago
Hi, Guys!
Is there any easy way to get the median return?
I found Median class in WealthLab.Indicators, but I'm confused how to get Time series returns.
0
305
Solved
10 Replies

Reply

Bookmark

Sort
Cone8
 ( 6.30% )
- ago
#1
I don't know of a visualizer that has that metric (it would be pretty close to Mean Returns in the Basic Scorecard), but it'd be easy calculate that by adding a bit of code in the BacktestComplete method of your strategy.
0
Glitch8
 ( 11.87% )
- ago
#2
You mean a median of individual trade returns? Other options are programming a custom ScoreCard or using the finantic ScoreCard extension.
0
- ago
#3
The finantic.ScoreCard extension has Median of returns...
....and much, much more...
0
- ago
#4
No, I meant is there any simple way to get an array of returns using C# code or TimeSeries of returns?
CODE:
var medReturns = Median.Series(?, Parameters[0].AsInt);
0
- ago
#5
QUOTE:
get an array of returns using C# code

The only thing I can figure is that you want to write a C# Backtester extension method and call it from either the Cleanup{block} or the BacktestComplete{block}. But I can't figure out which. Once you get this data, what do you want to do with it? And are you grouping the information by Symbol or by DataSet in your C# code?

Please go to https://www.wealth-lab.com/Support/ApiReference/Backtester and tell us which Backtester call below you are interest in.
CODE:
public TimeSeries DailyReturns public TimeSeries EquityCurve
Understand, all this activity is being done post-backtest, so we are really talking about some kind of Performance Visualizer. What's wrong with using an existing Performance Visualizer such as Analysis Series to look at the returns?
0
Glitch8
 ( 11.87% )
- ago
#6
What kind of returns? Bar-by-bar (daily?), monthly? annual?
0
- ago
#7
I want to get an analogue of ROC for the period, but at the output I want to get the median return. We are talking about daily intervals

I tried like this, but maybe there is a better way?
CODE:
public override void Initialize(BarHistory bars) { StartIndex = Parameters[0].AsInt; TimeSeries rets = new TimeSeries(bars.DateTimes, 0.0); for (int bar = 1; bar < bars.Count; bar++) { rets[bar] = bars.Close[bar] / bars.Close[bar - 1]; } var medRets = Median.Series(rets, Parameters[0].AsInt); bars.Cache[seriesKey] = medRets; }
0
- ago
#8
By return, I'm assuming you mean the (ExitPrice)-(EntryPrice) for each position traded, right?
I just looked at your code, and you're not computing returns. Returns are created by trading, and what you want to do doesn't involve trading.

You want to take the first derivative of Price to get Price velocity. There isn't any trading involved, so there aren't any returns involved. Do it this way:
CODE:
      public override void Initialize(BarHistory bars)       {          IndicatorBase priceVelocity = Momentum.Series(bars.Close, 1); //bars.Close[bar] - bars.Close[bar-1];          IndicatorBase medianVelocity = Median.Series(priceVelocity,Parameters[0].AsInt);          IndicatorBase roc = ROC.Series(bars.Close, 1); //compute relative change per bar          IndicatorBase medianROC = Median.Series(roc,Parameters[0].AsInt);       }
You may want to declare priceVelocity, medianVelocity, etc. in the MyStrategy{block} first so these variables become visible in both the Initialize{block} and Execute{block}. If so, be sure to remove the "IndicatorBase" declaration in Initialize.
0
- ago
#9
ROC is the average return for the period, I want to get the median return. But I discovered that there is no such ROCMedian method and there is also no method that would return TimeSeries of returns. So I am wondering if there any simple way to do this or if the only option is to do everything the old fashioned way through a loop.
0
Glitch8
 ( 11.87% )
- ago
#10
ROC isn't the average return, it's the percentage return from point A to point B. If you wanted the average 1-day return over a period you'd use SMA of ROC.

If you want the Median 1-day return over a period, use the Median indicator.

You can use the IndOnInd indicator to apply the Median indicator to the ROC like this. Be sure to change the ROC period to 1.

3
Best Answer

Reply

Bookmark

Sort