70 lines
2.8 KiB
C#
70 lines
2.8 KiB
C#
using YLErp.Modules.CalculationModule;
|
|
using YLErp.Modules.EodModule;
|
|
|
|
namespace YLErp.BLL.Eod
|
|
{
|
|
/// <summary>
|
|
/// 日终结算基类
|
|
/// </summary>
|
|
public class EodOperationBase
|
|
{
|
|
/// <summary>
|
|
/// 根据交易方向判断是否需要加符号
|
|
/// </summary>
|
|
public static int GetSign(string tradeSide)
|
|
{
|
|
return TradeCalcHelper.GetBuySellSign(tradeSide);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取收盘成功的最后一个结算日(isPreviousDate:date参数的上一日)
|
|
/// </summary>
|
|
public static DateTime GetLastSettlementDate(DateTime date, bool isPreviousDate = false)
|
|
{
|
|
return isPreviousDate ? EodDataHelper.GetPreSettleDate(date) : EodDataHelper.GetLastSettleDate(date);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取结算价收盘成功的最后一个结算日
|
|
/// </summary>
|
|
/// <param name="previousDateIsDefault">查询不到最后收盘日时是否返回当年最早收盘价收盘日,false返回DateTime.MinValue</param>
|
|
public static DateTime GetLastSettlementDate_Settle(bool lastSettleDateIsDefault = true)
|
|
{
|
|
DateTime? date = null;
|
|
using (var db = new YLContext())
|
|
{
|
|
date = db.eod_pnl_s.Select(O => O.ValueDate).OrderByDescending(O => O).FirstOrDefault();
|
|
if (date == null || date == DateTime.MinValue)
|
|
{
|
|
if (lastSettleDateIsDefault)
|
|
{
|
|
var accruedTotalPnlStartDate = valuedateBLL.SystemDate.AccruedTotalPnlStartDate ?? DateTime.Today.AddDays(-DateTime.Today.DayOfYear + 1);
|
|
date = db.eodStatus.Where(t => t.Status == "已收盘" && t.ValueDate >= accruedTotalPnlStartDate).Min(O => (DateTime?)O.ValueDate) ?? DateTime.MinValue;
|
|
}
|
|
else
|
|
{
|
|
date = DateTime.MinValue;
|
|
}
|
|
}
|
|
}
|
|
return date.Value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取持仓盈亏
|
|
/// </summary>
|
|
public static double GetPositionPnl(double Pv, double TradePrice, double Notional, double OriginalNotional, string BuySell)
|
|
{
|
|
var d = (double.IsNaN(Pv) ? 0.0 : Pv) - TradePrice * Notional / OriginalNotional * GetSign(BuySell);
|
|
return double.IsNaN(d) ? 0 : d;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取持仓成本(交易员角度)
|
|
/// </summary>
|
|
public static double GetPositionCost(double TradePrice, double PositionNotional, double OriginalNotional, string BuySell)
|
|
{
|
|
return OriginalNotional > 0 ? TradePrice * PositionNotional / OriginalNotional * GetSign(BuySell) : 0;
|
|
}
|
|
}
|
|
} |