I am attempting to construct an Indicator (or AddOn) which will return the basis between a spot index value and its associated current future contract (where basis = futures price - spot index value). It is my hope to use the basis in recent history to approximate the fair value of the future price (i.e. Spot index value + basis) for use in orders.
This requires :
- the series for spot index value and future price to be synced. It is my understanding this was cumbersome in NT7. I believe this has been addressed in NT8, Initializing a Series<T> with an Indicator Method.
- the same periodicity between spot index series and future series
Please find below (and attached) a failed attempt at synchronizing the two series and populating basisSeries.
Any advice / assistance would be appreciated.
public class Basis : Indicator { private Series<double> primarySeries; private Series<double> secondarySeries; private Series<double> basisSeries; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Basis = Futures price - Spot index value"; Name = "Basis"; Calculate = Calculate.OnBarClose; DisplayInDataBox = true; IsSuspendedWhileInactive = true; } else if (State == State.Configure) { // TODO align BarsPeriodType and period to primarySeries AddDataSeries("ES 03-16", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last); } else if (State == State.Historical) { // Syncs a Series object to the primary bar object primarySeries = new Series<double>(this); /* Syncs another Series object to the secondary bar object. We use an arbitrary indicator overloaded with an ISeries<double> input to achieve the sync. The indicator can be any indicator. The Series<double> will be synced to whatever the BarsArray[] is provided.*/ secondarySeries = new Series<double>(SMA(BarsArray[1], 50)); basisSeries = new Series<double>(this); basisSeries[0] = (Closes[0][0] - Closes[1][0]); } } protected override void OnBarUpdate() { Print(string.Format("{0} - Index ({1}) Future ({2}) = basis ({3})", Time[0].ToString("g"),Closes[0][0],Closes[1][0],Closes[2][0])); Value[0] = basisSeries[0]; } }
Shannon
Comment