private double getStockVolatility(List <StockTransaction> stockData)
        {
            double        vol   = 0;
            List <double> close = new List <double>();

            for (int i = 0; i < stockData.Count; i++)
            {
                close.Add(stockData[i].Close * stockData[i].AdjFactor);
            }
            vol = HistoricalVolatilityExtension.getHistoricalVolatilityByClosePrice(close);
            return(vol);
        }
        private double getOptionDelta(DateTime date, string BondCode, string stockCode)
        {
            double delta          = 0.5;
            var    bondInfo       = getBondDailyInfo(date, BondCode);
            int    days           = DateTimeExtension.DateUtils.GetSpanOfTradeDays(date, bondInfo.conversionEndDate);
            double duration       = (double)days / 252.0;
            var    stockList      = getPreviousStockCloseList(date, stockCode, days);
            var    stockLastClose = stockList[stockList.Count() - 1];
            double volatility     = HistoricalVolatilityExtension.getHistoricalVolatilityByClosePrice(stockList);

            double strike = bondInfo.conversionPrice;

            delta = ImpliedVolatilityExtension.ComputeOptionDelta(strike, duration, 0.04, 0, "认购", volatility, stockLastClose);
            return(delta);
        }
        private double getHisVol(DateTime today, int duration)
        {
            int           index        = 0;
            List <double> priceNowList = new List <double>();

            for (int i = 0; i < priceList.Count(); i++)
            {
                if (priceList[i].DateTime == today)
                {
                    index = i;
                    break;
                }
            }
            for (int i = index - duration - 1; i < index; i++)
            {
                priceNowList.Add(priceList[i].Close);
            }
            double vol = HistoricalVolatilityExtension.getHistoricalVolatilityByClosePrice(priceNowList);

            return(vol);
        }
Example #4
0
 private double getHistoricalVol(List <double> data)
 {
     return(HistoricalVolatilityExtension.getHistoricalVolatilityByClosePrice(data));
 }