Exemplo n.º 1
0
        protected void btnFilterResults_Click(object sender, EventArgs e)
        {
            FilterConditions filterConditions = new FilterConditions();

            filterConditions.SPLowerRange  = Convert.ToInt32(ddlSPLowerRange.SelectedValue);
            filterConditions.SPHigherRange = Convert.ToInt32(ddlSPHigherRange.SelectedValue);

            //if (ddlSPExpiry.SelectedValue.Equals("NONE"))
            //    filterConditions.SPExpiry = 0;
            //else
            //    filterConditions.SPExpiry = Convert.ToInt32(ddlSPExpiry.SelectedValue);

            filterConditions.ContractType    = ddlContractType.SelectedValue;
            filterConditions.OcType          = rblOCType.SelectedValue;
            filterConditions.StrategyType    = enumStrategyType.IRON_CONDOR.ToString();
            filterConditions.TimeGap         = timeAddGap;
            filterConditions.ExpiryDate      = ddlExpiryDates.SelectedValue;
            filterConditions.PercentageRange = iPercentageRage;
            filterConditions.SPDifference    = 100;

            DataSet dataSetResult = IronCondorClass.GetIronCondors(filterConditions);

            PopulateDataSet(dataSetResult);

            PopulateFilterFields(filterConditions);
        }
Exemplo n.º 2
0
        private void PopulateSPLowerRange(FilterConditions filterConditions)
        {
            int iLowerStrikePriceRange = OCHelper.RoundTo100(MySession.Current.RecordsObject.underlyingValue - (OCHelper.DefaultSP(rblOCType.SelectedValue) * iPercentageRage / 100));

            int iUpperStrikePrice = iLowerStrikePriceRange;

            ddlSPLowerRange.Items.Clear();

            foreach (int item in MySession.Current.RecordsObject.strikePrices)
            {
                if (item >= iLowerStrikePriceRange &&
                    item < MySession.Current.RecordsObject.underlyingValue &&
                    item % filterConditions.SPDifference == 0)
                {
                    ddlSPLowerRange.Items.Add(item.ToString());

                    //find the max strike price which meets this criteria to reduce filter size
                    iUpperStrikePrice = Math.Max(iUpperStrikePrice, item);
                }
            }

            //Select the Max strike price in the ddlb
            if (filterConditions.SPLowerRange == 0)
            {
                filterConditions.SPLowerRange = iUpperStrikePrice;
            }
            Utility.SelectDataInCombo(ddlSPLowerRange, filterConditions.SPLowerRange.ToString());
        }
Exemplo n.º 3
0
        protected void btnFilterResults_Click(object sender, EventArgs e)
        {
            FilterConditions filterConditions = new FilterConditions();

            filterConditions.SPLowerRange  = Convert.ToInt32(ddlSPLowerRange.SelectedValue);
            filterConditions.SPHigherRange = Convert.ToInt32(ddlSPHigherRange.SelectedValue);

            if (ddlSPExpiry.SelectedValue.Equals("NONE"))
            {
                filterConditions.SPExpiry = 0;
            }
            else
            {
                filterConditions.SPExpiry = Convert.ToInt32(ddlSPExpiry.SelectedValue);
            }

            filterConditions.ContractType    = ddlContractType.SelectedValue;
            filterConditions.OcType          = rblOCType.SelectedValue;
            filterConditions.StrategyType    = enumStrategyType.BUTTERFLY.ToString();
            filterConditions.TimeGap         = timeAddGap;
            filterConditions.ExpiryDate      = ddlExpiryDates.SelectedValue;
            filterConditions.PercentageRange = 0;
            filterConditions.SPDifference    = 100;

            DataSet dataSetResult = Strategy.FilterAll.FilterAllStrategies(filterConditions);

            PopulateDataSet(dataSetResult);

            PopulateFilterFields(filterConditions);
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            lblStart.Text = DateTime.Now.ToString();
            if (!IsPostBack)
            {
                FillExpiryDates(ddlExpiryDates);

                FilterConditions filterConditions = new FilterConditions();
                //filterConditions.SPLowerRange = MySession.Current.RecordsObject.strikePrices.Min();
                //filterConditions.SPHigherRange = MySession.Current.RecordsObject.strikePrices.Max();
                //filterConditions.SPExpiry = Convert.ToInt32(ddlSPExpiry.SelectedValue);
                filterConditions.ContractType    = ddlContractType.SelectedValue;
                filterConditions.OcType          = rblOCType.SelectedValue;
                filterConditions.StrategyType    = enumStrategyType.BUTTERFLY.ToString();
                filterConditions.TimeGap         = timeAddGap;
                filterConditions.ExpiryDate      = ddlExpiryDates.SelectedValue;
                filterConditions.PercentageRange = iPercentageRage;
                filterConditions.SPDifference    = 100;

                DataSet dataSetResult = Strategy.FilterAll.FilterAllStrategies(filterConditions);
                PopulateDataSet(dataSetResult);

                PopulateFilterFields(filterConditions);
                Page.LoadComplete += new EventHandler(Page_LoadComplete);
            }
        }
