Beispiel #1
0
        private static decimal FindTWMarginRequirement(string account, Positions positions)
        {
            Position pos = positions.ElementAt(0).Value;

            // this loop could be eliminated if the long symbol name gets persisted in database
            foreach (KeyValuePair <string, TWMargin> p in twMarginReq[account])
            {
                TWMargin mar = p.Value;
                if (pos.Symbol == mar.Symbol)
                {
                    return(mar.CapitalRequirement);
                }
            }

            return(0M);
        }
Beispiel #2
0
        private static decimal DefaultCapital(string account, string strat, Positions positions)
        {
            decimal multiplier = 100;

            TWPosition twpos = FindTWPosition(account, positions.ElementAt(0).Value);

            if (twpos != null)
            {
                multiplier = twpos.Multiplier;
            }


            if (strat.Length >= 8)
            {
                strat = strat.Substring(0, 8);
                if ((strat == "Iron Con") || (strat == "Vertical"))
                {
                    Dictionary <string, decimal> strikeRange = new Dictionary <string, decimal> {
                        { "Call", 0 }, { "Put", 0 }
                    };

                    foreach (KeyValuePair <string, Position> item in positions)
                    {
                        Position p = item.Value;
                        strikeRange[p.Type] += (p.Strike * p.Quantity);
                    }
                    if (Math.Abs(strikeRange["Put"]) > Math.Abs(strikeRange["Call"]))
                    {
                        return(Math.Abs(strikeRange["Put"]) * multiplier);
                    }
                    else
                    {
                        return(Math.Abs(strikeRange["Call"]) * multiplier);
                    }
                }
            }
            return(0);
        }
Beispiel #3
0
        private static string GuessStrategy(Positions positions)
        {
            string retval = "";

            if (positions.Count == 1)
            {
                retval  = positions.ElementAt(0).Value.Quantity < 0 ? "Short " : "Long ";
                retval += positions.ElementAt(0).Value.Type;
            }
            else if (positions.Count == 2)
            {
                if (positions.ElementAt(0).Value.ExpDate != positions.ElementAt(1).Value.ExpDate)
                {
                    retval = "Calendar Spread";
                }
                else if (positions.ElementAt(0).Value.Type == positions.ElementAt(1).Value.Type)
                {
                    if ((positions.ElementAt(0).Value.Quantity + positions.ElementAt(1).Value.Quantity) != 0)
                    {
                        retval = "Ratio " + positions.ElementAt(0).Value.Type + " Spread";
                    }
                    else
                    {
                        retval = "Vertical " + positions.ElementAt(0).Value.Type + " Spread";
                    }
                }
                else if (positions.ElementAt(0).Value.Strike == positions.ElementAt(1).Value.Strike)
                {
                    retval = "Straddle";
                }
                else
                {
                    retval = "Strangle";
                }
            }
            else if (positions.Count == 4)
            {
                decimal  sum       = 0;
                DateTime expDate   = DateTime.MinValue;
                bool     dateError = false;

                foreach (KeyValuePair <string, Position> item in positions)
                {
                    Position p = item.Value;
                    sum += p.Quantity;
                    if (expDate == DateTime.MinValue)
                    {
                        expDate = p.ExpDate;  // set date first time thru
                    }
                    else if (expDate != p.ExpDate)
                    {
                        dateError = true;   // set flag if any dates don't match
                    }
                    if (sum == 0)
                    {
                        if (dateError)
                        {
                            retval = "Calendar Spread";
                        }
                        else
                        {
                            retval = "Iron Condor";
                        }
                    }
                }
            }

            return(retval += "");
        }