Ejemplo n.º 1
0
        public static bool DoesUcfDiffer(this ISwapDescription swap, IUnrealisedCashFlow[] rhsUcf)
        {   // iterates over today's UCF
            var lhsUcf = swap.Position.UnrealisedCashFlows;

            if (lhsUcf == null && rhsUcf == null)
            {
                return(false);
            }
            if (lhsUcf == null || rhsUcf == null)
            {
                return(true);
            }
            // now both are non-null
            if (lhsUcf.Length != rhsUcf.Length)
            {
                return(true);
            }

            for (var i = 0; i < lhsUcf.Length; i++) // assume CFs are sorted
            {
                var lhs = lhsUcf[i]; var rhs = rhsUcf[i];
                if (lhs.PayDate != rhs.PayDate ||
                    lhs.ShortCashFlowType != rhs.ShortCashFlowType ||
                    lhs.CashType != rhs.CashType ||
                    lhs.Currency != rhs.Currency ||
                    lhs.Amount != rhs.Amount ||
                    lhs.FxFix != rhs.FxFix)
                {
                    return(true);
                }
            }
            ;
            return(false);
        }
Ejemplo n.º 2
0
 public static IUnrealisedCashFlow[] GetUcfSudden(this ISwapDescription swap, IUnrealisedCashFlow[] yesterday)
 {   // iterates over yesterday's UCF.  UCF Sudden is the amount that "disappeared".
     if (yesterday == null || yesterday.Length == 0)
     {
         return(new UnrealisedCashFlow[0]);
     }
     return(yesterday
            .Where(y => !swap.Position.UnrealisedCashFlows.Any(t => y.UcfMatches(t, swap.SwapCurrency != y.Currency)) &&
                   !swap.Position.RealisedCashFlows.Any(r => y.UcfMatches(r, swap.ValueDate, swap.SwapCurrency == y.Currency))
                   ).ToArray());
 }
Ejemplo n.º 3
0
 public static IRealisedCashFlow[] GetRcfSudden(this ISwapDescription swap, IUnrealisedCashFlow[] yesterday)
 {   // iterates of today's RCF.  RCF Sudden is the amount that "appeared".
     return(swap.Position.RealisedCashFlows
            .Where(r => r.DtdAmount != 0)
            .Select(r =>
     {
         var prevAmount = yesterday?.Where(y => y.UcfMatches(r, swap.ValueDate, swap.SwapCurrency != y.Currency)).Sum(y => y.Amount * y.FxFix) ?? 0.0;
         return new PFSFeed.Model.RealisedCashFlow(r.ShortCashFlowType, r.CashType, r.LtdAmount, r.DtdAmount * r.FxFix - prevAmount, r.Currency + "->" + swap.SwapCurrency, r.FxFix);
     })
            .ToArray());
 }
Ejemplo n.º 4
0
        public PfsData(int date, ISwapDescription swap_T_1, ISwapDescription swap_T_2 = null, double fx = 1, bool showFixes = false)
        {
            Date     = date;
            Swap_T_1 = swap_T_1;
            Swap_T_2 = swap_T_2;

            //fxRates = fxHist.ContainsKey(Date) ? fxHist[Date] : null;
            //fxRate = Utility.GetFxRate(fxRates, Swap_T_1.SwapCurrency);
            fxRate         = fx;
            this.showFixes = showFixes;
            yesterdayUcf   = swap_T_2?.Position?.UnrealisedCashFlows;
        }
Ejemplo n.º 5
0
 public static IUnrealisedCashFlow[] GetUcfDtd(this ISwapDescription swap, IUnrealisedCashFlow[] yesterday)
 {   // iterates over today's UCF
     if (yesterday == null || yesterday.Length == 0)
     {
         return(swap.Position.UnrealisedCashFlows);
     }
     return(swap.Position.UnrealisedCashFlows.Select(t =>
     {
         var prevAmount = yesterday.FirstOrDefault(y => t.UcfMatches(y, swap.SwapCurrency != t.Currency))?.Amount ?? 0.0;
         return new PFSFeed.Model.UnrealisedCashFlow(t.PayDate, t.ShortCashFlowType, t.CashType, (t.Amount - prevAmount) * t.FxFix, t.Currency + "->" + swap.SwapCurrency, t.FxFix, 0, 0, 0);
     }).ToArray());
 }
Ejemplo n.º 6
0
        public Dictionary <int, ISwapDescription> FetchPfsSwapHistory(Region region, string pfsId, int fromDate, int tillDate = 0)
        {
            if (tillDate < fromDate)
            {
                tillDate = Utility.DateToRover8(DateTime.Today);
            }

            var      retVal = new Dictionary <int, ISwapDescription>();
            DateTime dt;

            for (dt = Utility.Rover8ToDate(fromDate); dt < Utility.Rover8ToDate(tillDate); dt = Utility.AddBusinessDays(dt, 1, null))
            {
                ISwapDescription val = null;
                try { val = PFSGateway.GetEoDSwap(pfsId, region.ToString(), dt); } catch (ParsingException) { }
                retVal.Add(Utility.DateToRover8(dt), val);
            }

            ISwapDescription valLive = null;

            try { valLive = dt >= DateTime.Today ? PFSGateway.GetSwap(pfsId) : PFSGateway.GetEoDSwap(pfsId, region.ToString(), dt); } catch (ParsingException) { }
            retVal.Add(Utility.DateToRover8(dt >= DateTime.Today ? DateTime.Today : dt), valLive);
            return(retVal);
        }
Ejemplo n.º 7
0
 public static PfsDbConsistencyData CreatePfsDbConsistencyData(ISwapDescription p, PaaData d)
 {
     return(new PfsDbConsistencyData
     {
         EodDate = p.ValueDate,
         PosId = d.PosId,
         PfsTQ = p.Position.TradedQuantity,
         DbTQ = d.Quantity,
         PfsAvgCost = Math.Round(p.Position.ProfitLoss.AverageCost, 6),
         DbAvgCost = d.AverageCost,
         DbAvgCostA = d.AvgCostA,
         PfsRlsd = Utility.Round(p.Position.RealisedCashFlows.Where(cf => cf.ShortCashFlowType != ShortCashFlowTypeEnum.Distibution && cf.ShortCashFlowType != ShortCashFlowTypeEnum.Reset && cf.ShortCashFlowType != ShortCashFlowTypeEnum.TransactionFee)?.Sum(cf => cf.LtdAmount) ?? 0.0),
         DbRlsd = d.Realised,
         DbRlsdA = d.RlsdA,
         PfsComm = Utility.Round(p.Position.RealisedCashFlows.Where(cf => cf.ShortCashFlowType == ShortCashFlowTypeEnum.TransactionFee)?.Sum(cf => cf.LtdAmount) ?? 0.0),
         DbComm = d.Commission,
         DbCommA = d.CommA,
         PfsDiv = Utility.Round(p.Position.RealisedCashFlows.Where(cf => cf.ShortCashFlowType == ShortCashFlowTypeEnum.Distibution)?.Sum(cf => cf.LtdAmount) ?? 0.0),
         DbDiv = d.Dividend,
         PfsCoupon = Utility.Round(p.Position.RealisedCashFlows.Where(cf => cf.ShortCashFlowType == ShortCashFlowTypeEnum.Reset)?.Sum(cf => cf.LtdAmount) ?? 0.0),
         DbCoupon = d.Coupon,
         PfsId = d.PfsId,
     });
 }