Exemplo n.º 5
0
        protected void btnFilterResults_Click(object sender, EventArgs e)
        {
            FilterConditions filterConditions = new FilterConditions();

            filterConditions.SPLowerRange  = Convert.ToInt32(ddlSPLowerRange.SelectedValue);
            filterConditions.SPHigherRange = Convert.ToInt32(ddlSPHigherRange.SelectedValue);

            if (ddlSPExpiry.SelectedValue.Equals("NONE"))
            {
                filterConditions.SPExpiry = 0;
            }
            else
            {
                filterConditions.SPExpiry = Convert.ToInt32(ddlSPExpiry.SelectedValue);
            }

            filterConditions.ContractType    = ddlContractType.SelectedValue;
            filterConditions.OcType          = rblOCType.SelectedValue;
            filterConditions.StrategyType    = enumStrategyType.BUTTERFLY.ToString();
            filterConditions.TimeGap         = timeAddGap;
            filterConditions.ExpiryDate      = ddlExpiryDates.SelectedValue;
            filterConditions.PercentageRange = 0;
            filterConditions.SPDifference    = 100;

            DataSet dataSetResult = Butterfly.GetButterflySpreadStrategies(filterConditions);

            PopulateDataSet(dataSetResult);

            PopulateFilterFields(filterConditions);

            //DataSet filteredDataSet = new DataSet();
            //foreach (DataTable dataTable in dataSetResult.Tables)
            //{
            //    //List<string> sp = dataTable.AsEnumerable().Select(x => x["Strike Price"].ToString()).ToList();

            //    //Find Lowest and Highest value in the given table column
            //    int iLowestSP = int.MaxValue;
            //    int iHighestSP = int.MinValue;
            //    int iMiddleSP = 0;
            //    foreach (DataRow dr in dataTable.Rows)
            //    {
            //        int currentSP = Convert.ToInt32(dr.Field<string>("StrikePrice"));
            //        iLowestSP = Math.Min(iLowestSP, currentSP);
            //        iMiddleSP = Math.Max(iLowestSP, currentSP);
            //        iMiddleSP = Math.Min(iHighestSP, currentSP);
            //        iHighestSP = Math.Max(iHighestSP, currentSP);
            //    }

            //    if (filterConditions.SPLowerRange == iLowestSP &&
            //        filterConditions.SPHigherRange == iHighestSP &&
            //        filterConditions.SPExpiry == iMiddleSP)
            //    {
            //        filteredDataSet.Tables.Add(dataTable.Copy());
            //    }
            //}
            ////dataSetResult = Butterfly.GetButterflySpreadStrategies(filterConditions);
            //PopulateDataSet(filteredDataSet);
        }
Exemplo n.º 6
0
        private void PopulateFilterFields(FilterConditions filterConditions)
        {
            lblLastFetchedTime.Text = MySession.Current.RecordsObject.timestamp;
            lblLastPrice.Text       = MySession.Current.RecordsObject.underlyingValue.ToString();

            PopulateSPLowerRange(filterConditions);
            PopulateSPHigherRange(filterConditions);
            //PopulateSPExpiry(filterConditions);
        }
Exemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            lblStart.Text = DateTime.Now.ToString();

            if (!IsPostBack)
            {
                FillExpiryDates(ddlExpiryDates);

                FilterConditions filterConditions = new FilterConditions();
                filterConditions.ContractType    = ddlContractType.SelectedValue;
                filterConditions.OcType          = rblOCType.SelectedValue;
                filterConditions.StrategyType    = enumStrategyType.IRON_CONDOR.ToString();
                filterConditions.TimeGap         = timeAddGap;
                filterConditions.ExpiryDate      = ddlExpiryDates.SelectedValue;
                filterConditions.PercentageRange = iPercentageRage;
                filterConditions.SPDifference    = 100;

                DataSet dataSetResult = IronCondorClass.GetIronCondors(filterConditions);
                PopulateDataSet(dataSetResult);

                PopulateFilterFields(filterConditions);
                Page.LoadComplete += new EventHandler(Page_LoadComplete);
            }
        }
