Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ETD CSV parser #1556

Merged
merged 3 commits into from Sep 15, 2017
Merged

Add ETD CSV parser #1556

merged 3 commits into from Sep 15, 2017

Conversation

jodastephen
Copy link
Member

Add PositionCsvLoader to complement TradeCsvLoader.
Update trade loader to parse security trades.
Add extensibility to parser using a plugin, to pickup attributes.

Extensible parser using a plugin
Update trade parser to use plugin and parse security trades
Add `isKnownFormat()` method
*/
public static int parseInteger(String str) {
return Integer.parseInt(str);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method adding any value? Calling Integer.parseInt() directly seems good enough

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that we may add additional error handling or format handling later. With doubles in other projects we have supported (20) to mean -20.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok fair enough

* <p>
* The following standard columns are supported:<br />
* <ul>
* <li>The 'Strata Position Type' column is option, and defines the instrument type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional

* If that column is not found, the 'Long Quantity' and 'Short Quantity' columns will be used instead.
* <p>
* The single 'Expiry' column will normally just be set.
* Flex futures will also set the 'Expiry Day', 'Settlement Type' and 'Exercise Style'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this comment reference options rather than futures?

ValueWithFailures<List<T>> result = ValueWithFailures.of(ImmutableList.of());
for (CharSource charSource : charSources) {
ValueWithFailures<List<T>> singleResult = parseFile(charSource, positionType);
result = result.combinedWith(singleResult, Guavate::concatToList);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static import concatToList() for readibility

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a method reference 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry

// handle longQuantity and shortQuantity
double longQuantity = parseQuantity(row, LONG_QUANTITY_FIELD);
double shortQuantity = parseQuantity(row, SHORT_QUANTITY_FIELD);
double quantity = longQuantity - shortQuantity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to throw an exception or create a failure if quantity, short quantity and long quantity are all not populated.

Silently setting quantity to 0 feels dangerous; it's reasonable to expect clients to always provide a quantity (can always be manually set to 0 in the input if needed)

private static EtdSettlementType parseEtdSettlementType(String str) {
String upper = str.toUpperCase(Locale.ENGLISH);
Map<String, EtdSettlementType> valuesByCode =
Stream.of(EtdSettlementType.values()).collect(toImmutableMap(EtdSettlementType::getCode));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could store a static version of this map rather than recreating it every time the method is called.

* @param builder the builder to update
*/
public default void parsePositionAttributes(CsvRow row, PositionInfoBuilder builder) {
// do nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that these are builder mutating methods, 'populate' might be a better name than 'parse'.

Are we assuming that overrides of these methods may set non-attribute values on the builder (e.g. settlement date, trade date)?
If yes then parseInfo would be a better name than parseAttributes

If the methods are only expected to populate attributes then we could return a map of attributes and allow the clients to populate the builder

public void test_parseInteger() {
assertEquals(LoaderUtils.parseInteger("2"), 2);
assertThrowsIllegalArg(() -> LoaderUtils.parseInteger("Rubbish"));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a test of core java functionality

@jodastephen jodastephen merged commit 82490fc into master Sep 15, 2017
@jodastephen jodastephen deleted the topic/etd-csv branch September 15, 2017 16:35
@jodastephen jodastephen added this to the v1.4 milestone Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants