Создание WeightedIndexSecurity из исторических данных (получить исторический спред 2-х инструментов)
Здравствуйте.
Подскажите, как правильно создать WeightedIndexSecurity из исторических данных?
Имею:
Security _leg1Security = new Security() { Id = "SBER@TQBR" };
Security _leg2Security = new Security() { Id = "SBERP@TQBR" };
DateTime from = new DateTime(2017, 1, 3).ChangeKind(DateTimeKind.Utc);
DateTime to = new DateTime(2017, 1, 4).ChangeKind(DateTimeKind.Utc);
private TimeSpan _timeFrame = TimeSpan.FromMinutes(1);
В переменных _leg1TimeFrameCandles и _leg2TimeFrameCandles исторические 1-мин свечи, загруженные из локального хранилища.
_portfolio = new Portfolio
{
Name = "Test Account",
BeginValue = 1000000,
};
WeightedIndexSecurity _spreadSecurity = new WeightedIndexSecurity() { Id = "Index1", Board = ExchangeBoard.Forts };
_spreadSecurity.Weights.Add(_leg1Security.Id.ToSecurityId(), Convert.ToDecimal(1));
_spreadSecurity.Weights.Add(_leg2Security.Id.ToSecurityId(), Convert.ToDecimal(-1));
var securityList = new List<Security> { _spreadSecurity };
var portfolioList = new List<Portfolio> { _portfolio };
_historyEmulationConnector = new HistoryEmulationConnector(securityList, portfolioList);
_spreadCandleSeries = new CandleSeries(typeof(TimeFrameCandle), _spreadSecurity, TimeSpan.FromMinutes(1)) { BuildCandlesMode = BuildCandlesModes.Build };
ConfigManager.RegisterService<ISecurityProvider>(_historyEmulationConnector);
CandleManager _spreadCandleManager = new CandleManager(_historyEmulationConnector);
_spreadCandleManager.Processing += DrawSpreadCandle;
_spreadCandleManager.Start(_spreadCandleSeries); (Исключение - System.InvalidOperationException: "Инструмент S#:SBER@TQBR, Native:,Type: не найден.")
private void DrawSpreadCandle(CandleSeries series, Candle candle)
{
Debug.WriteLine(string.Format("series= {0}, candle= {1}, candleseries= {2}", series.Security.Id, candle.Security.Id, _spreadCandleSeries.Security.Id));
var data = new ChartDrawData();
data.Group(candle.OpenTime).Add(_spreadChartCandleElement, candle);
try
{
Chart.Draw(data);
}
catch (Exception ex)
{
}
}
Как получить исторический спред этих 2-х инструментов?