namespace YLErp.Modules.CalculationModule { /// /// 自定义期权交易计算服务 /// public class ForwardradeCalcService { /// /// 计算PV/Risk(交易员角度) /// public static TradeValueResult CalcValue(OtcTradeBase trade, double spotPrice) { if (trade is null) { throw new ArgumentNullException(nameof(trade)); } return CalcValue(trade.Strike ?? 0, spotPrice, trade.Notional, trade.CallPut, trade.BuySell); } /// /// 计算PV/Risk(交易员角度) /// public static TradeValueResult CalcValue(double strike, double spotPrice, double notional, string callput, string buysell) { var isCall = callput == "Call"; var pv = (spotPrice - strike) * notional; //买入看跌和卖出看涨取负值 var flag = (TradeCalcHelper.IsBuy(buysell) ? 1 : 2) | (isCall ? 1 : 2); TradeValueResult result; if (flag == 3) { result = new TradeValueResult { Pv = -pv, Delta = -notional, DeltaCash = -notional * spotPrice }; } else { result = new TradeValueResult { Pv = pv, Delta = notional, DeltaCash = notional * spotPrice }; } result.RoundedPv = result.Pv; return result; } /// /// 计算远期价值(客户角度) /// public static double CalcForwardValue(OtcTradeBase trade) { if (trade is null) { throw new ArgumentNullException(nameof(trade)); } if (trade.TradeType != "远期") { return 0; } var forwardValue = ((trade.SpotPrice ?? 0) - (trade.Strike ?? 0)) * trade.Notional; return trade.OptionType == "看涨" || trade.OptionType == "多头" ? forwardValue : -forwardValue; } } }