コード例 #1
0
        public void WarmUpPythonIndicatorProperly()
        {
            var algo = new AlgorithmStub
            {
                HistoryProvider = new SubscriptionDataReaderHistoryProvider()
            };
            var zipCacheProvider = new ZipDataCacheProvider(TestGlobals.DataProvider);

            algo.HistoryProvider.Initialize(new HistoryProviderInitializeParameters(
                                                null,
                                                null,
                                                TestGlobals.DataProvider,
                                                zipCacheProvider,
                                                TestGlobals.MapFileProvider,
                                                TestGlobals.FactorFileProvider,
                                                null,
                                                false,
                                                new DataPermissionManager()));
            algo.SetStartDate(2013, 10, 08);
            algo.AddEquity("SPY", Resolution.Minute);

            // Different types of indicators
            var indicatorDataPoint = new SimpleMovingAverage("SPY", 10);
            var indicatorDataBar   = new AverageTrueRange("SPY", 10);
            var indicatorTradeBar  = new VolumeWeightedAveragePriceIndicator("SPY", 10);

            using (Py.GIL())
            {
                var sma   = indicatorDataPoint.ToPython();
                var atr   = indicatorTradeBar.ToPython();
                var vwapi = indicatorDataBar.ToPython();

                Assert.DoesNotThrow(() => algo.WarmUpIndicator("SPY", sma, Resolution.Minute));
                Assert.DoesNotThrow(() => algo.WarmUpIndicator("SPY", atr, Resolution.Minute));
                Assert.DoesNotThrow(() => algo.WarmUpIndicator("SPY", vwapi, Resolution.Minute));

                var smaIsReady   = ((dynamic)sma).IsReady;
                var atrIsReady   = ((dynamic)atr).IsReady;
                var vwapiIsReady = ((dynamic)vwapi).IsReady;

                Assert.IsTrue(smaIsReady.IsTrue());
                Assert.IsTrue(atrIsReady.IsTrue());
                Assert.IsTrue(vwapiIsReady.IsTrue());
            }

            zipCacheProvider.DisposeSafely();
        }