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

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


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

Подскажите, как правильно создать WeightedIndexSecurity из исторических данных?

Имею: Security _leg1Security = new Security() ; Security _leg2Security = new Security() ;

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)) ;

        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 
Дмитрий_

Avatar
Date: 12/31/2017
Reply


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

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

Thanks:

Support

Avatar
Date: 1/4/2018
Reply


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

Thanks:

Дмитрий_

Avatar
Date: 1/5/2018
Reply


_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 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 (934) Capture2.PNG 15 KB (905) Capture1.PNG 59 KB (961)
Thanks:

Дмитрий_

Avatar
Date: 1/5/2018
Reply


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

Thanks:

Дмитрий_

Avatar
Date: 1/9/2018
Reply


Детальная информация Снимок.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 (1007) Снимок4.PNG 39 KB (884) Снимок2.PNG 19 KB (894) Снимок1.PNG 19 KB (1876) Снимок.PNG 18 KB (970)
Thanks: Иван З.

Support

Avatar
Date: 1/9/2018
Reply


Добрый день

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

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);
Thanks: Иван З. Дмитрий_

Support

Avatar
Date: 1/9/2018
Reply


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

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

ConfigManager.RegisterService<ICompilerService>(new RoslynCompilerService());
Thanks: Иван З. Дмитрий_
< 1 2 

Attach files by dragging & dropping, , or pasting from the clipboard.

loading
clippy