コード例 #1
0
        public void CSharpReturnNullTest(dynamic input)
        {
            var qb   = new QuantBook();
            var data = qb.GetFundamental(input[0], input[1], input[2], input[3]);

            Assert.IsEmpty(data);
        }
コード例 #2
0
        public void FuturesOptionsWithFutureOptionContract()
        {
            using (Py.GIL())
            {
                var qb           = new QuantBook();
                var expiry       = new DateTime(2020, 3, 20);
                var future       = Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, expiry);
                var futureOption = Symbol.CreateOption(
                    future,
                    future.ID.Market,
                    OptionStyle.American,
                    OptionRight.Call,
                    3300m,
                    expiry);

                var     start   = new DateTime(2020, 1, 5);
                var     end     = new DateTime(2020, 1, 6);
                var     history = qb.GetOptionHistory(futureOption, start, end, Resolution.Minute);
                dynamic df      = history.GetAllData();

                Assert.IsNotNull(df);
                Assert.IsFalse((bool)df.empty.AsManagedObject(typeof(bool)));
                Assert.AreEqual(360, (int)df.__len__().AsManagedObject(typeof(int)));
                Assert.AreEqual(5, (int)df.index.levels.__len__().AsManagedObject(typeof(int)));
                Assert.IsTrue((bool)df.index.levels[0].__contains__(expiry.ToStringInvariant("yyyy-MM-dd")).AsManagedObject(typeof(bool)));
            }
        }
コード例 #3
0
        public void OptionUnderlyingSymbolQuantBookHistory()
        {
            var qb         = new QuantBook();
            var twx        = qb.AddEquity("TWX");
            var twxOptions = qb.AddOption("TWX");

            var historyByOptionSymbol = qb.GetOptionHistory(twxOptions.Symbol, new DateTime(2014, 6, 5), new DateTime(2014, 6, 6));
            var historyByEquitySymbol = qb.GetOptionHistory(twx.Symbol, new DateTime(2014, 6, 5), new DateTime(2014, 6, 6));

            List <DateTime> expiry;
            List <DateTime> byUnderlyingExpiry;

            historyByOptionSymbol.GetExpiryDates().TryConvert(out expiry);
            historyByEquitySymbol.GetExpiryDates().TryConvert(out byUnderlyingExpiry);

            List <decimal> strikes;
            List <decimal> byUnderlyingStrikes;

            historyByOptionSymbol.GetStrikes().TryConvert(out strikes);
            historyByEquitySymbol.GetStrikes().TryConvert(out byUnderlyingStrikes);

            Assert.IsTrue(expiry.Count > 0);
            Assert.IsTrue(expiry.SequenceEqual(byUnderlyingExpiry));

            Assert.IsTrue(strikes.Count > 0);
            Assert.IsTrue(strikes.SequenceEqual(byUnderlyingStrikes));
        }
コード例 #4
0
        public void CanoicalFutureCrashesGetOptionHistory()
        {
            var qb     = new QuantBook();
            var future = Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);

            Assert.Throws <ArgumentException>(() =>
            {
                qb.GetOptionHistory(future, default(DateTime), DateTime.MaxValue, Resolution.Minute);
            });
        }
コード例 #5
0
        public void DefaultEndDate()
        {
            var qb           = new QuantBook();
            var startDate    = DateTime.UtcNow.Date.AddDays(-2);
            var expectedDate = DateTime.UtcNow.Date;
            IEnumerable <DataDictionary <dynamic> > data = qb.GetFundamental("AAPL", "ValuationRatios.PERatio", startDate);

            // Check that the last day in the collection is as expected (today)
            var lastDay = data.Last();

            Assert.AreEqual(expectedDate, lastDay.Time);
        }
コード例 #6
0
        public void CSharpFundamentalData(dynamic input)
        {
            var qb   = new QuantBook();
            var data = qb.GetFundamental(input[0], input[1], _startDate, _endDate);

            foreach (var day in data)
            {
                foreach (var value in day.Values)
                {
                    Assert.AreEqual(input[2], value);
                    Assert.AreEqual(_startDate, day.Time);
                }
            }
        }
コード例 #7
0
        public void Setup()
        {
            // Store initial handler
            _logHandler = Log.LogHandler;

            SymbolCache.Clear();
            MarketHoursDatabase.Reset();

            // Using a date that we have data for in the repo
            _startDate = new DateTime(2014, 3, 31);
            _endDate   = new DateTime(2014, 3, 31);

            // Our qb instance to test on
            _qb = new QuantBook();

            using (Py.GIL())
            {
                _module = Py.Import("Test_QuantBookHistory");
            }
        }
コード例 #8
0
        public void QuantBookObjectStoreBehavior()
        {
            // Test for issue #4811, on loop store objects would duplicate
            for (int i = 0; i < 3; i++)
            {
                // Create a QuantBook and save some data
                var qb = new QuantBook();
                qb.ObjectStore.Save("a.txt", "1010101010101010101010");
                Assert.IsTrue(qb.ObjectStore.ContainsKey("a.txt"));

                // Assert the store has only a.txt
                var store = qb.ObjectStore.GetEnumerator().AsEnumerable().ToList();
                Assert.IsTrue(store.Count == 1);
                Assert.IsTrue(store[0].Key == "a.txt");

                // Get the file path and verify it exists
                var path = qb.ObjectStore.GetFilePath("a.txt");
                Assert.IsTrue(File.Exists(path));
            }
        }