From c0b15a96c176f01a7199d3c3d107946341af3e50 Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Fri, 9 Apr 2021 16:41:57 -0400 Subject: Added a basic skeleton for derivative trades, if we dedice to look at those as well. --- data/xml_derivative_only_test.xml | 97 ++++++++++++++++++++++ .../brown/cs/student/term/parsing/Transaction.java | 16 +++- .../java/edu/brown/cs/student/TransactionTest.java | 20 +++++ 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 data/xml_derivative_only_test.xml diff --git a/data/xml_derivative_only_test.xml b/data/xml_derivative_only_test.xml new file mode 100644 index 0000000..cd19564 --- /dev/null +++ b/data/xml_derivative_only_test.xml @@ -0,0 +1,97 @@ + + + + X0306 + + 4 + + 2021-04-07 + + + 0001005817 + TOMPKINS FINANCIAL CORP + TMP + + + + + 0001463126 + Fessenden Daniel J. + + + C/O TOMPKINS FINANCIAL CORPORATION + P.O. BOX 460 + ITHACA + NY + 14851 + + + + 1 + + + + + + + Phantom Stock + + + + + + 2021-04-07 + + + 4 + A + 0 + + + + + 142.275 + + + 80.8293 + + + A + + + + + + + + + + + Common Stock + + + 142.275 + + + + + 4757.199 + + + + + D + + + + + + + Each share of phantom stock is the economic equivalent of one share of common stock. Phantom stock represents deferred stock compensation under the Amended and Restated Retainer Plan for Eligible Directors of Tompkins Financial Corporation and its Wholly-Owned Subsidiaries. These shares are held in a rabbi trust pending distribution upon the occurrence of certain events specified in the Plan. The reporting person has no voting or investment power over the shares prior to such distribution. + + + + /s/Daniel J. Fessenden + 2021-04-09 + + diff --git a/src/main/java/edu/brown/cs/student/term/parsing/Transaction.java b/src/main/java/edu/brown/cs/student/term/parsing/Transaction.java index 718d2a5..2111048 100644 --- a/src/main/java/edu/brown/cs/student/term/parsing/Transaction.java +++ b/src/main/java/edu/brown/cs/student/term/parsing/Transaction.java @@ -22,7 +22,7 @@ public class Transaction { private final String ticker; /** - * Constructor that extracts the important info from the document. + * Constructor that represents the transaction from the document. * @param document The document parsed from the xml file. */ public Transaction(Document document) { @@ -34,7 +34,19 @@ public class Transaction { id = id(); ticker = ticker(); - NodeList tradesAsNodes = document.getElementsByTagName("nonDerivativeTransaction"); + // There are two types of transactions within the xml - derivative and non derivative. + NodeList nonDerivative = document.getElementsByTagName("nonDerivativeTransaction"); + //NodeList derivative = document.getElementsByTagName("derivativeTransaction"); + // Processing both of their trades into the trades instance var. + processTransactions(nonDerivative); + //processTransactions(derivative); + } + + /** + * Takes a transaction as a node list, then processes and stores them into trades. + * @param tradesAsNodes The trades within the transaction as a nodelist. + */ + private void processTransactions(NodeList tradesAsNodes) { int numTrades = tradesAsNodes.getLength(); for(int i = 0; i < numTrades; i++) { NodeList tradeValues = getValueList(tradesAsNodes.item(i)); diff --git a/src/test/java/edu/brown/cs/student/TransactionTest.java b/src/test/java/edu/brown/cs/student/TransactionTest.java index 444263d..f9a00f7 100644 --- a/src/test/java/edu/brown/cs/student/TransactionTest.java +++ b/src/test/java/edu/brown/cs/student/TransactionTest.java @@ -67,6 +67,26 @@ public class TransactionTest { tearDown(); } + /* + @Test + public void derivativeTransaction(){ + setUp(); + Document doc = _xmlParser.parse("data/xml_derivative_only_test.xml"); + assertNotEquals(doc, null); + + // One trades in transaction + Transaction transaction = new Transaction(doc); + assertEquals(transaction.getTrades().size(), 1); + + // TODO: add more qualities on trade to test... + Trade firstTrade = transaction.getTrades().get(0); + assertEquals(firstTrade.getNumShares(), 8236); + assertEquals(firstTrade.getHolder().getId(), 1463126); + + tearDown(); + } + */ + @Test public void noTrades(){ setUp(); -- cgit v1.2.3-70-g09d2