Ejemplo n.º 1
0
        // parse full definition
        private static FxSwapTrade parseFull(CsvRow row, TradeInfo info)
        {
            FxSingle nearFx = FxSingleTradeCsvLoader.parseFxSingle(row, "");
            FxSingle farFx  = FxSingleTradeCsvLoader.parseFxSingle(row, "Far ");

            return(FxSwapTrade.of(info, FxSwap.of(nearFx, farFx)));
        }
Ejemplo n.º 2
0
        // convention-based
        // ideally we'd use the trade date plus "period to start" to get the spot/payment date
        // but we don't have all the data and it gets complicated in places like TRY, RUB and AED
        private static FxSwapTrade parseConvention(CsvRow row, TradeInfo info)
        {
            CurrencyPair pair            = CurrencyPair.parse(row.getValue(CONVENTION_FIELD));
            BuySell      buySell         = LoaderUtils.parseBuySell(row.getValue(BUY_SELL_FIELD));
            Currency     currency        = Currency.parse(row.getValue(CURRENCY_FIELD));
            double       notional        = LoaderUtils.parseDouble(row.getValue(NOTIONAL_FIELD));
            double       nearFxRate      = LoaderUtils.parseDouble(row.getValue(FX_RATE_FIELD));
            double       farFxRate       = LoaderUtils.parseDouble(row.getValue(FAR_FX_RATE_DATE_FIELD));
            LocalDate    nearPaymentDate = LoaderUtils.parseDate(row.getValue(PAYMENT_DATE_FIELD));
            LocalDate    farPaymentDate  = LoaderUtils.parseDate(row.getValue(FAR_PAYMENT_DATE_FIELD));
            Optional <BusinessDayAdjustment> paymentAdj = FxSingleTradeCsvLoader.parsePaymentDateAdjustment(row);

            CurrencyAmount amount   = CurrencyAmount.of(currency, buySell.normalize(notional));
            FxRate         nearRate = FxRate.of(pair, nearFxRate);
            FxRate         farRate  = FxRate.of(pair, farFxRate);
            FxSwap         fx       = paymentAdj.map(adj => FxSwap.of(amount, nearRate, nearPaymentDate, farRate, farPaymentDate, adj)).orElseGet(() => FxSwap.of(amount, nearRate, nearPaymentDate, farRate, farPaymentDate));

            return(FxSwapTrade.of(info, fx));
        }
Ejemplo n.º 3
0
        // loads a single CSV file
        private ValueWithFailures <IList <T> > parseFile <T>(CsvIterator csv, Type <T> tradeType) where T : com.opengamma.strata.product.Trade
        {
            IList <T>           trades   = new List <T>();
            IList <FailureItem> failures = new List <FailureItem>();

            while (csv.hasNext())
            {
                CsvRow row = csv.next();
                try
                {
                    string    typeRaw = row.getField(TYPE_FIELD);
                    TradeInfo info    = parseTradeInfo(row);
                    switch (typeRaw.ToUpper(Locale.ENGLISH))
                    {
                    case "FRA":
                        if (tradeType == typeof(FraTrade) || tradeType == typeof(Trade))
                        {
                            trades.Add(tradeType.cast(FraTradeCsvLoader.parse(row, info, resolver)));
                        }
                        break;

                    case "SECURITY":
                        if (tradeType == typeof(SecurityTrade) || tradeType == typeof(GenericSecurityTrade) || tradeType == typeof(ResolvableSecurityTrade) || tradeType == typeof(Trade))
                        {
                            SecurityQuantityTrade parsed = SecurityCsvLoader.parseTrade(row, info, resolver);
                            if (tradeType.IsInstanceOfType(parsed))
                            {
                                trades.Add(tradeType.cast(parsed));
                            }
                        }
                        break;

                    case "SWAP":
                        if (tradeType == typeof(SwapTrade) || tradeType == typeof(Trade))
                        {
                            IList <CsvRow> variableRows = new List <CsvRow>();
                            while (csv.hasNext() && csv.peek().getField(TYPE_FIELD).ToUpper(Locale.ENGLISH).Equals("VARIABLE"))
                            {
                                variableRows.Add(csv.next());
                            }
                            trades.Add(tradeType.cast(SwapTradeCsvLoader.parse(row, variableRows, info, resolver)));
                        }
                        break;

                    case "TERMDEPOSIT":
                    case "TERM DEPOSIT":
                        if (tradeType == typeof(TermDepositTrade) || tradeType == typeof(Trade))
                        {
                            trades.Add(tradeType.cast(TermDepositTradeCsvLoader.parse(row, info, resolver)));
                        }
                        break;

                    case "VARIABLE":
                        failures.Add(FailureItem.of(FailureReason.PARSING, "CSV file contained a 'Variable' type at line {lineNumber} that was not preceeded by a 'Swap'", row.lineNumber()));
                        break;

                    case "FX":
                    case "FXSINGLE":
                    case "FX SINGLE":
                        if (tradeType == typeof(FxSingleTrade) || tradeType == typeof(FxTrade) || tradeType == typeof(Trade))
                        {
                            trades.Add(tradeType.cast(FxSingleTradeCsvLoader.parse(row, info, resolver)));
                        }
                        break;

                    case "FXSWAP":
                    case "FX SWAP":
                        if (tradeType == typeof(FxSwapTrade) || tradeType == typeof(FxTrade) || tradeType == typeof(Trade))
                        {
                            trades.Add(tradeType.cast(FxSwapTradeCsvLoader.parse(row, info, resolver)));
                        }
                        break;

                    default:
                        failures.Add(FailureItem.of(FailureReason.PARSING, "CSV file trade type '{tradeType}' is not known at line {lineNumber}", typeRaw, row.lineNumber()));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    failures.Add(FailureItem.of(FailureReason.PARSING, ex, "CSV file trade could not be parsed at line {lineNumber}: {exceptionMessage}", row.lineNumber(), ex.Message));
                }
            }
            return(ValueWithFailures.of(trades, failures));
        }