79 lines
2.3 KiB
C#
79 lines
2.3 KiB
C#
namespace YLErp.Modules.CalculationModule
|
|
{
|
|
/// <summary>
|
|
/// 自定义期权交易计算服务
|
|
/// </summary>
|
|
public class ForwardradeCalcService
|
|
{
|
|
/// <summary>
|
|
/// 计算PV/Risk(交易员角度)
|
|
/// </summary>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算PV/Risk(交易员角度)
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算远期价值(客户角度)
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
}
|