Supported Indicators
Cross Sectional Information Coefficient
Introduction
The cross-sectional information coefficient (IC) is the standard IC of factor research: each period, it is the Spearman correlation across many assets between their signal values at the end of the previous period and their returns over this period. The indicator owns one signal per asset: each input updates its asset's signal first, so the signals must not be updated elsewhere, such as by an algorithm helper that registered them. The indicator throws when it detects such an update. The signals can't be built from other indicators, as TimeSeriesInformationCoefficient explains. An asset's price is its input's value. Inputs whose end times fall in the same UTC period, at the inputs' resolution, form a period, so assets whose bars end at different local times, such as futures of different exchanges, share their daily periods. The indicator correlates a period as soon as every asset it tracks has an input for it. Otherwise, such as when an asset was delisted, it correlates the assets that have one when the next period starts. Each value has the end time of its period's last input, in the exchange time zone of the first asset given at construction. A period needs at least three assets with a signal value and a return. An asset with no input for a period pairs its last signal value with its return since then. Use Add and Remove to follow a changing cross-section, such as a universe's constituents.
To view the implementation of this indicator, see the LEAN GitHub repository.
Using CSIC Indicator
To create an automatic indicator for CrossSectionalInformationCoefficient, call the CSICcsic helper method from the QCAlgorithm class. The CSICcsic method creates a CrossSectionalInformationCoefficient object, hooks it up for automatic updates, and returns it so you can use it in your algorithm. In most cases, you should call the helper method in the Initializeinitialize method.
public class CrossSectionalInformationCoefficientAlgorithm : QCAlgorithm
{
private Symbol[] _symbols;
private CrossSectionalInformationCoefficient _csic;
public override void Initialize()
{
_symbols = new[] { "QQQ", "SPY", "IWM" }.Select(ticker => AddEquity(ticker, Resolution.Daily).Symbol).ToArray();
_csic = CSIC(_symbols, symbol => new RateOfChange(5));
}
public override void OnData(Slice data)
{
if (_csic.IsReady)
{
// The current value of _csic is represented by itself (_csic)
// or _csic.Current.Value
Plot("CrossSectionalInformationCoefficient", "csic", _csic);
}
}
} class CrossSectionalInformationCoefficientAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbols = [self.add_equity(ticker, Resolution.DAILY).symbol for ticker in ["QQQ", "SPY", "IWM"]]
self._csic = self.csic(self._symbols, lambda symbol: RateOfChange(5))
def on_data(self, slice: Slice) -> None:
if self._csic.is_ready:
# The current value of self._csic is represented by self._csic.current.value
self.plot("CrossSectionalInformationCoefficient", "csic", self._csic.current.value)To create an automatic indicator for CrossSectionalInformationCoefficient using universe constituents, call the CSICcsic helper method from the QCAlgorithm class. The CSICcsic method creates a CrossSectionalInformationCoefficient object, hooks it up for automatic updates, and returns it so you can use it in your algorithm. In this case, you should call the helper method in the OnSecuritiesChangedon_securities_changed method.
public class CrossSectionalInformationCoefficientAlgorithm : QCAlgorithm
{
private Universe _universe;
private CrossSectionalInformationCoefficient _csic;
public override void Initialize()
{
SetStartDate(2024,1,1);
SetEndDate(2024,12,31);
UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.Schedule.On(DateRules.MonthStart());
_universe = AddUniverse(Universe.ETF("SPY"));
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
_csic = CSIC(_universe.Selected, symbol => new RateOfChange(5));
}
public override void OnData(Slice data)
{
if (_csic.IsReady)
{
// The current value of _csic is represented by itself (_csic)
// or _csic.Current.Value
Plot("CrossSectionalInformationCoefficient", "csic", _csic);
}
}
} class CrossSectionalInformationCoefficientAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024,1,1)
self.set_end_date(2024,12,31)
self.universe_settings.resolution = Resolution.DAILY
self.universe_settings.schedule.on(self.date_rules.month_start())
self._universe = self.add_universe(self.universe.etf('SPY'))
def on_securities_changed(self, changes: SecurityChanges) -> None:
self._csic = self.csic(list(self._universe.selected), lambda symbol: RateOfChange(5))
def on_data(self, slice: Slice) -> None:
if self._csic.is_ready:
# The current value of self._csic is represented by self._csic.current.value
self.plot("CrossSectionalInformationCoefficient", "csic", self._csic.current.value)For more information about this method, see the QCAlgorithm classQCAlgorithm class.
You can manually create a CrossSectionalInformationCoefficient indicator, so it doesn't automatically update. Manual indicators let you update their values with any data you choose.
Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Updateupdate method. The indicator will only be ready after you prime it with enough data.
public class CrossSectionalInformationCoefficientAlgorithm : QCAlgorithm
{
private Symbol[] _symbols;
private CrossSectionalInformationCoefficient _crosssectionalinformationcoefficient;
public override void Initialize()
{
_symbols = new[] { "QQQ", "SPY", "IWM" }.Select(ticker => AddEquity(ticker, Resolution.Daily).Symbol).ToArray();
_crosssectionalinformationcoefficient = new CrossSectionalInformationCoefficient(_symbols, symbol => new RateOfChange(5));
}
public override void OnData(Slice data)
{
foreach (var symbol in _symbols)
{
if (data.Bars.TryGetValue(symbol, out var bar))
_crosssectionalinformationcoefficient.Update(bar);
}
if (_crosssectionalinformationcoefficient.IsReady)
{
// The current value of _crosssectionalinformationcoefficient is represented by itself (_crosssectionalinformationcoefficient)
// or _crosssectionalinformationcoefficient.Current.Value
Plot("CrossSectionalInformationCoefficient", "crosssectionalinformationcoefficient", _crosssectionalinformationcoefficient);
}
}
} class CrossSectionalInformationCoefficientAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbols = [self.add_equity(ticker, Resolution.DAILY).symbol for ticker in ["QQQ", "SPY", "IWM"]]
self._crosssectionalinformationcoefficient = CrossSectionalInformationCoefficient(self._symbols, lambda symbol: RateOfChange(5))
def on_data(self, slice: Slice) -> None:
for symbol in self._symbols:
bar = slice.bars.get(symbol)
if bar:
self._crosssectionalinformationcoefficient.update(bar)
if self._crosssectionalinformationcoefficient.is_ready:
# The current value of self._crosssectionalinformationcoefficient is represented by self._crosssectionalinformationcoefficient.current.value
self.plot("CrossSectionalInformationCoefficient", "crosssectionalinformationcoefficient", self._crosssectionalinformationcoefficient.current.value)For more information about this indicator, see its referencereference.
Indicator History
To get the historical data of the CrossSectionalInformationCoefficient indicator, call the IndicatorHistoryself.indicator_history method. This method resets your indicator, makes a history request, and updates the indicator with the historical data. Just like with regular history requests, the IndicatorHistoryindicator_history method supports time periods based on a trailing number of bars, a trailing period of time, or a defined period of time. If you don't provide a resolution argument, it defaults to match the resolution of the security subscription.
public class CrossSectionalInformationCoefficientAlgorithm : QCAlgorithm
{
private Symbol[] _symbols;
private CrossSectionalInformationCoefficient _csic;
public override void Initialize()
{
_symbols = new[] { "QQQ", "SPY", "IWM" }.Select(ticker => AddEquity(ticker, Resolution.Daily).Symbol).ToArray();
_csic = CSIC(_symbols, symbol => new RateOfChange(5));
var indicatorHistory = IndicatorHistory(_csic, _symbols, 100, Resolution.Minute);
var timeSpanIndicatorHistory = IndicatorHistory(_csic, _symbols, TimeSpan.FromDays(10), Resolution.Minute);
var timePeriodIndicatorHistory = IndicatorHistory(_csic, _symbols, new DateTime(2024, 7, 1), new DateTime(2024, 7, 5), Resolution.Minute);
}
} class CrossSectionalInformationCoefficientAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbols = [self.add_equity(ticker, Resolution.DAILY).symbol for ticker in ["QQQ", "SPY", "IWM"]]
self._csic = self.csic(self._symbols, lambda symbol: RateOfChange(5))
indicator_history = self.indicator_history(self._csic, self._symbols, 100, Resolution.MINUTE)
timedelta_indicator_history = self.indicator_history(self._csic, self._symbols, timedelta(days=10), Resolution.MINUTE)
time_period_indicator_history = self.indicator_history(self._csic, self._symbols, datetime(2024, 7, 1), datetime(2024, 7, 5), Resolution.MINUTE)
