Esempio n. 1
0
        private static void GetTTupleList <T>(PyObject obj, ref List <T> result)
        {
            PyIter iter = new PyIter(obj);

            while (iter.MoveNext())
            {
                var r = iter.Current.ToPython();
                if (PyTuple.IsTupleType(r))
                {
                    GetTTupleList <T>(r, ref result);
                    continue;
                }

                switch (typeof(T).Name)
                {
                case "Single":
                case "Double":
                case "Int32":
                case "Int64":
                case "UInt32":
                case "UInt64":
                case "Byte":
                case "Object":
                case "String":
                case "SByte":
                    result.Add(r.As <T>());
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Scan the portfolio and the updated data for a potential margin call situation which may get the holdings below zero!
        /// If there is a margin call, liquidate the portfolio immediately before the portfolio gets sub zero.
        /// </summary>
        /// <param name="issueMarginCallWarning">Set to true if a warning should be issued to the algorithm</param>
        /// <returns>True for a margin call on the holdings.</returns>
        public List <SubmitOrderRequest> GetMarginCallOrders(out bool issueMarginCallWarning)
        {
            using (Py.GIL())
            {
                var value = _model.GetMarginCallOrders(out issueMarginCallWarning);

                // Since pythonnet does not support out parameters, the methods return
                // a tuple where the out parameter comes after the other returned values
                if (!PyTuple.IsTupleType(value))
                {
                    throw new ArgumentException($"{_model.__class__.__name__}.GetMarginCallOrders: Must return a tuple, where the first item is a list and the second a boolean");
                }

                // In this case, the first item holds the list of margin calls
                // and the second the out parameter 'issueMarginCallWarning'
                var marginCallOrders = value[0] as PyObject;
                issueMarginCallWarning = value[1];

                // Since GetMarginCallOrders may return a python list
                // Need to convert to C# list
                var requests = new List <SubmitOrderRequest>();
                foreach (PyObject pyObject in marginCallOrders)
                {
                    SubmitOrderRequest request;
                    if (pyObject.TryConvert(out request))
                    {
                        requests.Add(request);
                    }
                }
                issueMarginCallWarning |= requests.Count > 0;
                return(requests);
            }
        }
Esempio n. 3
0
 public void TestPyTupleIsTupleType()
 {
     using (Py.GIL())
     {
         var t = new PyTuple();
         Assert.IsTrue(PyTuple.IsTupleType(t));
     }
 }
Esempio n. 4
0
 public void TestStringIsTupleType()
 {
     using (Py.GIL())
     {
         var s = new PyString("foo");
         Assert.IsFalse(PyTuple.IsTupleType(s));
     }
 }
Esempio n. 5
0
        private static void GetNdListFromTuple(PyObject obj, ref List <NDarray> result)
        {
            PyIter iter = new PyIter(obj);

            while (iter.MoveNext())
            {
                var r = iter.Current.ToPython();

                if (PyTuple.IsTupleType(r))
                {
                    GetNdListFromTuple(r, ref result);
                    continue;
                }

                result.Add(new NDarray(r));
            }
        }
Esempio n. 6
0
        public void TestPyTupleIsTupleType()
        {
            var t = new PyTuple();

            Assert.True(PyTuple.IsTupleType(t));
        }
Esempio n. 7
0
        public void TestStringIsTupleType()
        {
            var s = new PyString("foo");

            Assert.False(PyTuple.IsTupleType(s));
        }