Example #1
0
        public bool isChecked(int i)
        {
            var            val    = lstOptions.ElementAt(i);
            TDAOptionQuote option = val[0];

            return(option.isChecked);
        }
Example #2
0
 public string classChanged(string fieldName, TDAOptionQuote prevOption, TDAOptionQuote option)
 {
     if (prevOption != null)
     {
         var prevAmt = prevOption[fieldName];
         var currAmt = option[fieldName];
         return(classColor <dynamic>
                    (ref prevAmt, ref currAmt));
     }
     else
     {
         return("");
     }
 }
Example #3
0
        /// <summary>
        /// Determine # of TDAParameters.contracts at each strike before
        /// </summary>
        /// <remarks>
        /// Has to be recalced if Buys, Depth or Strikes changes, so just do at top of cycle
        /// </remarks>
        public void contractsAllocate()
        {
            /// First, build dictCredits based on 100*prem for list of checked strikes? e.g. 0:52, 2:26, 4:13
            dictCredits = new Dictionary <int, double>();

            Dictionary <int, double> dictMultiples = new Dictionary <int, double>();
            double parts = 0;

            for (int i = 0; i < lstOptions.Length - 1; i++)
            {
                if (TDASpreadManager.isInDepthAndParity(i))
                /// If strike indexes within the Depth
                {
                    var            optionsList     = lstOptions.ElementAt(i);
                    TDAOptionQuote option          = optionsList[0];
                    var            optionsLongList = lstOptions.ElementAt(i + 1);
                    TDAOptionQuote optionLong      = optionsList[0];
                    var            valPrem         = 100 * (option.bid - optionLong.ask);

                    var hasKey    = TDAParameters.dictOptionCheckbox.ContainsKey(option.description);
                    var isChecked = true;
                    if (hasKey)
                    {
                        isChecked = TDAParameters.dictOptionCheckbox[option.description];
                    }
                    if (isChecked)
                    {
                        dictCredits.Add(i, valPrem);
                        /// iMult is inverted multiple of most e.g. 2 if you are 1/2 of most
                        double iMult = 1;
                        switch (TDAParameters.allocation)
                        {
                        case "Geometric":
                            iMult  = Math.Round(dictCredits.Values.First() / valPrem, 0);
                            iMult *= iMult;
                            break;

                        case "Equal Contracts":
                            iMult = 1;
                            break;

                        case "Progressive":
                            iMult = Math.Round(dictCredits.Values.First() / valPrem, 0);
                            break;

                        case "Equal Credit":
                            iMult = dictCredits.Values.First() / valPrem;
                            break;

                        case "Average":
                            iMult = dictCredits.Values.First() / valPrem;
                            iMult = iMult * iMult + iMult;
                            break;

                        default:
                            break;
                        }

                        dictMultiples.Add(i, iMult);
                        parts += iMult;
                    }
                }
            }
            /// Now get the number of TDAParameters.contracts per part, the multiple
            double mult = Math.Floor(TDAParameters.optionNumContracts / parts);

            /// So dictCredits has values like [52,26,13]
            /// and dictMults has values like [1,2,4]
            /// and parts is = 7
            /// and mult is 50 / 7 = 7
            /// So contracts becomes 7, 14, 28 = 49 total
            for (var i = 0; i < dictCredits.Values.Count; i++)
            {
                var key = dictCredits.ElementAt(i).Key;
                if (dictMultiples.ContainsKey(key))
                {
                    var            contracts   = mult * dictMultiples[key];
                    var            optionsList = lstOptions.ElementAt(key);
                    TDAOptionQuote option      = optionsList[0];
                    try
                    {
                        var isManual = TDAParameters.dictIsManualContracts.ContainsKey(option.description) &&
                                       TDAParameters.dictIsManualContracts[option.description];

                        if (!isManual)
                        {
                            if (TDAParameters.dictOptionContracts.ContainsKey(option.description))
                            {
                                TDAParameters.dictOptionContracts[option.description] = Convert.ToInt32(contracts);
                            }
                            else
                            {
                                TDAParameters.dictOptionContracts.Add(option.description, Convert.ToInt32(contracts));
                            }
                            option.contracts = Convert.ToInt32(contracts);
                        }
                    }
                    catch (Exception exx)
                    {
                        Console.WriteLine(exx.Message);
                    }
                }
            }
        }
