コード例 #1
0
        protected double CalculateExpiryValue(string contractType, string transactionType, double strikePrice,
                                              double premiumPaid, double expiryPrice)
        {
            double result = 0;

            if (contractType == enumContractType.PE.ToString() && transactionType == enumTransactionType.BUY.ToString())
            {
                result = FO.PutBuy(strikePrice, premiumPaid, expiryPrice);
            }
            if (contractType == enumContractType.PE.ToString() && transactionType == enumTransactionType.SELL.ToString())
            {
                result = FO.PutSell(strikePrice, premiumPaid, expiryPrice);
            }
            if (contractType == enumContractType.CE.ToString() && transactionType == enumTransactionType.BUY.ToString())
            {
                result = FO.CallBuy(strikePrice, premiumPaid, expiryPrice);
            }
            if (contractType == enumContractType.CE.ToString() && transactionType == enumTransactionType.SELL.ToString())
            {
                result = FO.CallSell(strikePrice, premiumPaid, expiryPrice);
            }
            if (contractType == enumContractType.EQ.ToString() && transactionType == enumTransactionType.BUY.ToString())
            {
                result = FO.EQBuy(strikePrice, expiryPrice);
            }
            if (contractType == enumContractType.FUT.ToString() && transactionType == enumTransactionType.BUY.ToString())
            {
                result = FO.FutBuy(strikePrice, expiryPrice);
            }
            if (contractType == enumContractType.FUT.ToString() && transactionType == enumTransactionType.SELL.ToString())
            {
                result = FO.FutSell(strikePrice, expiryPrice);
            }

            return(result);
        }
コード例 #2
0
        private DataTable AddRowstoStrategyTable(DataTable dt)
        {
            List <int> strikePrices = GetStrikePrices();
            DataRow    datarow;

            foreach (var row in MySession.Current.RecordsObject.data)
            {
                if (row.CE != null && (row.CE.strikePrice <= iUpperStrikePriceRange && row.CE.strikePrice >= iLowerStrikePriceRange))
                {
                    //Add CE Buy row
                    datarow                    = dt.NewRow();
                    datarow["Stock"]           = row.CE.underlying.ToString();
                    datarow["Contract"]        = enumContractType.CE.ToString();
                    datarow["TransactionType"] = enumTransactionType.BUY.ToString();
                    datarow["StrikePrice"]     = row.CE.strikePrice.ToString();
                    datarow["LotSize"]         = Convert.ToInt32(enumLotSize.BankNifty).ToString();
                    datarow["Premium"]         = row.CE.lastPrice.ToString();
                    datarow["ExpiryDate"]      = row.CE.expiryDate.ToString();

                    foreach (var item in strikePrices)
                    {
                        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.ToString();
                    datarow["Contract"]        = enumContractType.CE.ToString();
                    datarow["TransactionType"] = enumTransactionType.SELL.ToString();
                    datarow["StrikePrice"]     = row.CE.strikePrice.ToString();
                    datarow["LotSize"]         = Convert.ToInt32(enumLotSize.BankNifty).ToString();
                    datarow["Premium"]         = row.CE.lastPrice.ToString();
                    datarow["ExpiryDate"]      = row.CE.expiryDate.ToString();

                    foreach (var item in strikePrices)
                    {
                        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))
                {
                    //Add PE Buy row
                    datarow                    = dt.NewRow();
                    datarow["Stock"]           = row.PE.underlying.ToString();
                    datarow["Contract"]        = enumContractType.PE.ToString();
                    datarow["TransactionType"] = enumTransactionType.BUY.ToString();
                    datarow["StrikePrice"]     = row.PE.strikePrice.ToString();
                    datarow["LotSize"]         = Convert.ToInt32(enumLotSize.BankNifty).ToString();
                    datarow["Premium"]         = row.PE.lastPrice.ToString();
                    datarow["ExpiryDate"]      = row.PE.expiryDate.ToString();

                    foreach (var item in strikePrices)
                    {
                        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.ToString();
                    datarow["Contract"]        = enumContractType.PE.ToString();
                    datarow["TransactionType"] = enumTransactionType.SELL.ToString();
                    datarow["StrikePrice"]     = row.PE.strikePrice.ToString();
                    datarow["LotSize"]         = Convert.ToInt32(enumLotSize.BankNifty).ToString();
                    datarow["Premium"]         = row.PE.lastPrice.ToString();
                    datarow["ExpiryDate"]      = row.PE.expiryDate.ToString();


                    foreach (var item in strikePrices)
                    {
                        datarow[dt.Columns[item.ToString()].ColumnName] = FO.PutSell(row.PE.strikePrice, row.PE.lastPrice, Convert.ToDouble(item));
                    }
                    dt.Rows.Add(datarow);
                }
            }
            return(dt);
        }
コード例 #3
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);
        }