从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
using Qdp.Foundation.Implementations;
|
||||
using Qdp.Pricing.Base.Enums;
|
||||
using Qdp.Pricing.Base.Implementations;
|
||||
using Qdp.Pricing.Library.Equity.Engines.Analytical;
|
||||
using YLErp.BLL;
|
||||
using YLErp.Modules.VolatilityModule;
|
||||
|
||||
namespace YLErp.Modules.ExcelAddinModule
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ExcelVolatilityService
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static double? GetUnderlyingVol(YLContext db, string optionCode, DateTime valueDate, string userGroup = null)
|
||||
{
|
||||
if (PS.Config.Is光大光子)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var exUm = DataCacheProvider.GetExchangeListOptionDataSource().GetData(optionCode);
|
||||
if (exUm == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(exUm.UnderlyingCode);
|
||||
if (um == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var price = um.Price ?? 0;
|
||||
|
||||
if (valuedateBLL.SystemDate.ValueDate > valueDate)
|
||||
{
|
||||
if (ConsGlobal.InstrumentType.IsStock(um.UnderlyingInstrumentType))
|
||||
{
|
||||
price = (db.eod_stock_price.Where(O => O.ValueDate <= valueDate && O.UnderlyingCode == um.UnderlyingCode)
|
||||
.OrderByDescending(n => n.ValueDate).Select(n => (double?)n.ClosePrice).FirstOrDefault()) ?? 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
price = (db.eod_commodity_future_price.Where(O => O.ValueDate <= valueDate && O.UnderlyingCode == um.UnderlyingCode)
|
||||
.OrderByDescending(n => n.ValueDate).Select(n => (double?)n.ClosePrice).FirstOrDefault()) ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
var req = new SingleVolReq
|
||||
{
|
||||
VolType = "交易",
|
||||
Strike = exUm.Strike,
|
||||
SpotPrice = price,
|
||||
TradeDate = valueDate,
|
||||
ExerciseDate = exUm.MaturityDate,
|
||||
IsMoneynessOption = "否",
|
||||
//req.CallPut = trade.CallPut;
|
||||
UnderlyingId = exUm.id,
|
||||
UnderlyingCode = exUm.UnderlyingCode,
|
||||
UnderlyingName = um.UnderlyingName,
|
||||
UnderlyingTypeId = um.UnderlyingTypeId,
|
||||
UserGroup = userGroup
|
||||
};
|
||||
|
||||
var vol = SingleVolService.GetSingleVol(req, 0);
|
||||
|
||||
return vol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static HandleResult<Dictionary<string, Dictionary<string, double?>>> GetTradeVol(DateTime date, List<string> tradeNumbers)
|
||||
{
|
||||
var result = new Dictionary<string, Dictionary<string, double?>>();
|
||||
|
||||
using (var context = new YLContext())
|
||||
{
|
||||
var trades = context.trade.Where(O => tradeNumbers.Contains(O.TradeNumber)).ToList();
|
||||
if (trades == null || trades.Count == 0)
|
||||
{ return new HandleResult<Dictionary<string, Dictionary<string, double?>>>("交易代码不存在"); }
|
||||
for (var i = 0; i < trades.Count; i++)
|
||||
{
|
||||
if (!result.ContainsKey(trades[i].TradeNumber))
|
||||
{ result.Add(trades[i].TradeNumber, new Dictionary<string, double?>()); }
|
||||
result[trades[i].TradeNumber]["TradeOpenVolatility"] = trades[i].TradeOpenVolatility;
|
||||
result[trades[i].TradeNumber]["TradeCloseVolatility"] = trades[i].TradeCloseVolatility;
|
||||
result[trades[i].TradeNumber]["NumOfSmoothingDays"] = trades[i].NumOfSmoothingDays;
|
||||
if (trades[i].StartDate > date) { result[trades[i].TradeNumber]["TradeVol"] = null; }
|
||||
else
|
||||
{
|
||||
result[trades[i].TradeNumber]["TradeVol"] = AnalyticalOptionTradeVolInterp.tradeVolLinearInterp(
|
||||
new Date(date),
|
||||
trades[i].TradeOpenVolatility.GetValueOrDefault(),
|
||||
trades[i].TradeCloseVolatility.GetValueOrDefault(),
|
||||
new Date(trades[i].StartDate.GetValueOrDefault()),
|
||||
new Date(trades[i].ExerciseDate.GetValueOrDefault()),
|
||||
trades[i].NumOfSmoothingDays.GetValueOrDefault(),
|
||||
DayCountMode.TradingDay,
|
||||
CalendarImpl.Get("chn")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new HandleResult<Dictionary<string, Dictionary<string, double?>>>(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user