Создание WeightedIndexSecurity из исторических данных (получить исторический спред 2-х инструментов)


Создание WeightedIndexSecurity из исторических данных (получить исторический спред 2-х инструментов)
Atom
21.12.2017


Здравствуйте.

Подскажите, как правильно создать 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-х инструментов?


< 1 2 
Дмитрий_

Фотография
Дата: 31.12.2017
Ответить


Спасибо за ссылку.
Я перечитал её, и не смог найти информацию по построению спреда напрямую из хранящихся у меня данных, но по находящимся там ссылкам нашёл, то что связано со Storage и IndexSecurity.
Это класс IndexSecurityMarketDataStorage<T> http://doc.stocksharp.ru...MarketDataStorage_1.htm
О нём шла речь?

С Наступающим Вас!
Спасибо:

Support

Фотография
Дата: 04.01.2018
Ответить


Хранилище работает с индексом как с обычным инструментом. Отдельно для каждого типа инструмента нет документации так как хранилище универсальное.
Спасибо:

Дмитрий_

Фотография
Дата: 05.01.2018
Ответить


_leg1TimeFrameCandles = LoadTimeFrameCandlesFromStorage(_leg1Security,
_timeFrame,
HistoryPath.Folder.ToFullPath(),
StorageFormats.Binary,
new DateTimeOffset(from),
new DateTimeOffset(to));

_leg2TimeFrameCandles = LoadTimeFrameCandlesFromStorage(_leg2Security,
_timeFrame,
HistoryPath.Folder.ToFullPath(),
StorageFormats.Binary,
new DateTimeOffset(from),
new DateTimeOffset(to));

WeightedIndexSecurity _spreadTestSecurity = new WeightedIndexSecurity()
{
Id = "Index1",
Type= SecurityTypes.Stock,
Board = ExchangeBoard.MicexTqbr
};
_spreadTestSecurity.Weights.Add(_leg1Security.Id.ToSecurityId(), Convert.ToDecimal(1));
_spreadTestSecurity.Weights.Add(_leg2Security.Id.ToSecurityId(), Convert.ToDecimal(-1));

_spreadTestTimeFrameCandles = LoadTimeFrameCandlesFromStorage(_spreadTestSecurity,
_timeFrame,
HistoryPath.Folder.ToFullPath(),
StorageFormats.Binary,
new DateTimeOffset(from),
new DateTimeOffset(to));


private IEnumerable<Candle> LoadTimeFrameCandlesFromStorage(Security security, TimeSpan timeframe, string path, StorageFormats format, DateTimeOffset from, DateTimeOffset to)
{
var storageRegistry = new StorageRegistry();
var storage = storageRegistry.GetCandleStorage(typeof(TimeFrameCandle), security, timeframe, new LocalMarketDataDrive(path), format);

return storage.Load(from, to);
}


Capture.PNGCapture1.PNGCapture2.PNG


C помощью метода LoadTimeFrameCandlesFromStorage загружаю свечи:
_leg1TimeFrameCandles - Ок,
_leg2TimeFrameCandles - Ок,
_spreadTestTimeFrameCandles - не Ок, хотя с индексом работаю как с обычным инструментом. Я что-то путаю?
Capture.PNG 63 KB (480) Capture2.PNG 15 KB (479) Capture1.PNG 59 KB (492)
Спасибо:

Дмитрий_

Фотография
Дата: 05.01.2018
Ответить


Аналогична ситуация и с
ExpressionIndexSecurity _spreadTestSecurity = new ExpressionIndexSecurity()
{
Id = "Index1",
Expression = "SBER@TQBR-SBERP@TQBR",
Type = SecurityTypes.Stock,
Board = ExchangeBoard.MicexTqbr
};
Спасибо:

Дмитрий_

Фотография
Дата: 09.01.2018
Ответить


Детальная информация
Снимок.PNG
Снимок1.PNG
Данных не найдено
Снимок2.PNG
Обращается по пути, которого нет
Снимок3.PNG
Снимок4.PNG

WeightedIndexSecurity _spreadTestSecurity = new WeightedIndexSecurity()
{
Id = "Index1",
Type= SecurityTypes.Stock,
Board = ExchangeBoard.MicexTqbr
};
_spreadTestSecurity.Weights.Add(_leg1Security.Id.ToSecurityId(), Convert.ToDecimal(1));
_spreadTestSecurity.Weights.Add(_leg2Security.Id.ToSecurityId(), Convert.ToDecimal(-1));
Снимок3.PNG 33 KB (466) Снимок4.PNG 39 KB (466) Снимок2.PNG 19 KB (427) Снимок1.PNG 19 KB (845) Снимок.PNG 18 KB (469)
Спасибо: Иван З.

Support

Фотография
Дата: 09.01.2018
Ответить


Добрый день

Попробуйте такой код

Код
var basketStorage = new IndexSecurityMarketDataStorage<CandleMessage>(_spreadTestSecurity, tf);

basketStorage.InnerStorages.Add(storageRegistry.GetCandleStorage(typeof(TimeFrameCandle), _leg1Security, tf, new LocalMarketDataDrive(path)));
basketStorage.InnerStorages.Add(storageRegistry.GetCandleStorage(typeof(TimeFrameCandle), _leg2Security, tf, new LocalMarketDataDrive(path)));

var candles = basketStorage.Load(from, to);
Спасибо: Иван З. Дмитрий_

Support

Фотография
Дата: 09.01.2018
Ответить


Дмитрий Антипов Перейти
Аналогична ситуация и с
ExpressionIndexSecurity _spreadTestSecurity = new ExpressionIndexSecurity()
{
Id = "Index1",
Expression = "SBER@TQBR-SBERP@TQBR",
Type = SecurityTypes.Stock,
Board = ExchangeBoard.MicexTqbr
};


Для этого необходимо использовать специальные компилятор, зарегистрированный при старте программы:

Код
ConfigManager.RegisterService<ICompilerService>(new RoslynCompilerService());


Спасибо: Иван З. Дмитрий_
< 1 2 

Добавить файлы через драг-н-дроп, , или вставить из буфера обмена.

loading
clippy