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.
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.
Rename
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.
You mean a median of individual trade returns? Other options are programming a custom ScoreCard or using the finantic ScoreCard extension.
The finantic.ScoreCard extension has Median of returns...
....and much, much more...
....and much, much more...
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);
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: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?
public TimeSeries DailyReturns public TimeSeries EquityCurve
What kind of returns? Bar-by-bar (daily?), monthly? annual?
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?
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; }
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: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.
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); }
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.
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.
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.
Your Response
Post
Edit Post
Login is required