- ago
Is there a way in IndexLab to create an index where each component has a different weighting?
1
677
Solved
14 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.06% )
- ago
#1
Currently no, but I think it's a good idea, so I'm going to add a new indicator, CompisiteWeightedIndex, to the next release of IndexLab. You'll be able to specify weightings using a text-box parameter of comma separated entries, like:

AAPL=2, BA=1.5, CSCO=1, EBAY=0.5

0
- ago
#2
It might be possible to achieve in C# code. Here's a quick and dirty prototype:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using WealthLab.ChartWPF; using System.Drawing; using System.Collections.Generic; namespace WealthScript3 {    public class MyStrategy : UserStrategyBase    {       TimeSeries index = new TimeSeries();       string key = "IndexOnDemand";       public override void Initialize(BarHistory bars)       {          if (GetGlobal(key) == null)          {             // Index weights array             string[] sym = new string[2] { "AAPL", "IBM" };             double[] pct = new double[2] { 0.65, 0.35 };             // Get external symbols data for index creation             try             {                var x = new TimeSeries(bars.DateTimes, 0);                for(int i = 0; i <= sym.GetUpperBound(0); i++)                {                   x += (GetHistory(bars, sym[i]).Close * pct[i]);                }                index = x;                index.Description = "Weighted Index";                // Place created index to global memory                SetGlobal(key, index);             }             catch             {                WriteToDebugLog("No data or could not find series");             }          }          var global = (TimeSeries)GetGlobal(key);          PlotTimeSeriesLine(global, global.Description, "indexPane");       }       public override void Execute(BarHistory bars, int idx)       {       }    } }
1
- ago
#3
That would be fantastic -- thanks! In the construct you define, I assume that for the quick example you laid out, the end result would be for AAPL to have a 40% weight, BA a 30% weight, CSCO 20%, and EBAY 10% -- all summing to 100%.

Is that correct?
0
- ago
#4
Also, I tried to run the code. It compiled and ran successfully. However, can you tell me where to go to see the results either in a chart or in the combined time series.

Still trying to figure out WL7 ... Thanks.
0
Glitch8
 ( 10.06% )
- ago
#5
I already implemented the CompositeWeightedIndicator for the next release of IndexLab, in case you want to wait ...

0
- ago
#6
You folks are amazing!! When is that release? In the meantime how do look at the results from the quick code that was posted?

Thanks!
0
- ago
#7
Indicator should be plotted at the bottom of the chart.
0
Glitch8
 ( 10.06% )
- ago
#8
One thing that IndexLab does that Eugene's quick code does not is account for splits in the historical data. If not done, it can severely throw off the generated composite.
0
- ago
#9
Good point Dion, the code should take splits into account using the SplitReverse indicator e.g.

CODE:
//replace //x += (GetHistory(bars, sym[i]).Close * pct[i]); //with var _bSym = GetHistory(bars, sym[i]; var _adj = SplitReverse.Series(_bSym, PriceComponents.Close); x += _adj * pct[i];
0
- ago
#10
There is no plot at the bottom after I run the code.
0
- ago
#11
Try this simplified version. Remember it's just a proof of concept - not the complete code:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using WealthLab.ChartWPF; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 {    public class MyStrategy : UserStrategyBase    {       TimeSeries index = new TimeSeries();       //plot a market benchmark in its own pane and don't trade unless the benchmark is above its 50-day SMA       public override void Initialize(BarHistory bars)       {          // Index proportions array          string[] sym = new string[2] { "AAPL", "IBM" };          double[] pct = new double[2] { 0.65, 0.35 };          // Get external symbols data for index creation          try          {             var x = new TimeSeries(bars.DateTimes, 0);             for (int i = 0; i <= sym.GetUpperBound(0); i++)             {                var _bSym = GetHistory(bars, sym[i]);                var _adj = SplitReverse.Series(_bSym, PriceComponents.Close);                x += _adj * pct[i];             }             index = x;             index.Description = "Weighted Index";          }          catch          {             WriteToDebugLog("No data or could not find series");          }          PlotTimeSeriesLine(index, index.Description, "indexPane");       }       public override void Execute(BarHistory bars, int idx)       {       }    } }
1
- ago
#12
It worked this time. Thanks!

I eagerly await the formal release.
2
Best Answer
- ago
#13
Do you have a planned date for this release in the extension? I notice there has been at least 1 new release but I don’t believe this enhancement was included. Thanks!
0
Cone8
 ( 23.82% )
- ago
#14
It's in Build 8 - since 2 March.

I just noticed we should improve the Description of CompositeWeightedIndex, but there's a help hint if you hover over the "Weights" parameter.

Description (should be):
Generates an index of a DataSet taking an average of weighted closing prices and accounting for the effects of stock splits. The weight of each component is 1.0 unless specified as follows, e.g., AAPL=1.25, BA=0.75, GOOGL=1.2
0

Reply

Bookmark

Sort