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

Conversation

Projects
None yet
2 participants
@jodastephen
Member

jodastephen commented Sep 11, 2017

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

jodastephen added some commits Sep 7, 2017

Add ETD CSV parser
Extensible parser using a plugin
Update trade parser to use plugin and parse security trades
Change type column name
Add `isKnownFormat()` method
*/
public static int parseInteger(String str) {
return Integer.parseInt(str);
}

This comment has been minimized.

@brianweller89

brianweller89 Sep 14, 2017

Contributor

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

This comment has been minimized.

@jodastephen

jodastephen Sep 15, 2017

Member

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.

This comment has been minimized.

@brianweller89

brianweller89 Sep 15, 2017

Contributor

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,

This comment has been minimized.

@brianweller89

brianweller89 Sep 14, 2017

Contributor

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'.

This comment has been minimized.

@brianweller89

brianweller89 Sep 14, 2017

Contributor

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);

This comment has been minimized.

@brianweller89

brianweller89 Sep 14, 2017

Contributor

Static import concatToList() for readibility

This comment has been minimized.

@jodastephen

jodastephen Sep 15, 2017

Member

Its a method reference 😄

This comment has been minimized.

@brianweller89

brianweller89 Sep 15, 2017

Contributor

Oops, sorry

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

This comment has been minimized.

@brianweller89

brianweller89 Sep 14, 2017

Contributor

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));

This comment has been minimized.

@brianweller89

brianweller89 Sep 14, 2017

Contributor

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

This comment has been minimized.

@brianweller89

brianweller89 Sep 14, 2017

Contributor

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"));
}

This comment has been minimized.

@brianweller89

brianweller89 Sep 14, 2017

Contributor

This is just a test of core java functionality

@jodastephen jodastephen merged commit 82490fc into master Sep 15, 2017

15 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
security/snyk No new issues
Details
security/snyk - modules/basics/pom.xml No new issues
Details
security/snyk - modules/calc/pom.xml No new issues
Details
security/snyk - modules/collect/pom.xml No new issues
Details
security/snyk - modules/data/pom.xml No new issues
Details
security/snyk - modules/loader/pom.xml No new issues
Details
security/snyk - modules/market/pom.xml No new issues
Details
security/snyk - modules/math/pom.xml No new issues
Details
security/snyk - modules/measure/pom.xml No new issues
Details
security/snyk - modules/pom.xml No new issues
Details
security/snyk - modules/pricer/pom.xml No new issues
Details
security/snyk - modules/product/pom.xml No new issues
Details
security/snyk - modules/report/pom.xml No new issues
Details

@jodastephen jodastephen deleted the topic/etd-csv branch Sep 15, 2017

@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