33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using YLErp.DBModels.Helpers;
|
|
using YLErp.Modules.VolatilityModule;
|
|
|
|
namespace YLErp.Modules.PricingModule
|
|
{
|
|
/// <summary>
|
|
/// 反算波动率和执行价服务
|
|
/// </summary>
|
|
public class ReverseCalcService
|
|
{
|
|
/// <summary>
|
|
/// 根据平仓单价计算隐含波动率
|
|
/// </summary>
|
|
public static double? GetImpliedUnWindVol(trade td, DateTime unWindDate, double unWindPrice, double underlyingPrice, bool isEod)
|
|
{
|
|
try
|
|
{
|
|
var trade = td.Clone();
|
|
trade.TradeSinglePrice = unWindPrice;
|
|
trade.PremiumRate = TradeHelper.GetPremiumRateByTradeSinglePrice(trade.TradeSinglePrice, trade.SpotPrice);
|
|
trade.BuySell = "买入";
|
|
trade.VolType = trade.BuySell == "卖出" ? "报价Bid" : "报价Ask";
|
|
return VolatilityHelper.GetImpliedVol(unWindDate, trade, trade.TTMDays, underlyingPrice, isEod);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFactory.GetLogger("计算隐含波动率").Error("根据平仓单价计算隐含波动率出错", ex);
|
|
throw new ServiceException("计算隐含波动率出错,平仓单价设置偏低或偏高,内部错误信息:" + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|