- ago
I use split-unadjusted price & volume in backtesting to see if stocks met my price & volume filters. It was relatively easy to calculate in WL6 b/c of this:

CODE:
DataSeriesOp.SplitReverseFactor(ws, "Split (Yahoo! Finance)", out reverseAdjustment); .....


Unable to find this in WL7, does it exist in same/different form or name? If not, please consider this a feature request.
(And either full code or a snippet would help in the meantime. TIA.)
0
734
Solved
11 Replies

Reply

Bookmark

Sort
- ago
#1
Let's not mark every topic as feature request. First we need to evaluate whether it fits the new design.
0
- ago
#2
So I have an incomplete code snippet to create a split adjustment factor/reverse adjustment series:
CODE:
   public class splitUnadj : TimeSeries    {       TimeSeries ts;       UserStrategyBase usb;       public splitUnadj(UserStrategyBase usb, BarHistory bars, TimeSeries ts, string description) : base()       {          this.ts = ts;          this.usb = usb;          FirstValidIndex = ts.FirstValidIndex;          //DataSeriesOp.SplitReverseFactor(usb, "split", out reverseAdjustment); //WL6                    //calculate split adjustment factor (reverse adjustment) using the list containing data points on Splits          List<EventDataPoint> fList = bars.EventDataPoints.Where(i => i.Value > 0 && i.Name == "Split").ToList();          TimeSeries saf = new TimeSeries(); //Split adjustment factor series          int bar = bars.Count-1;          double _saf = 1d;          double _div = 0d;          try          {             //don't process a symbol with no fundamental (event) data point             if (fList.Count == 0)                return;             for (int n = fList.Count - 1; n >= 0; n--)             {


I'm stuck here, any help appreciated (and you don't have to use the snippet exactly, it's rough work and there are probably some redundancies here).
0
Cone8
 ( 24.56% )
- ago
#3
Use the SplitRev indicator.


CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript2 { public class MyStrategy : UserStrategyBase {       TimeSeries _sRev;        public override void Initialize(BarHistory bars) {          _sRev = new SplitReverse(bars, PriceComponents.Close);          PlotTimeSeriesLine(_sRev, "Split-Close", "Price"); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }
0
Best Answer
- ago
#4
Thank you!

That works perfectly on Prices but not so on Volume. e.g. if there's a 2:1 split then this method adjusts pre-split Prices by x2 (which is correct) but its also adjusting pre-split Volume the same way by x2 whereas it ought to be dividing them by 2.
0
- ago
#5
Good catch. Will fix in Build 8.
1
- ago
#6
How far back does the split data go please and what source is used for individual stocks using this strategy?

I tried it for INTC, AMD, and QQQ and it's not finding any of the splits. They're all 2000 or before I believe.

Is there a way to get split dates and their multiplier? A TimeSeries that's all the multiplier that would adjust the historical shares? For example if you look at TSLA, it would be all 1s starting 8/31/20 and all 5s before that since a 5:1 stock split happened then. And if theoretically a 2:1 stock split had happened on 3/1/20 then the TimeSeries would be 10 for 2/28/20 and before.

This kind of works and it always says 5 before the split date but the graph is not a straight line for some reason:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript3 { public class MyStrategy : UserStrategyBase {       TimeSeries equity, benchmark_equity, benchmark_multiplier;       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars) {          benchmark_multiplier = new SplitReverse(bars, PriceComponents.Close) /             bars.Close;          PlotTimeSeriesLine(benchmark_multiplier, "Close", "Split");       } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }


Is there a reason the graph looks weird?

Thanks
0
- ago
#7
I have positions that are held through stock splits but the quantity doesn't seem to be effected on bars after the split.

Does the back tester just use the SplitReverse multiples while calculating profits?

If I need the adjusted number of shares after a split on an open position would I just use something like what I have above?

Thanks
0
- ago
#8
Hi MPO,
QUOTE:
Is there a way to get split dates and their multiplier? A TimeSeries that's all the multiplier that would adjust the historical shares?


Check out code below; plot using Weekly scale so you can see a larger time frame and be sure to update your Event Data first:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; using System.Linq;   // for Fundamentals namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          // Check for Splits          lstSplits = bars.EventDataPoints.Where(i => i.Value > 0 && i.Name == "Split").ToList();          int cnt = lstSplits.Count;          WriteToDebugLog("Split list count = " + cnt);          for (int a = cnt -1; a > -1; a--)             WriteToDebugLog(lstSplits[a].Name + ", " + lstSplits[a].Date.ToShortDateString()                + " " + lstSplits[a].Value.ToString("#0.##") + " : 1");          // Create a split factor series          TimeSeries saf = new TimeSeries(bars.DateTimes, 1);          int bar = bars.Count -1; double _saf = 1; double _splt;          if (lstSplits != null) //safety1          {             if (lstSplits.Count > 0) //safety2             {                for (int n = lstSplits.Count - 1; n >= 0; n--)                {                   var fi = lstSplits[n];                   int fbar = saf.IndexOf(fi.Date.Date);                   if (fbar == -1)                      continue;                   while (bar >= fbar) { if (bar < 1) break; saf[bar] = _saf; bar--; }                   _saf = saf[bar+1] * fi.Value;                }                while (bar > -1) { saf[bar] = _saf; bar--; }             }          }          //Test          PlotTimeSeries(saf, "Split Factor", "pTest", Color.Gray, PlotStyles.ThickHistogram);          TimeSeries suC = bars.Close * saf; //splitUnadjusted Close          PlotTimeSeriesLine(suC, "Actual Price (i.e. Split-Unadjusted)", "psuC", Color.Red, 2);          TimeSeries suV = bars.Volume / saf; //splitUnadjusted Volume          PlotTimeSeries(suV, "Actual Volume (i.e. Split-Unadjusted)", "psuV", Color.Green, PlotStyles.ThickHistogram);       } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { } }       //declare private variables below       List<EventDataPoint> lstSplits;    } }


0
- ago
#9
Awesome. Thanks!
0
- ago
#10
Using build 8.
Just noticed another issue with SplitReverse...it is making the split-unadjustments to the Price & Volume *on the day of the split* also whereas the split-unadjustments are correctly only applied up to the bar before the day of split.
Take the symbol AAPL as an example. Compare your split-unadjusted prices on the day-of-split to original prices which can be found here (you may have to play with the zoom/bars loaded for better granularity): https://www.macrotrends.net/stocks/charts/AAPL/apple/stock-splits
0
- ago
#11
QUOTE:
Just noticed another issue with SplitReverse...it is making the split-unadjustments to the Price & Volume *on the day of the split*

Thanks, we'll get this fixed in Build 9.
1

Reply

Bookmark

Sort