833 lines
45 KiB
C#
833 lines
45 KiB
C#
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.IO;
|
|
//using System.Linq;
|
|
//using System.Linq.Expressions;
|
|
//using YLErp.BLL;
|
|
//using YLErp.BLL.Eod;
|
|
//using YLErp.DBModels;
|
|
//using YLErp.Helpers;
|
|
//using YLErp.Model;
|
|
//using YLErp.Modules.CalculationModule;
|
|
//using YLErp.Modules.DataProviderModule;
|
|
//using YLErp.Modules.EodModule;
|
|
|
|
//namespace YLErp.Modules.RiskExposure
|
|
//{
|
|
// /// <summary>
|
|
// /// 市场风险结算报告服务
|
|
// /// </summary>
|
|
// /// <typeparam name="T"></typeparam>
|
|
// public class RiskExposureReportServiceV2<T> : YLBaseService where T : EodTradePosition
|
|
// {
|
|
// public RiskExposureReportServiceV2(OptUserInfo userInfo) : base(userInfo)
|
|
// {
|
|
|
|
// }
|
|
|
|
// public RiskExposureReportModel SearchRiskExposureReportsV2<T1>(RiskRequestModel reqModel) where T1 : EodTradeRisk
|
|
// {
|
|
// RiskExposureReportModel result = null;
|
|
|
|
// reqModel = CheckModel(reqModel);
|
|
// var startDate = EodOperationBase.GetLastSettlementDate(reqModel.ValueDateStart ?? valuedateBLL.SystemDate.AccruedTotalPnlStartDate ?? DateTime.Today);
|
|
// var preDate = EodOperationBase.GetLastSettlementDate(startDate.AddDays(-1));
|
|
// var dataProvider = new EodRiskCalcDataProvider(reqModel.ValueDateEnd, startDate, reqModel.EodSettlePriceMode);
|
|
// var predicate = BuildPredicateOfEodTradePosition(preDate, reqModel, dataProvider);
|
|
// var useFirstEod = reqModel.ValueDateStart.HasValue ? PredicateBuilder.True<T>() : PredicateBuilder.False<T>();
|
|
|
|
// // 索引数据
|
|
// var sourceQuery = DbContext.Set<T>().Where(predicate)
|
|
// .GroupBy(O => new { O.TradeId, O.HedgeUniqueCode })
|
|
// .Select(O => new { O.Key.TradeId, O.Key.HedgeUniqueCode, maxDate = O.Max(B => B.ValueDate) });
|
|
|
|
// var query = from source in sourceQuery
|
|
// join lastEod in DbContext.Set<T>() on new { ValueDate = source.maxDate, TradeId = source.TradeId + source.HedgeUniqueCode }
|
|
// equals new { lastEod.ValueDate, TradeId = lastEod.TradeId + lastEod.HedgeUniqueCode }
|
|
// join tempEod in DbContext.Set<T>().Where(useFirstEod) on new { ValueDate = preDate, TradeId = source.TradeId + source.HedgeUniqueCode }
|
|
// equals new { tempEod.ValueDate, TradeId = tempEod.TradeId + tempEod.HedgeUniqueCode } into tempEod
|
|
// from firstEod in tempEod.DefaultIfEmpty()
|
|
// join tempT in DbContext.trade on source.TradeId equals tempT.id into tempT
|
|
// from trade in tempT.DefaultIfEmpty()
|
|
// join tempRisk in DbContext.Set<T1>() on new { ValueDate = reqModel.ValueDateEnd, TradeId = source.TradeId + source.HedgeUniqueCode }
|
|
// equals new { tempRisk.ValueDate, TradeId = tempRisk.TradeId + tempRisk.HedgeUniqueCode } into tempRisk
|
|
// from risk in tempRisk.DefaultIfEmpty()
|
|
// join et in DbContext.eod_trade on new { ValueDate = source.maxDate, TradeId = source.TradeId } equals new { et.ValueDate, et.TradeId } into tempEt
|
|
// from et in tempEt.DefaultIfEmpty()
|
|
// select new pnlListEndModel
|
|
// {
|
|
// eodTrade = new xodTradeBase { TradeJson = et.TradeJson },
|
|
|
|
// ValueDate = lastEod.ValueDate,
|
|
// TradeId = lastEod.TradeId,
|
|
// Eid = lastEod.id,
|
|
// TradeNumber = trade != null ? trade.TradeNumber : null,
|
|
// UnderlyingCode = lastEod.UnderlyingCode,
|
|
// OptionCode = lastEod.ExchangeOptionCode,
|
|
// UnderlyingId = lastEod.UnderlyingId,
|
|
// BookId = lastEod.BookId,
|
|
// TradeType = trade == null ? lastEod.TradeType : trade.TradeType,
|
|
// Amount = lastEod.Amount,
|
|
// AccruedTotalPnL = lastEod.TotalPnL - (firstEod == null || lastEod.ValueDate == firstEod.ValueDate || (trade != null && ConsTrade.OptionTradeTypes.Contains(trade.TradeType) && trade.TradeDate == firstEod.ValueDate) ? 0 : firstEod.TotalPnL),
|
|
// Commission = lastEod.Commission,//总计手续费
|
|
// DailyPnl = lastEod.DailyPnL,
|
|
// Delta = risk.Delta,
|
|
// DeltaCash = risk.DeltaCash,
|
|
// Gamma = risk.Gamma,
|
|
// GammaCash = risk.GammaCash,
|
|
// Vega = risk.Vega,
|
|
// Rho = risk.Rho * 100,
|
|
// Theta = risk.Theta,
|
|
// TraderId = trade == null ? 0 : trade.TraderId,
|
|
// SpotPrice = trade == null ? 0 : trade.SpotPrice,
|
|
// };
|
|
|
|
// if (reqModel.TradeTypes.Any())
|
|
// {
|
|
// query = query.Where(O => reqModel.TradeTypes.Contains(O.TradeType));
|
|
// }
|
|
// var eodPnlListEnd = query.ToList();
|
|
// eodPnlListEnd.ForEach(O =>
|
|
// {
|
|
// if (O.ValueDate != reqModel.ValueDateEnd)
|
|
// {
|
|
// O.Amount = 0;
|
|
// O.DailyPnl = O.Delta = O.Gamma = O.Vega = O.Rho = O.Theta = 0;
|
|
// O.DeltaCash = 0;
|
|
// O.GammaCash = 0;
|
|
// }
|
|
// O.StockEqvNotional = O.eodTrade?.trade == null ? 0 : O.eodTrade.trade.StockEqvNotional;
|
|
// });
|
|
// //合并处理
|
|
// var underlyingGroup = eodPnlListEnd.GroupBy(e => e.UnderlyingCode.ToUpperInvariant());
|
|
// var underlyingIdList = underlyingGroup.Select(g => g.Key).ToList();
|
|
// var underlyingRiskList = new List<UnderlyingRiskModel>();
|
|
|
|
// //历史累计盈亏
|
|
// var predicate2 = BuildPredicateOfEodPnlStatics(reqModel, dataProvider).Compile();
|
|
// var accruedTotalPnlService = new AccruedTotalPnlService<T>(this);
|
|
// var exchangeFinishedPnlList = accruedTotalPnlService.GetFinishedTradePnls(startDate, reqModel.ValueDateEnd.AddDays(-1), true)
|
|
// .Where(predicate2).ToList();
|
|
|
|
// var preValueDate = EodOperationBase.GetLastSettlementDate(reqModel.ValueDateEnd, true);
|
|
|
|
// //前一日的所有合约的累计手续费
|
|
// var preValueDateCommissionForHedge = accruedTotalPnlService.GetCommissionForHedge(preValueDate).Where(predicate2)
|
|
// .GroupBy(n => n.AssetType + "^" + n.UnderlyingCode.ToUpperInvariant())
|
|
// .ToDictionary(n => n.Key, m => m.Sum(x => x.TotalCommission), StringComparer.OrdinalIgnoreCase);
|
|
|
|
// //获取场内交易数据
|
|
// var exchangeOptionRisks = CalculateExchangeListOptionRisks(reqModel.ValueDateEnd, reqModel)
|
|
// .GroupBy(n => n.UnderlyingCode.ToUpperInvariant()).Select(n => new
|
|
// {
|
|
// Code = n.Key,
|
|
// Delta = n.Sum(m => m.Delta),
|
|
// Gamma = n.Sum(m => m.Gamma),
|
|
// Theta = n.Sum(m => m.Theta),
|
|
// Vega = n.Sum(m => m.Vega),
|
|
// Rho = n.Sum(m => m.Rho),
|
|
// GammaCash = n.Sum(m => m.GammaCash),
|
|
// DeltaCash = n.Sum(m => m.DeltaCash),
|
|
// }).ToDictionary(n => n.Code, StringComparer.OrdinalIgnoreCase);
|
|
|
|
// #region 1.对于最后一日有持仓数据的合约
|
|
// foreach (var groupItem in underlyingGroup)
|
|
// {
|
|
// dataProvider.TryGetEodPrice(groupItem.Key, out var price);
|
|
// var underlyingRisk = new UnderlyingRiskModel();
|
|
// var underlying = dataProvider.GetUnderlying(groupItem.Key);
|
|
// if (underlying == null)
|
|
// {
|
|
// throw new ServiceException("标的数据不存在:" + groupItem.Key);
|
|
// }
|
|
// var variety = DbContext.variety.Find(underlying.UnderlyingTypeId);
|
|
// var variety_limit = variety == null ? null : DbContext.variety_limit.FirstOrDefault(o => o.VarietyCode == variety.VarietyCode);
|
|
// underlyingRisk.UnderlyingId = underlying.id;
|
|
// underlyingRisk.UnderlyingCode = underlying.UnderlyingCode;
|
|
// underlyingRisk.UnderlyingPrice = price;
|
|
// underlyingRisk.UnderlyingInstrumentType = underlying.UnderlyingInstrumentType;
|
|
// underlyingRisk.VarietyCode = underlying.CommodityCode == "组合标的" ? "组合标的" : (variety == null ? underlying.UnderlyingType : variety.VarietyCode);
|
|
// underlyingRisk.VarietyOpenLimitIcon = variety == null || !(variety_limit?.IsPercent ?? false) ? "¥" : "%";
|
|
|
|
// if (underlying.CommodityCode == "组合标的")
|
|
// {
|
|
// underlyingRisk.SyntheticUnderlyingTipsInfo = synthetic_underlyingBLL.GetUnderlyingTipsInfo(underlying.UnderlyingCode);
|
|
// }
|
|
|
|
// var underlyingExchangeFinishedPnlList = exchangeFinishedPnlList.Where(p => string.Equals(p.UnderlyingCode, underlying.UnderlyingCode, StringComparison.OrdinalIgnoreCase)).ToList();
|
|
// var underlyingPreValueDateCommissionList = preValueDateCommissionForHedge.Where(p => string.Equals(p.UnderlyingCode, underlying.UnderlyingCode, StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
// var otcOptionsTradeType = ConsTrade.OptionTradeTypes.ToList();
|
|
// otcOptionsTradeType.Remove("收益互换");
|
|
|
|
// //场外期权 + 场内期权
|
|
// var otcRisk = underlyingRisk.OtcRisk = new EodRiskModel();
|
|
// var exOptionRisk = underlyingRisk.ExOptionRisk = new EodRiskModel();
|
|
|
|
// if (exchangeOptionRisks.TryGetValue(groupItem.Key, out var a))
|
|
// {
|
|
// exOptionRisk.Delta = a.Delta;
|
|
// exOptionRisk.Gamma = a.Gamma;
|
|
// exOptionRisk.Theta = a.Theta;
|
|
// exOptionRisk.Vega = a.Vega;
|
|
// exOptionRisk.Rho = a.Rho;
|
|
// exOptionRisk.DeltaCash = a.DeltaCash;
|
|
// exOptionRisk.GammaCash = a.GammaCash;
|
|
// }
|
|
|
|
// foreach (var item in groupItem)
|
|
// {
|
|
// if (otcOptionsTradeType.Contains(item.TradeType))
|
|
// {
|
|
// otcRisk.StockEqvNotional += item.StockEqvNotional;
|
|
// otcRisk.Pnl += item.AccruedTotalPnL ?? 0;
|
|
// otcRisk.Delta += item.Delta ?? 0;
|
|
// otcRisk.DeltaCash += item.DeltaCash ?? 0;
|
|
// otcRisk.GammaCash += item.GammaCash ?? 0;
|
|
// otcRisk.PositionStockEqvNotional += (item.Amount * item.SpotPrice) ?? 0;
|
|
// otcRisk.Gamma += item.Gamma ?? 0;
|
|
// otcRisk.Theta += item.Theta ?? 0;
|
|
// otcRisk.Vega += item.Vega ?? 0;
|
|
// otcRisk.Rho += item.Rho ?? 0;
|
|
// otcRisk.DailyPnl += item.DailyPnl ?? 0;
|
|
// }
|
|
// else if (item.TradeType == "场内期权")
|
|
// {
|
|
// exOptionRisk.Pnl += item.AccruedTotalPnL ?? 0;
|
|
// exOptionRisk.StockEqvNotional += NumberHelper.Normalize(item.StockEqvNotional);
|
|
// exOptionRisk.DailyCommission += item.Commission;// - preValueDateCommissionExOptSum;//当日累计 - 昨日累计 = 当日手续费
|
|
// exOptionRisk.DailyPnl += item.DailyPnl ?? 0;
|
|
// }
|
|
// }
|
|
|
|
// otcRisk.DeltaInLots = TradeLotsCalc.CalcDeltaInLots(Convert.ToDouble(otcRisk.Delta), variety, underlying);
|
|
// otcRisk.GammaInLots = TradeLotsCalc.CalcGammaInLots(Convert.ToDouble(otcRisk.Gamma), variety, underlying);
|
|
|
|
// //场内期权
|
|
// var exchangeRiskList = groupItem.Where(g => g.TradeType == "场内期权");
|
|
|
|
// var underlyingExchangeOptionFinishedCommission = underlyingExchangeFinishedPnlList.Where(x => x.AssetType == "场内期权").Sum(x => x.TotalCommission);
|
|
// var preValueDateCommissionExOptSum = underlyingPreValueDateCommissionList.Where(x => x.AssetType == "场内期权").Sum(x => x.TotalCommission);
|
|
// underlyingRisk.ExOptionRisk = new EodRiskModel
|
|
// {
|
|
// DailyCommission = exchangeRiskList.Sum(r => r.Commission) - preValueDateCommissionExOptSum,//当日累计 - 昨日累计 = 当日手续费
|
|
// DailyPnl = exchangeRiskList.Sum(r => r.DailyPnl ?? 0)
|
|
// };
|
|
// underlyingRisk.ExOptionRisk.DeltaInLots = TradeLotsCalc.CalcDeltaInLots(Convert.ToDouble(underlyingRisk.ExOptionRisk.Delta), variety, underlying);
|
|
// underlyingRisk.ExOptionRisk.GammaInLots = TradeLotsCalc.CalcGammaInLots(Convert.ToDouble(underlyingRisk.ExOptionRisk.Gamma), variety, underlying);
|
|
|
|
// //标的交易
|
|
// var hedgeRiskList = groupItem.Where(g => g.TradeType == "商品期货" || g.TradeType == "股票" || g.TradeType == "商品现货");
|
|
|
|
// var finishedHedgeList = underlyingExchangeFinishedPnlList.Where(x => x.AssetType == "商品期货" || x.AssetType == "股票");
|
|
// var preValueDateCommissionHedgeList = underlyingPreValueDateCommissionList.Where(x => x.AssetType == "商品期货" || x.AssetType == "股票");
|
|
|
|
// var underlyingHedgeFinishedCommission = finishedHedgeList.Sum(x => x.TotalCommission);
|
|
// var preValueDateCommissionHedgeSum = preValueDateCommissionHedgeList.Sum(x => x.TotalCommission);
|
|
|
|
// underlyingRisk.FuturesRisk = new EodRiskModel
|
|
// {
|
|
// Pnl = Convert.ToDecimal(hedgeRiskList.Sum(r => r.AccruedTotalPnL ?? 0)),
|
|
// Position = Convert.ToDecimal(hedgeRiskList.Sum(r => r.Amount)),
|
|
// StockEqvNotional = hedgeRiskList.Sum(r => r.Amount * price),
|
|
// Commission = hedgeRiskList.Sum(r => r.Commission) + underlyingHedgeFinishedCommission,
|
|
// DailyCommission = hedgeRiskList.Sum(r => r.Commission) - preValueDateCommissionHedgeSum,
|
|
// DailyPnl = hedgeRiskList.Sum(r => r.DailyPnl ?? 0)
|
|
// };
|
|
// underlyingRisk.FuturesRisk.PositionInLots = TradeLotsCalc.CalcDeltaInLots(Convert.ToDouble(underlyingRisk.FuturesRisk.Position), variety, underlying);
|
|
|
|
// underlyingRisk.FuturesRisk.PositionIncrementInLots = underlyingRisk.FuturesRisk.PositionInLots - 0;// tartPositionInLots;
|
|
// underlyingRisk.FuturesRisk.Delta = underlyingRisk.FuturesRisk.Position;
|
|
// underlyingRisk.FuturesRisk.DeltaCash = (decimal)underlyingRisk.UnderlyingPrice * underlyingRisk.FuturesRisk.Delta;
|
|
// underlyingRisk.FuturesRisk.GammaCash = (decimal)underlyingRisk.UnderlyingPrice * underlyingRisk.FuturesRisk.Gamma;
|
|
// underlyingRisk.FuturesRisk.DeltaInLots = underlyingRisk.FuturesRisk.PositionInLots;
|
|
|
|
// //远期统计
|
|
// var forwardRiskList = groupItem.Where(g => g.TradeType == "远期");
|
|
// underlyingRisk.ForwardRisk = new EodRiskModel
|
|
// {
|
|
// Pnl = Convert.ToDecimal(forwardRiskList.Sum(r => r.AccruedTotalPnL ?? 0)),
|
|
// Delta = forwardRiskList.Sum(r => r.Delta ?? 0),
|
|
// DeltaCash = (decimal)forwardRiskList.Sum(r => r.DeltaCash),
|
|
// GammaCash = (decimal)forwardRiskList.Sum(r => r.GammaCash),
|
|
// PositionStockEqvNotional = forwardRiskList.Sum(r => (r.Amount * r.SpotPrice) ?? 0),
|
|
// DailyPnl = forwardRiskList.Sum(r => r.DailyPnl ?? 0)
|
|
// };
|
|
// underlyingRisk.ForwardRisk.DeltaInLots = TradeLotsCalc.CalcDeltaInLots(Convert.ToDouble(underlyingRisk.ForwardRisk.Delta), variety, underlying);
|
|
|
|
// //收益互换统计
|
|
// var swapRiskList = groupItem.Where(g => g.TradeType == "收益互换");
|
|
// underlyingRisk.SwapRisk = new EodRiskModel
|
|
// {
|
|
// StockEqvNotional = swapRiskList.Sum(r => r.StockEqvNotional),
|
|
// //Pnl = Convert.ToDecimal(swapRiskList.Sum(r => r.AccruedTotalPnL ?? 0) + underlyingForwardFinishedPnl - otcForwardUnderlyingPnlStartSum),
|
|
// Pnl = Convert.ToDecimal(swapRiskList.Sum(r => r.AccruedTotalPnL ?? 0)),
|
|
// Delta = swapRiskList.Sum(r => r.Delta ?? 0),
|
|
// DeltaCash = (decimal)swapRiskList.Sum(r => r.DeltaCash),
|
|
// GammaCash = (decimal)swapRiskList.Sum(r => r.GammaCash),
|
|
// PositionStockEqvNotional = swapRiskList.Sum(r => (r.Amount * r.SpotPrice) ?? 0),
|
|
// DailyPnl = swapRiskList.Sum(r => r.DailyPnl ?? 0)
|
|
// };
|
|
// underlyingRisk.SwapRisk.DeltaInLots = TradeLotsCalc.CalcDeltaInLots(Convert.ToDouble(underlyingRisk.SwapRisk.Delta), variety, underlying);
|
|
|
|
// //汇总合计
|
|
// underlyingRisk.PortfolioRisk = new EodRiskModel
|
|
// {
|
|
// StockEqvNotional = underlyingRisk.OtcRisk.StockEqvNotional + underlyingRisk.ExOptionRisk.StockEqvNotional + underlyingRisk.FuturesRisk.StockEqvNotional,
|
|
// Pnl = underlyingRisk.OtcRisk.Pnl + underlyingRisk.ExOptionRisk.Pnl + underlyingRisk.FuturesRisk.Pnl + underlyingRisk.ForwardRisk.Pnl + underlyingRisk.SwapRisk.Pnl,
|
|
// Delta = underlyingRisk.OtcRisk.Delta + underlyingRisk.ExOptionRisk.Delta + underlyingRisk.FuturesRisk.Delta + underlyingRisk.ForwardRisk.Delta + underlyingRisk.SwapRisk.Delta,
|
|
// DeltaCash = underlyingRisk.OtcRisk.DeltaCash + underlyingRisk.ExOptionRisk.DeltaCash + underlyingRisk.FuturesRisk.DeltaCash + underlyingRisk.ForwardRisk.DeltaCash + underlyingRisk.SwapRisk.DeltaCash,
|
|
// GammaCash = underlyingRisk.OtcRisk.GammaCash + underlyingRisk.ExOptionRisk.GammaCash + underlyingRisk.FuturesRisk.GammaCash + underlyingRisk.ForwardRisk.GammaCash + underlyingRisk.SwapRisk.GammaCash,
|
|
// PositionStockEqvNotional = underlyingRisk.OtcRisk.PositionStockEqvNotional + underlyingRisk.ExOptionRisk.PositionStockEqvNotional + underlyingRisk.ForwardRisk.PositionStockEqvNotional + underlyingRisk.SwapRisk.PositionStockEqvNotional,
|
|
// DeltaInLots = underlyingRisk.OtcRisk.DeltaInLots + underlyingRisk.ExOptionRisk.DeltaInLots + underlyingRisk.FuturesRisk.DeltaInLots + underlyingRisk.ForwardRisk.DeltaInLots + underlyingRisk.SwapRisk.DeltaInLots,
|
|
// DailyPnl = underlyingRisk.OtcRisk.DailyPnl + underlyingRisk.ExOptionRisk.DailyPnl + underlyingRisk.FuturesRisk.DailyPnl + +underlyingRisk.ForwardRisk.DailyPnl + +underlyingRisk.SwapRisk.DailyPnl,
|
|
// Commission = underlyingRisk.ExOptionRisk.Commission + underlyingRisk.FuturesRisk.Commission,
|
|
// Gamma = underlyingRisk.OtcRisk.Gamma + underlyingRisk.ExOptionRisk.Gamma,
|
|
// Theta = underlyingRisk.OtcRisk.Theta + underlyingRisk.ExOptionRisk.Theta,
|
|
// Vega = underlyingRisk.OtcRisk.Vega + underlyingRisk.ExOptionRisk.Vega,
|
|
// Rho = underlyingRisk.OtcRisk.Rho + underlyingRisk.ExOptionRisk.Rho
|
|
// };
|
|
// underlyingRiskList.Add(underlyingRisk);
|
|
// }
|
|
// #endregion
|
|
|
|
// underlyingRiskList = underlyingRiskList.OrderBy(u => u, new UnderlyingRiskModelSortComparer()).ToList();
|
|
// var varietyRiskExposureReports = underlyingRiskList.GroupBy(u => new { u.VarietyCode, u.VarietyOpenLimit, u.VarietyOpenLimitIcon }).Select(g =>
|
|
// {
|
|
// var list = g.ToList();
|
|
// var portfolioSum = new EodRiskModel
|
|
// {
|
|
// StockEqvNotional = list.Sum(l => l.PortfolioRisk.StockEqvNotional),
|
|
// Pnl = list.Sum(l => l.PortfolioRisk.Pnl),
|
|
// Delta = list.Sum(l => l.PortfolioRisk.Delta),
|
|
// DeltaCash = list.Sum(l => l.PortfolioRisk.DeltaCash),
|
|
// GammaCash = list.Sum(l => l.PortfolioRisk.GammaCash),
|
|
// PositionStockEqvNotional = list.Sum(l => l.PortfolioRisk.PositionStockEqvNotional),
|
|
// DeltaInLots = list.Sum(l => l.PortfolioRisk.DeltaInLots),
|
|
// DailyPnl = list.Sum(l => l.PortfolioRisk.DailyPnl),
|
|
// Commission = list.Sum(l => l.PortfolioRisk.Commission),
|
|
// Gamma = list.Sum(l => l.PortfolioRisk.Gamma),
|
|
// Theta = list.Sum(l => l.PortfolioRisk.Theta),
|
|
// Vega = list.Sum(l => l.PortfolioRisk.Vega),
|
|
// Rho = list.Sum(l => l.PortfolioRisk.Rho)
|
|
// };
|
|
// var otcSum = new EodRiskModel
|
|
// {
|
|
// StockEqvNotional = list.Sum(l => l.OtcRisk.StockEqvNotional),
|
|
// Pnl = list.Sum(l => l.OtcRisk.Pnl),
|
|
// Delta = list.Sum(l => l.OtcRisk.Delta),
|
|
// DeltaInLots = list.Sum(l => l.OtcRisk.DeltaInLots),
|
|
// Gamma = list.Sum(l => l.OtcRisk.Gamma),
|
|
// GammaInLots = list.Sum(l => l.OtcRisk.GammaInLots),
|
|
// Theta = list.Sum(l => l.OtcRisk.Theta),
|
|
// Vega = list.Sum(l => l.OtcRisk.Vega),
|
|
// Rho = list.Sum(l => l.OtcRisk.Rho),
|
|
// DailyPnl = list.Sum(l => l.OtcRisk.DailyPnl),
|
|
// DeltaCash = list.Sum(l => l.OtcRisk.DeltaCash),
|
|
// };
|
|
// var exchangeListOptionSum = new EodRiskModel
|
|
// {
|
|
// Pnl = list.Sum(l => l.ExOptionRisk.Pnl),
|
|
// Delta = list.Sum(l => l.ExOptionRisk.Delta),
|
|
// DeltaInLots = list.Sum(l => l.ExOptionRisk.DeltaInLots),
|
|
// Gamma = list.Sum(l => l.ExOptionRisk.Gamma),
|
|
// GammaInLots = list.Sum(l => l.ExOptionRisk.GammaInLots),
|
|
// Theta = list.Sum(l => l.ExOptionRisk.Theta),
|
|
// Vega = list.Sum(l => l.ExOptionRisk.Vega),
|
|
// Rho = list.Sum(l => l.ExOptionRisk.Rho),
|
|
// Commission = list.Sum(l => l.ExOptionRisk.Commission),
|
|
// DailyPnl = list.Sum(l => l.ExOptionRisk.DailyPnl),
|
|
// DailyCommission = list.Sum(l => l.ExOptionRisk.DailyCommission),
|
|
// DeltaCash = list.Sum(l => l.ExOptionRisk.DeltaCash),
|
|
// StockEqvNotional = list.Sum(l => l.ExOptionRisk.StockEqvNotional)
|
|
// };
|
|
// var futuresSum = new EodRiskModel
|
|
// {
|
|
// Pnl = list.Sum(l => l.FuturesRisk.Pnl),
|
|
// Position = list.Sum(l => l.FuturesRisk.Position),
|
|
// PositionInLots = list.Sum(l => l.FuturesRisk.PositionInLots),
|
|
// PositionIncrementInLots = list.Sum(l => l.FuturesRisk.PositionIncrementInLots),
|
|
// Commission = list.Sum(l => l.FuturesRisk.Commission),
|
|
// DailyPnl = list.Sum(l => l.FuturesRisk.DailyPnl),
|
|
// DailyCommission = list.Sum(l => l.FuturesRisk.DailyCommission),
|
|
// StockEqvNotional = list.Sum(l => l.FuturesRisk.StockEqvNotional)
|
|
// };
|
|
// var forwardSum = new EodRiskModel
|
|
// {
|
|
// Pnl = list.Sum(l => l.ForwardRisk.Pnl),
|
|
// Delta = list.Sum(l => l.ForwardRisk.Delta),
|
|
// DeltaInLots = list.Sum(l => l.ForwardRisk.DeltaInLots),
|
|
// DailyPnl = list.Sum(l => l.ForwardRisk.DailyPnl)
|
|
// };
|
|
// var swapSum = new EodRiskModel
|
|
// {
|
|
// StockEqvNotional = list.Sum(l => l.SwapRisk.StockEqvNotional),
|
|
// Pnl = list.Sum(l => l.SwapRisk.Pnl),
|
|
// Delta = list.Sum(l => l.SwapRisk.Delta),
|
|
// DeltaInLots = list.Sum(l => l.SwapRisk.DeltaInLots),
|
|
// DailyPnl = list.Sum(l => l.SwapRisk.DailyPnl)
|
|
// };
|
|
// var varietyLimit = DbContext.variety_limit.FirstOrDefault(o => o.VarietyCode == g.Key.VarietyCode);
|
|
// return new VarietyRiskExposureModel
|
|
// {
|
|
// VarietyCode = g.Key.VarietyCode,
|
|
// VarietyOpenLimit = g.Key.VarietyOpenLimit,
|
|
// VarietyOpenLimitIcon = g.Key.VarietyOpenLimitIcon,
|
|
// VarietySum = new RiskExposureReportSumModel
|
|
// {
|
|
// PortfolioSum = portfolioSum,
|
|
// OtcSum = otcSum,
|
|
// ExOptionSum = exchangeListOptionSum,
|
|
// FuturesSum = futuresSum,
|
|
// ForwardSum = forwardSum,
|
|
// SwapSum = swapSum
|
|
// },
|
|
// UnderlyingRiskList = list,
|
|
// varietyLimit = varietyLimit ?? new VarietyLimit()
|
|
// };
|
|
// }).ToList();
|
|
|
|
// result = new RiskExposureReportModel
|
|
// {
|
|
// ReportModels = varietyRiskExposureReports,
|
|
// //总和盈亏比例计算元素取值逻辑
|
|
// TotalPnlRate = accruedTotalPnlService.CalcTotalPnlRate(startDate, reqModel.ValueDateEnd),
|
|
// Sum = new RiskExposureReportSumModel
|
|
// {
|
|
// PortfolioSum = varietyRiskExposureReports.Select(r => r.VarietySum.PortfolioSum).Aggregate(new EodRiskModel(), (p, n) => p + n),
|
|
// OtcSum = varietyRiskExposureReports.Select(r => r.VarietySum.OtcSum).Aggregate(new EodRiskModel(), (p, n) => p + n),
|
|
// ExOptionSum = varietyRiskExposureReports.Select(r => r.VarietySum.ExOptionSum).Aggregate(new EodRiskModel(), (p, n) => p + n),
|
|
// FuturesSum = varietyRiskExposureReports.Select(r => r.VarietySum.FuturesSum).Aggregate(new EodRiskModel(), (p, n) => p + n),
|
|
// ForwardSum = varietyRiskExposureReports.Select(r => r.VarietySum.ForwardSum).Aggregate(new EodRiskModel(), (p, n) => p + n),
|
|
// SwapSum = varietyRiskExposureReports.Select(r => r.VarietySum.SwapSum).Aggregate(new EodRiskModel(), (p, n) => p + n)
|
|
// }
|
|
// };
|
|
// return result;
|
|
// }
|
|
|
|
// //检查查询对象并规范化
|
|
// private RiskRequestModel CheckModel(RiskRequestModel reqModel)
|
|
// {
|
|
// if (reqModel == null)
|
|
// {
|
|
// throw new ServiceException("实体不能为空");
|
|
// }
|
|
|
|
// var endDateName = reqModel.ValueDateStart == null ? "结算日期" : "结束日期";
|
|
|
|
// if (reqModel.ValueDateEnd == null)
|
|
// {
|
|
// throw new ServiceException($"{endDateName}不能为空");
|
|
// }
|
|
// if (reqModel.ValueDateStart != null && reqModel.ValueDateStart > reqModel.ValueDateEnd)
|
|
// {
|
|
// throw new ServiceException("开始日期不能大于结束日期");
|
|
// }
|
|
// DateTime settleDate;
|
|
// if (reqModel.EodSettlePriceMode == "结算价")
|
|
// {
|
|
// settleDate = EodOperationBase.GetLastSettlementDate_Settle(false);
|
|
// }
|
|
// else
|
|
// {
|
|
// settleDate = EodOperationBase.GetLastSettlementDate(valuedateBLL.ValueDate);
|
|
// }
|
|
// if (reqModel.ValueDateEnd > settleDate)
|
|
// {
|
|
// throw new ServiceException($"{endDateName}不能大于上一次收盘日期{settleDate:yyyy-MM-dd}");
|
|
// }
|
|
|
|
// return reqModel.Normalize();
|
|
// }
|
|
|
|
// //构建EodTradePositionBase对象查询预测
|
|
// private Expression<Func<T, bool>> BuildPredicateOfEodTradePosition(DateTime preDate, RiskRequestModel reqModel, EodRiskCalcDataProvider dataProvider)
|
|
// {
|
|
// var predicate = PredicateBuilder.Create<T>(
|
|
// t => t.ValueDate > preDate && t.ValueDate <= reqModel.ValueDateEnd && t.TradeType != "结构化交易" && t.TradeType != "现金流交易");
|
|
|
|
// if (reqModel.ClientIds.Any())
|
|
// {
|
|
// predicate = predicate.And(q => reqModel.ClientIds.Contains(q.ClientId));
|
|
// }
|
|
// if (reqModel.BookIds.Any())
|
|
// {
|
|
// predicate = predicate.And(q => reqModel.BookIds.Contains(q.BookId));
|
|
// }
|
|
// //if (reqModel.TradeTypes.Any())
|
|
// //{
|
|
// // predicate = predicate.And(q => reqModel.TradeTypes.Contains(q.TradeType));
|
|
// //}
|
|
// if (reqModel.VarietyIds.Any())
|
|
// {
|
|
// var underlyingIds = dataProvider.GetUnderlyingQuery()
|
|
// .Where(u => reqModel.VarietyIds.Contains(u.UnderlyingTypeId)).Select(u => u.id).ToList();
|
|
// if (reqModel.UnderlyingIds.Any())
|
|
// {
|
|
// //取并集
|
|
// reqModel.UnderlyingIds = reqModel.UnderlyingIds.Intersect(underlyingIds).ToArray();
|
|
// }
|
|
// else
|
|
// {
|
|
// reqModel.UnderlyingIds = underlyingIds;
|
|
// }
|
|
// if (!reqModel.UnderlyingIds.Any())
|
|
// {
|
|
// reqModel.UnderlyingIds = new int[] { 0 };
|
|
// }
|
|
// }
|
|
// if (reqModel.UnderlyingIds.Any())
|
|
// {
|
|
// predicate = predicate.And(q => reqModel.UnderlyingIds.Contains(q.UnderlyingId));
|
|
// }
|
|
// return predicate;
|
|
// }
|
|
|
|
// //构建EodPnlStaticsDto对象查询预测
|
|
// private Expression<Func<EodPnlStaticsDto, bool>> BuildPredicateOfEodPnlStatics(RiskRequestModel reqModel, EodRiskCalcDataProvider dataProvider)
|
|
// {
|
|
// var predicate = PredicateBuilder.True<EodPnlStaticsDto>();
|
|
|
|
// if (reqModel.BookIds.Any())
|
|
// {
|
|
// predicate = predicate.And(q => reqModel.BookIds.Contains(q.BookId));
|
|
// }
|
|
|
|
// if (reqModel.ClientIds.Any())
|
|
// {
|
|
// predicate = predicate.And(q => reqModel.ClientIds.Contains(q.ClientId));
|
|
// }
|
|
|
|
// if (reqModel.TradeTypes.Any())
|
|
// {
|
|
// predicate = predicate.And(q => reqModel.TradeTypes.Contains(q.AssetType));
|
|
// }
|
|
|
|
// IEnumerable<int> UnderlyingIds = null;
|
|
|
|
// //标的过滤
|
|
// if (reqModel.UnderlyingIds != null && reqModel.UnderlyingIds.Any())
|
|
// {
|
|
// UnderlyingIds = reqModel.UnderlyingIds;
|
|
// }
|
|
|
|
// //品种过滤
|
|
// if (reqModel.VarietyIds != null && reqModel.VarietyIds.Any())
|
|
// {
|
|
// var UnderlyingIds2 = dataProvider.GetUnderlyingQuery()
|
|
// .Where(n => reqModel.VarietyIds.Contains(n.UnderlyingTypeId))
|
|
// .Select(n => n.id).ToArray();
|
|
// //合并标的过滤(取并集)
|
|
// UnderlyingIds = UnderlyingIds == null ? UnderlyingIds2 : UnderlyingIds.Intersect(UnderlyingIds2);
|
|
// }
|
|
|
|
// if (UnderlyingIds != null)
|
|
// {
|
|
// var UnderlyingCodes = dataProvider.GetUnderlyingQuery()
|
|
// .Where(n => UnderlyingIds.Contains(n.id))
|
|
// .Select(n => n.UnderlyingCode).ToArray();
|
|
// if (!UnderlyingCodes.Any())
|
|
// {
|
|
// UnderlyingCodes = new string[] { string.Empty };
|
|
// }
|
|
// predicate = predicate.And(q => UnderlyingCodes.Contains(q.UnderlyingCode));
|
|
// }
|
|
|
|
// if (reqModel.TraderIds.Any())
|
|
// {
|
|
// predicate = predicate.And(q => reqModel.TraderIds.Contains(q.TraderId));
|
|
// }
|
|
|
|
// return predicate;
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// 导出报告
|
|
// /// </summary>
|
|
// public byte[] ExportReport<T1>(RiskRequestModel reqModel) where T1 : EodTradeRisk
|
|
// {
|
|
// var report = SearchRiskExposureReportsV2<T1>(reqModel);
|
|
// report.ReportStart = (reqModel.ValueDateStart ?? reqModel.ValueDateEnd).ToString("yyyy-M-d");
|
|
// report.ReportEnd = reqModel.ValueDateEnd.ToString("yyyy-M-d");
|
|
|
|
// if (report.ReportModels == null || !report.ReportModels.Any())
|
|
// {
|
|
// throw new Exception("无导出数据!");//(请确保区间收盘是连续的,特别是最后日)
|
|
// }
|
|
|
|
// //获取盯市报告模板信息
|
|
// var settleDocName = "市场风险模板一.xlsx";//导出单日
|
|
// if (reqModel.ValueDateStart != null)
|
|
// {
|
|
// settleDocName = "市场风险模板二.xlsx";//导出区间
|
|
// }
|
|
// var templateFileName = OtcAppContext.MapPath("~/App_Docs/导出模板/" + settleDocName);
|
|
|
|
// var PortfolioList = new List<EodRiskModel>();
|
|
// var OtcList = new List<EodRiskModel>();
|
|
// var ExOptionList = new List<EodRiskModel>();
|
|
// var FuturesList = new List<EodRiskModel>();
|
|
// var ForwardList = new List<EodRiskModel>();
|
|
// var SwapList = new List<EodRiskModel>();
|
|
// var emptyRiskModel = new EodRiskModel { VarietyCode = "####" };
|
|
|
|
// foreach (var item in report.ReportModels)
|
|
// {
|
|
// item.VarietySum.PortfolioSum.VarietyCode = item.VarietyCode;
|
|
// PortfolioList.Add(item.VarietySum.PortfolioSum);
|
|
// PortfolioList.AddRange(item.UnderlyingRiskList.Select(m =>
|
|
// {
|
|
// m.PortfolioRisk.UnderlyingCode = m.UnderlyingCode;
|
|
// m.PortfolioRisk.UnderlyingPrice = m.UnderlyingPrice?.ToString("F2");
|
|
// return m.PortfolioRisk;
|
|
// }));
|
|
// PortfolioList.Add(emptyRiskModel);
|
|
|
|
// item.VarietySum.OtcSum.VarietyCode = item.VarietyCode;
|
|
// OtcList.Add(item.VarietySum.OtcSum);
|
|
// OtcList.AddRange(item.UnderlyingRiskList.Select(m =>
|
|
// {
|
|
// m.OtcRisk.UnderlyingCode = m.UnderlyingCode;
|
|
// m.OtcRisk.UnderlyingPrice = m.UnderlyingPrice?.ToString("F2");
|
|
// return m.OtcRisk;
|
|
// }));
|
|
// OtcList.Add(emptyRiskModel);
|
|
|
|
// item.VarietySum.ExOptionSum.VarietyCode = item.VarietyCode;
|
|
// ExOptionList.Add(item.VarietySum.ExOptionSum);
|
|
// ExOptionList.AddRange(item.UnderlyingRiskList.Select(m =>
|
|
// {
|
|
// m.ExOptionRisk.UnderlyingCode = m.UnderlyingCode;
|
|
// m.ExOptionRisk.UnderlyingPrice = m.UnderlyingPrice?.ToString("F2");
|
|
// return m.ExOptionRisk;
|
|
// }));
|
|
// ExOptionList.Add(emptyRiskModel);
|
|
|
|
// item.VarietySum.FuturesSum.VarietyCode = item.VarietyCode;
|
|
// FuturesList.Add(item.VarietySum.FuturesSum);
|
|
// FuturesList.AddRange(item.UnderlyingRiskList.Select(m =>
|
|
// {
|
|
// m.FuturesRisk.UnderlyingCode = m.UnderlyingCode;
|
|
// m.FuturesRisk.UnderlyingPrice = m.UnderlyingPrice?.ToString("F2");
|
|
// return m.FuturesRisk;
|
|
// }));
|
|
// FuturesList.Add(emptyRiskModel);
|
|
|
|
// item.VarietySum.ForwardSum.VarietyCode = item.VarietyCode;
|
|
// ForwardList.Add(item.VarietySum.ForwardSum);
|
|
// ForwardList.AddRange(item.UnderlyingRiskList.Select(m =>
|
|
// {
|
|
// m.ForwardRisk.UnderlyingCode = m.UnderlyingCode;
|
|
// m.ForwardRisk.UnderlyingPrice = m.UnderlyingPrice?.ToString("F2");
|
|
// return m.ForwardRisk;
|
|
// }));
|
|
// ForwardList.Add(emptyRiskModel);
|
|
|
|
// item.VarietySum.SwapSum.VarietyCode = item.VarietyCode;
|
|
// SwapList.Add(item.VarietySum.SwapSum);
|
|
// SwapList.AddRange(item.UnderlyingRiskList.Select(m =>
|
|
// {
|
|
// m.SwapRisk.UnderlyingCode = m.UnderlyingCode;
|
|
// m.SwapRisk.UnderlyingPrice = m.UnderlyingPrice?.ToString("F2");
|
|
// return m.SwapRisk;
|
|
// }));
|
|
// SwapList.Add(emptyRiskModel);
|
|
// }
|
|
|
|
// var varb = new
|
|
// {
|
|
// PortfolioList,
|
|
// report.Sum.PortfolioSum,
|
|
|
|
// OtcList,
|
|
// report.Sum.OtcSum,
|
|
|
|
// ExOptionList,
|
|
// report.Sum.ExOptionSum,
|
|
|
|
// FuturesList,
|
|
// report.Sum.FuturesSum,
|
|
|
|
// ForwardList,
|
|
// report.Sum.ForwardSum,
|
|
|
|
// SwapList,
|
|
// report.Sum.SwapSum,
|
|
|
|
// report.ReportStart,
|
|
// report.ReportEnd
|
|
// };
|
|
|
|
// using (var generator = Office.ExcelModule.ExcelGenerator
|
|
// .UseTemplateGenerator(templateFileName).AddVariable(varb))
|
|
// {
|
|
// var wrap = generator.GetExcelWrapper();
|
|
|
|
// generator.Generate();
|
|
|
|
// for (var i = 1; i <= 6; i++)
|
|
// {
|
|
// wrap.SetSheet(i);
|
|
// var rowLoop = wrap.GetRowLoop();
|
|
// for (var j = 0; j < 1000; j++)
|
|
// {
|
|
// var value = rowLoop.MoveNext().GetValue(1);
|
|
|
|
// if (value == "####")
|
|
// {
|
|
// rowLoop.Current.ClearContents();
|
|
// }
|
|
// else if (value == "合计")
|
|
// {
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// using (var ms = new MemoryStream())
|
|
// {
|
|
// generator.SaveAs(ms);
|
|
// return ms.ToArray();
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// 获取取值日的场内期权风险指标
|
|
// /// </summary>
|
|
// private IEnumerable<EodPositionRisksDTO> CalculateExchangeListOptionRisks(DateTime settleDate, RiskRequestModel reqModel)
|
|
// {
|
|
// if (reqModel.ClientIds.Any(n => n > 0) || reqModel.TradeTypes.Any() && !reqModel.TradeTypes.Contains("场内期权"))
|
|
// {
|
|
// return Enumerable.Empty<EodPositionRisksDTO>();
|
|
// }
|
|
|
|
// var riskPredicate = PredicateBuilder.Create<EodTradeRisk>(t => t.ValueDate == settleDate && t.TradeId < 1);
|
|
// var posPredicate = PredicateBuilder.Create<EodTradePosition>(t => t.ValueDate == settleDate && t.TradeId < 1 && t.TradeType == "场内期权");
|
|
|
|
// if (reqModel.BookIds != null && reqModel.BookIds.Any(n => n > 0))
|
|
// {
|
|
// posPredicate = posPredicate.And(t => reqModel.BookIds.Contains(t.BookId));
|
|
// }
|
|
|
|
// var varietyIds = reqModel.VarietyIds != null && reqModel.VarietyIds.Any(n => n > 0) ? reqModel.VarietyIds : Enumerable.Empty<int>();
|
|
// var underlyingIds = reqModel.UnderlyingIds != null && reqModel.UnderlyingIds.Any(n => n > 0) ? reqModel.UnderlyingIds : Enumerable.Empty<int>();
|
|
|
|
// IQueryable<EodTradeRisk> riskQuery;
|
|
// IQueryable<EodTradePosition> posQuery;
|
|
|
|
// switch (reqModel.EodSettlePriceMode)
|
|
// {
|
|
// case "结算价":
|
|
// riskQuery = DbContext.eod_trade_risk_hedgevol_s.Where(riskPredicate);
|
|
// posQuery = DbContext.eod_trade_position_hedgevol_s.Where(posPredicate);
|
|
// break;
|
|
// default:
|
|
// riskQuery = DbContext.eod_trade_risk_hedgevol.Where(riskPredicate);
|
|
// posQuery = DbContext.eod_trade_position_hedgevol.Where(posPredicate);
|
|
// break;
|
|
// }
|
|
|
|
// var query = from risk in riskQuery
|
|
// join pos in posQuery on risk.HedgeUniqueCode equals pos.HedgeUniqueCode
|
|
// join un in DbContext.underlying_manager on pos.UnderlyingCode equals un.UnderlyingCode
|
|
// join ex in DbContext.exchange_list_option on pos.ExchangeOptionCode equals ex.ContractCode
|
|
// where (!underlyingIds.Any() || underlyingIds.Contains(un.id))
|
|
// && (!varietyIds.Any() || varietyIds.Contains(un.UnderlyingTypeId))
|
|
// select new EodPositionRisksDTO
|
|
// {
|
|
// id = -pos.id,
|
|
|
|
// PV = pos.Pv,
|
|
// RoundedPV = pos.RoundedPv,
|
|
// PositionPnl = pos.PositionPnL,
|
|
// RoundedPositionPnl = pos.RoundedPositionPnL,
|
|
|
|
// Vega = risk.Vega,
|
|
// Theta = risk.Theta,
|
|
// Rho = risk.Rho,
|
|
// Delta = risk.Delta,
|
|
// Gamma = risk.Gamma,
|
|
// Exposure = risk.CreditExposure,
|
|
// CurrentVolatility = risk.Vol,
|
|
|
|
// Notional = pos.Amount,
|
|
// OriginalNotional = pos.Amount,
|
|
// TradePrice = pos.Cost,
|
|
// TradeSinglePrice = pos.Amount > 0 ? pos.Cost / pos.Amount : 0,
|
|
// TradeType = pos.TradeType,
|
|
// UnderlyingCode = pos.UnderlyingCode,
|
|
|
|
// UnderlyingPrice = un.Price ?? 0,
|
|
// UnderlyingId = un.id,
|
|
// VarietyId = un.UnderlyingTypeId,
|
|
// UnderlyingAssetName = un.UnderlyingName,
|
|
|
|
// Margin = pos.Margin,
|
|
// RealizedPnl = pos.TotalPnL - (double)pos.PositionPnL,
|
|
// ExchangeOptionCode = pos.ExchangeOptionCode,
|
|
|
|
// Strike = ex.Strike,
|
|
// ExerciseDate = ex.MaturityDate,
|
|
// OptionType = ex.OptionType,
|
|
// TradeDate = ex.OpenDate
|
|
// };
|
|
|
|
// var datas = query.ToArray();
|
|
|
|
// foreach (var data in datas)
|
|
// {
|
|
// data.RiskFreeRate = valuedateBLL.RiskFreeRate / 100;
|
|
|
|
// var um = DataCacheProvider.GetUnderlyingDataSource().GetData(data.UnderlyingCode);
|
|
|
|
// if (um != null)
|
|
// {
|
|
// data.DeltaCash = (double)(data.Delta ?? 0) * data.UnderlyingPrice;
|
|
// data.GammaCash = (double)(data.Gamma ?? 0) * data.UnderlyingPrice;
|
|
// data.GammaLots = (double)(data.Gamma ?? 0) / um.ContractSize;
|
|
// data.DeltaLots = (double)(data.Delta ?? 0) / um.ContractSize;
|
|
// }
|
|
|
|
// data.Rho *= 100;
|
|
// data.TradeOriginalAmount = um != null ? data.OriginalNotional / um.CountRatio : data.OriginalNotional;
|
|
|
|
// data.StockEqvNotional = data.Strike * data.Notional;
|
|
// }
|
|
|
|
// return datas;
|
|
// }
|
|
// }
|
|
|
|
// internal class pnlListEndModel
|
|
// {
|
|
// public xodTradeBase eodTrade { get; set; }
|
|
|
|
// public DateTime ValueDate { get; set; }
|
|
// public int? TradeId { get; set; }
|
|
// public int Eid { get; set; }
|
|
// public string TradeNumber { get; set; }
|
|
// public string UnderlyingCode { get; set; }
|
|
// public string OptionCode { get; set; }
|
|
// public int UnderlyingId { get; set; }
|
|
// public int BookId { get; set; }
|
|
// public string TradeType { get; set; }
|
|
// public double Amount { get; set; }
|
|
// public double? AccruedTotalPnL { get; set; }
|
|
// public double Commission { get; set; }
|
|
// public double? DailyPnl { get; set; }
|
|
// public double? Delta { get; set; }
|
|
// public double? DeltaCash { get; set; }
|
|
// public double? Gamma { get; set; }
|
|
// public double? GammaCash { get; set; }
|
|
// public double? Vega { get; set; }
|
|
// public double? Rho { get; set; }
|
|
// public double? Theta { get; set; }
|
|
// public int? TraderId { get; set; }
|
|
// public double? SpotPrice { get; set; }
|
|
// public double StockEqvNotional { get; set; }
|
|
|
|
// public pnlListEndModel() { }
|
|
// }
|
|
//}
|