Exemplo n.º 8
0
        private void PopulateSPExpiry(FilterConditions filterConditions)
        {
            int iUpperStrikePriceRange = OCHelper.RoundTo100(MySession.Current.RecordsObject.underlyingValue + (OCHelper.DefaultSP(rblOCType.SelectedValue) * iPercentageRage / 100));
            int iLowerStrikePriceRange = OCHelper.RoundTo100(MySession.Current.RecordsObject.underlyingValue - (OCHelper.DefaultSP(rblOCType.SelectedValue) * iPercentageRage / 100));

            //List<int> strikePrices = MySession.Current.RecordsObject.strikePrices;
            ddlSPExpiry.Items.Clear();

            ddlSPExpiry.Items.Add("NONE");

            foreach (var item in MySession.Current.RecordsObject.strikePrices)
            {
                if (item < iUpperStrikePriceRange && item > iLowerStrikePriceRange && item % filterConditions.SPDifference == 0 &&
                    item < filterConditions.SPHigherRange && item > filterConditions.SPLowerRange)
                {
                    ddlSPExpiry.Items.Add(item.ToString());
                }
            }

            if (filterConditions.SPExpiry != 0)
            {
                Utility.SelectDataInCombo(ddlSPExpiry, filterConditions.SPExpiry.ToString());
            }
        }
Exemplo n.º 9
0
        public static DataTable AddRecordsToDataTable(FilterConditions filterConditions)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Stock");
            dt.Columns.Add("Identifier");
            dt.Columns.Add("TradingSymbol");
            dt.Columns.Add("Contract");
            dt.Columns.Add("TransactionType");
            dt.Columns.Add("StrikePrice");
            dt.Columns.Add("LotSize");
            dt.Columns.Add("Premium");
            dt.Columns.Add("ExpiryDate");

            Records recordsObject = GetOC(filterConditions.OcType);

            int iUpperStrikePriceRange = 0;
            int iLowerStrikePriceRange = 0;

            if (filterConditions.PercentageRange > 0)
            {
                iUpperStrikePriceRange = RoundTo100(recordsObject.underlyingValue + (DefaultSP(filterConditions.OcType) * filterConditions.PercentageRange / 100));
                iLowerStrikePriceRange = RoundTo100(recordsObject.underlyingValue - (DefaultSP(filterConditions.OcType) * filterConditions.PercentageRange / 100));
            }
            else
            {
                iUpperStrikePriceRange = filterConditions.SPHigherRange;
                iLowerStrikePriceRange = filterConditions.SPLowerRange;
            }

            //List<int> strikePrices = MySession.Current.RecordsObject.strikePrices;
            List <int> filteredStrikePrices = new List <int>();

            foreach (var item in MySession.Current.RecordsObject.strikePrices)
            {
                if (item <= iUpperStrikePriceRange && item >= iLowerStrikePriceRange)
                {
                    filteredStrikePrices.Add(item);
                    dt.Columns.Add(item.ToString());
                }
            }

            DataRow datarow;

            foreach (var row in recordsObject.data)
            {
                string formattedDateForTradingSymbol = TradingSymbol_DateFormatter(row.expiryDate);

                if (row.CE != null &&
                    (row.CE.strikePrice <= iUpperStrikePriceRange &&
                     row.CE.strikePrice >= iLowerStrikePriceRange) &&
                    (row.CE.strikePrice % 100 == 0) &&
                    row.CE.lastPrice > 0 &&
                    row.expiryDate.Equals(filterConditions.ExpiryDate) &&
                    (filterConditions.ContractType.Equals(enumContractType.CE.ToString()) ||
                     filterConditions.ContractType.Equals("ALL")))
                {
                    //Add CE Buy row
                    datarow                    = dt.NewRow();
                    datarow["Stock"]           = row.CE.underlying;
                    datarow["Identifier"]      = row.CE.identifier;
                    datarow["Contract"]        = enumContractType.CE.ToString();
                    datarow["TransactionType"] = enumTransactionType.BUY.ToString();
                    datarow["StrikePrice"]     = row.CE.strikePrice.ToString();
                    datarow["LotSize"]         = GetLotSize(filterConditions.OcType);
                    datarow["Premium"]         = row.CE.lastPrice.ToString();
                    datarow["ExpiryDate"]      = row.CE.expiryDate;
                    datarow["TradingSymbol"]   = string.Concat(row.CE.underlying, formattedDateForTradingSymbol, row.CE.strikePrice.ToString(), enumContractType.CE.ToString());

                    foreach (var item in filteredStrikePrices)
                    {
                        datarow[dt.Columns[item.ToString()].ColumnName] = FO.CallBuy(row.CE.strikePrice, row.CE.lastPrice, Convert.ToDouble(item));
                    }
                    dt.Rows.Add(datarow);

                    //Add CE Sell row
                    datarow                    = dt.NewRow();
                    datarow["Stock"]           = row.CE.underlying;
                    datarow["Identifier"]      = row.CE.identifier;
                    datarow["Contract"]        = enumContractType.CE.ToString();
                    datarow["TransactionType"] = enumTransactionType.SELL.ToString();
                    datarow["StrikePrice"]     = row.CE.strikePrice.ToString();
                    datarow["LotSize"]         = GetLotSize(filterConditions.OcType);
                    datarow["Premium"]         = row.CE.lastPrice.ToString();
                    datarow["ExpiryDate"]      = row.CE.expiryDate;
                    datarow["TradingSymbol"]   = string.Concat(row.CE.underlying, formattedDateForTradingSymbol, row.CE.strikePrice.ToString(), enumContractType.CE.ToString());

                    foreach (var item in filteredStrikePrices)
                    {
                        datarow[dt.Columns[item.ToString()].ColumnName] = FO.CallSell(row.CE.strikePrice, row.CE.lastPrice, Convert.ToDouble(item));
                    }
                    dt.Rows.Add(datarow);
                }

                if (row.PE != null &&
                    (row.PE.strikePrice <= iUpperStrikePriceRange && row.PE.strikePrice >= iLowerStrikePriceRange) &&
                    (row.PE.strikePrice % 100 == 0) &&
                    row.PE.lastPrice > 0 &&
                    row.expiryDate.Equals(filterConditions.ExpiryDate) &&
                    (filterConditions.ContractType.Equals(enumContractType.PE.ToString()) ||
                     filterConditions.ContractType.Equals("ALL")))
                {
                    //Add PE Buy row
                    datarow                    = dt.NewRow();
                    datarow["Stock"]           = row.PE.underlying;
                    datarow["Identifier"]      = row.PE.identifier;
                    datarow["Contract"]        = enumContractType.PE.ToString();
                    datarow["TransactionType"] = enumTransactionType.BUY.ToString();
                    datarow["StrikePrice"]     = row.PE.strikePrice.ToString();
                    datarow["LotSize"]         = GetLotSize(filterConditions.OcType);
                    datarow["Premium"]         = row.PE.lastPrice.ToString();
                    datarow["ExpiryDate"]      = row.PE.expiryDate;
                    datarow["TradingSymbol"]   = string.Concat(row.PE.underlying, formattedDateForTradingSymbol, row.PE.strikePrice.ToString(), enumContractType.PE.ToString());

                    foreach (var item in filteredStrikePrices)
                    {
                        datarow[dt.Columns[item.ToString()].ColumnName] = FO.PutBuy(row.PE.strikePrice, row.PE.lastPrice, Convert.ToDouble(item));
                    }
                    dt.Rows.Add(datarow);

                    //Add PE Sell row
                    datarow                    = dt.NewRow();
                    datarow["Stock"]           = row.PE.underlying;
                    datarow["Identifier"]      = row.PE.identifier;
                    datarow["Contract"]        = enumContractType.PE.ToString();
                    datarow["TransactionType"] = enumTransactionType.SELL.ToString();
                    datarow["StrikePrice"]     = row.PE.strikePrice.ToString();
                    datarow["LotSize"]         = GetLotSize(filterConditions.OcType);
                    datarow["Premium"]         = row.PE.lastPrice.ToString();
                    datarow["ExpiryDate"]      = row.PE.expiryDate;
                    datarow["TradingSymbol"]   = string.Concat(row.PE.underlying, formattedDateForTradingSymbol, row.PE.strikePrice.ToString(), enumContractType.PE.ToString());

                    foreach (var item in filteredStrikePrices)
                    {
                        datarow[dt.Columns[item.ToString()].ColumnName] = FO.PutSell(row.PE.strikePrice, row.PE.lastPrice, Convert.ToDouble(item));
                    }
                    dt.Rows.Add(datarow);
                }
            }
            return(dt);
        }