Example #4
0
        public void getOptionQuote(int i, ref TDAOptionQuote option, ref TDAOptionQuote longOption)
        {
            if (lstOptions[0][0].symbol.LastIndexOf("C") > lstOptions[0][0].symbol.LastIndexOf("P"))
            {
                lstOptions = TDA.callOptions;
            }
            else
            {
                lstOptions = TDA.putOptions;
            }

            if (i < lstOptions.Length - 1)
            {
                var next = lstOptions.ElementAt(i + 1);

                if (TDAParameters.inTheMoney)
                {
                    if (i == 0)
                    {
                        if (otmOptions != null)
                        {
                            next = otmOptions.ElementAt(0);
                        }
                    }
                    else
                    {
                        next = lstOptions.ElementAt(i - 1);
                    }
                }

                TDAOptionQuote nextOption = next[0];

                option.prem = option.bid - nextOption.ask;
            }

            if (i + TDAParameters.optionNumSpreadStrikes < lstOptions.Length)
            {
                var next2 = lstOptions.ElementAt(i + TDAParameters.optionNumSpreadStrikes);
                if (TDAParameters.inTheMoney)
                {
                    if (i == TDAParameters.optionNumSpreadStrikes - 1)
                    {
                        if (otmOptions != null)
                        {
                            next2 = otmOptions.ElementAt(i + (TDAParameters.optionNumSpreadStrikes - 1));
                        }
                    }
                    else
                    if (i >= TDAParameters.optionNumSpreadStrikes)
                    {
                        next2 = lstOptions.ElementAt(i - TDAParameters.optionNumSpreadStrikes);
                    }
                }

                longOption   = next2[0];
                option.prem2 = option.bid - longOption.ask;

                option.buyOption = longOption.symbol;
                var    sellOption = option.symbol;
                string longStrike = "";
                if (option.buyOption.LastIndexOf("C") > option.buyOption.LastIndexOf("P"))
                {
                    longStrike       = Regex.Split(option.buyOption, "C").Last();
                    option.buyOption = "C" + longStrike;
                }
                else
                {
                    longStrike       = Regex.Split(option.buyOption, "P").Last();
                    option.buyOption = "P" + longStrike;
                }
                option.maxLoss       = Math.Abs(option.strikePrice - Convert.ToSingle(longStrike)) - option.prem2;
                option.breakeven     = option.strikePrice + option.prem2;
                option.index         = i;
                option.buyLongStrike = Convert.ToSingle(longStrike);
                var hasKey    = TDAParameters.dictOptionCheckbox.ContainsKey(option.description);
                var isChecked = true;
                if (hasKey)
                {
                    isChecked = TDAParameters.dictOptionCheckbox[option.description];
                }
                if (TDAParameters.sellOptionIndex != -1)
                {
                    if (TDASpreadManager.isInDepthAndParity(i))
                    {
                        option.isChecked = isChecked;
                    }
                }
                //var tokenTimeStampAsDateObj = new Date(userPrincipalsResponse.streamerInfo.tokenTimestamp);
                //var tokenTimeStampAsMs = tokenTimeStampAsDateObj.getTime();
                if (option.isChecked)
                {
                    //var contracts = (float)TDAParameters.contracts[i];
                    option.credit     = option.contracts * 100 * option.prem2;
                    option.collateral = option.contracts * 100 * Math.Abs(option.strikePrice - longOption.strikePrice) - option.credit;

                    totalCollateral += option.collateral;
                    totalContracts  += option.contracts;
                    totalCredit     += option.credit;
                }
            }
        }
Example #5
0
 public string showChecked(TDAOptionQuote option, string val)
 {
     return(option.isChecked ? val : " ");
 }