Exemplo n.º 1
0
 public void PlotNetPosition(Slice slice)
 {
     _longHoldingsCount.AddPoint(slice.Time, OptionTools.GetHoldingQuantity(this, _primarySymbol, true, false));
     _shortHoldingsCount.AddPoint(slice.Time, -OptionTools.GetHoldingQuantity(this, _primarySymbol, false, true));
     _longOpenOrdersCount.AddPoint(slice.Time, OptionTools.GetOpenOrderQuantity(this, _primarySymbol, true, false));
     _shortOpenOrdersCount.AddPoint(slice.Time, -OptionTools.GetOpenOrderQuantity(this, _primarySymbol, false, true));
 }
Exemplo n.º 2
0
        protected virtual List <IPortfolioTarget> IncrementOptionPositions(QCAlgorithmFramework algorithm, Symbol baseSymbol, IEnumerable <OptionHolding> holdings, Insight insight)
        {
            //don't touch anything if there are orders still pending
            if (OptionTools.GetOpenOrderQuantity(algorithm, baseSymbol, true, true) > 0)
            {
                return(null);
            }

            var targets = new List <IPortfolioTarget>();

            holdings.All(p =>
            {
                targets.Add(new PortfolioTarget(p.Symbol, p.Quantity + this.PositionSize));
                return(true);
            });
            return(targets);
        }
Exemplo n.º 3
0
        public sealed override List <IPortfolioTarget> OpenTargetsFromInsight(QCAlgorithmFramework algorithm, Symbol baseSymbol, Insight insight)
        {
            var currentHoldings   = GetOptionHoldings(algorithm, baseSymbol);
            var pendingOrderCount = OptionTools.GetOpenOrderQuantity(algorithm, baseSymbol, true, true);

            if (this.PrintPosition)
            {
                algorithm.Log("pending orders: " + pendingOrderCount);
                foreach (var holding in currentHoldings)
                {
                    algorithm.Log("holding: " + holding.Symbol + "\t" + holding.Quantity + "\t" + holding.UnrealizedProfit);
                }
            }

            if (currentHoldings.Count() > 0 ||
                pendingOrderCount > 0)
            {
                this.SanityCheckHoldings(algorithm, currentHoldings);

                if (insight.Direction == InsightDirection.Flat)
                {
                    //create a target to close holdings
                    return(this.LiquidateOptions(algorithm, currentHoldings));
                }
                else
                {
                    //TODO: close pending orders too???
                    var closingTargets = PossiblyCloseCurrentTargets(algorithm, baseSymbol, currentHoldings, insight);
                    if (closingTargets == null || closingTargets.Count > 0)
                    {
                        return(closingTargets);
                    }

                    //if we aren't closing anything, then add to open position
                    return(this.IncrementOptionPositions(algorithm, baseSymbol, currentHoldings, insight));
                }
            }
            else
            {
                return(FindPotentialOptions(algorithm, baseSymbol, insight));
            }
        }