- ago
Is there a way, using the drag and drop interface, to add a constraint to buy only if the coefficient of variation is less than x?
0
387
Solved
3 Replies

Reply

Bookmark

Sort
- ago
#1
If you know the formula, you can try to build it with transformer indicators (MathInd...) on-the-fly.

Another possibility is to code it in the handy New Indicator Wizard for use in Blocks.
0
- ago
#2
As suggested, just use the coefficient of variation formula to compute it as a TimeSeries.
CODE:
   public class MyStrategy : UserStrategyBase    {       const int coeffVarPeriod = 10;       TimeSeries coeffVar;              public override void Initialize(BarHistory bars)       {          coeffVar = new StdDev(bars.Close, coeffVarPeriod) / new SMA(bars.Close, coeffVarPeriod);       }       public override void Execute(BarHistory bars, int idx)       {          if (HasOpenPosition(bars, PositionType.Long))          {             //code your sell conditions here          }          else          {             //code your buy conditions here             if (coeffVar[idx] < 0.1)                PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0.0);          }       }    }

But as statistics guys, we both know the standard deviation is unreliable with noisy data that contains outliers. So using a more robust measurement is really required here. Wikipedia writes "A more robust [metric] is the quartile coefficient of dispersion, half the interquartile range, (Q3 - Q1) / 2, divided by the average of the quartiles, (Q1 + Q3) / 2." https://en.wikipedia.org/wiki/Coefficient_of_variation

And, in practice, using the quartile coefficient of dispersion would be the way to do it for noisy stock prices. Hmm, I thought finantic.Indicators had the quartile calculations for you, but I don't see them there--oops. https://www.wealth-lab.com/extension/detail/finantic.Indicators#screenshots Maybe MP, MP2, MP3, MP4 are the quartiles, but I could be wrong.

Well, the Math.NET numerical analysis package has them (which is what I use). Check out https://numerics.mathdotnet.com/DescriptiveStatistics

---
Another approach would be to simply use the Beta indicator WL has with the S&P500 as the index. If the short-term Beta is over two or so, then I wouldn't buy the stock.
0
Best Answer
- ago
#3
Okay thanks for the help.
0

Reply

Bookmark

Sort