Skip to content

Instantly share code, notes, and snippets.

@vshank77
Created May 2, 2017 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vshank77/5f3145f196cc42f09deb49c155bbdaa2 to your computer and use it in GitHub Desktop.
Save vshank77/5f3145f196cc42f09deb49c155bbdaa2 to your computer and use it in GitHub Desktop.
Generating CFI Codes
package io.abaci.dataserver.handlers.object;
import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import org.testng.annotations.Test;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import static io.abaci.util.ObjUtil.safePrefix;
public class CfiCodeGen {
private static final String[] liste0 = new String[]{"E. Equities", "D. Debts", "R. Rights", "O. Options", "F. Futures", "M. Others"};
private static final String[][] liste = new String[][]{
new String[]{"S. Shares", "P. Preferred shares", "R. Preference shares", "C. Convertible shares",
"F. Preferred convertible shares", "V. Preference convertible shares",
"U. Units, i.e. unit trusts/mutual funds/OPCVM/OICVM", "M. Others"},
new String[]{"B. Bonds", "C. Convertible bonds", "W. Bonds with warrants attached", "T. Medium-term notes", "Y. Money market instruments", "M. Others"},
new String[]{"A. Allotment rights", "S. Subscription rights", "P. Purchase rights", "W. Warrants", "M. Others", "X. UNDEFINED"},
new String[]{"C. Call options", "P. Put options", "M. Others", "X. UNDEFINED"},
new String[]{"F. Financial Futures", "C. Commodities Futures", "X. UNDEFINED"},
new String[]{"R. Referential Instruments", "M. Other assets"}
};
private static final String[][] liste2 = new String[][]{
new String[]{"V. Voting", "N. Non-voting", "R. Restricted voting", "E. Enhanced voting", "X. UNDEFINED"},
new String[]{"V. Voting", "N. Non-voting", "R. Restricted voting", "E. Enhanced voting", "X. UNDEFINED"},
new String[]{"V. Voting", "N. Non-voting", "R. Restricted voting", "E. Enhanced voting", "X. UNDEFINED"},
new String[]{"V. Voting", "N. Non-voting", "R. Restricted voting", "E. Enhanced voting", "X. UNDEFINED"},
new String[]{"V. Voting", "N. Non-voting", "R. Restricted voting", "E. Enhanced voting", "X. UNDEFINED"},
new String[]{"V. Voting", "N. Non-voting", "R. Restricted voting", "E. Enhanced voting", "X. UNDEFINED"},
new String[]{"C. Closed-end", "O. Open-end", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste3 = new String[][]{
new String[]{"F. Fixed rate", "Z. Zero rate", "V. Variable", "X. UNDEFINED"},
new String[]{"F. Fixed rate", "Z. Zero rate", "V. Variable", "X. UNDEFINED"},
new String[]{"F. Fixed rate", "Z. Zero rate", "V. Variable", "X. UNDEFINED"},
new String[]{"F. Fixed rate", "Z. Zero rate", "V. Variable", "X. UNDEFINED"},
new String[]{"F. Fixed rate", "Z. Zero rate", "V. Variable", "X. UNDEFINED"},
new String[]{"F. Fixed rate", "Z. Zero rate", "V. Variable", "X. UNDEFINED"}
};
private static final String[][] liste4 = new String[][]{
new String[]{"X. NOT APPLICABLE"},
new String[]{"S. Ordinary shares", "P. Preferred shares", "R. Preference shares", "C. Convertible shares",
"F. Preferred convertible shares", "V. Preference convertible shares", "B. Bonds", "O. Others", "X. UNDEFINED"},
new String[]{"S. Ordinary shares", "P. Preferred shares", "R. Preference shares", "C. Convertible shares",
"F. Preferred convertible shares", "V. Preference convertible shares", "B. Bonds", "O. Others", "X. UNDEFINED"},
new String[]{"B. Basket", "S. Stock-Equities", "D. Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "M. Others", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste5 = new String[][]{
new String[]{"A. American", "E. European", "X. UNDEFINED"},
new String[]{"A. American", "E. European", "X. UNDEFINED"},
new String[]{"A. American", "E. European", "X. UNDEFINED"},
new String[]{"A. American", "E. European", "X. UNDEFINED"}
};
private static final String[][] liste6 = new String[][]{
new String[]{"B. Basket", "S. Stock-Equities", "D. Debt Instruments", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"},
new String[]{"E. Extraction Resources", "A. Agriculture, forestry and fishing", "I. Industrial Products", "S. Services", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste7 = new String[][]{
new String[]{"C. Currencies", "T. Commodities", "R. Interest rates", "I. Indices", "X. UNDEFINED"},
new String[]{"R. Real Estate Deeds", "I. Insurance Policies", "E. Escrow Receipts", "F. Forwards", "P. Precious Metal Receipts", "O. Others", "X. UNDEFINED"}
};
private static final String[][] liste8 = new String[][]{
new String[]{"T. Restrictions", "U. Free", "X. UNDEFINED"},
new String[]{"R. Redeemable", "E. Extendible", "T. Redeemable/Extentible", "X. UNDEFINED"},
new String[]{"R. Redeemable", "E. Extendible", "T. Redeemable/Extentible", "X. UNDEFINED"},
new String[]{"T. Restrictions", "U. Free", "X. UNDEFINED"},
new String[]{"R. Redeemable", "E. Extendible", "T. Redeemable/Extentible", "X. UNDEFINED"},
new String[]{"R. Redeemable", "E. Extendible", "T. Redeemable/Extentible", "X. UNDEFINED"},
new String[]{"I. Income funds", "G. Growth funds", "M. Mixed funds", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste9 = new String[][]{
new String[]{"O. Nil paid", "P. Partly paid", "F. Fully paid", "X. UNDEFINED"},
new String[]{"F. Fixed rate Income", "C. Cumulative, Fixed Rate Income", "P. Participating Income", "Q. Cumulative, Participating Income",
"A. Adjustable Rate Income", "N. Normal Rate Income", "X. UNDEFINED"},
new String[]{"F. Fixed rate Income", "C. Cumulative, Fixed Rate Income", "P. Participating Income", "Q. Cumulative, Participating Income",
"A. Adjustable Rate Income", "N. Normal Rate Income", "X. UNDEFINED"},
new String[]{"F. Fixed rate Income", "C. Cumulative, Fixed Rate Income", "P. Participating Income", "Q. Cumulative, Participating Income",
"A. Adjustable Rate Income", "N. Normal Rate Income", "X. UNDEFINED"},
new String[]{"F. Fixed rate Income", "C. Cumulative, Fixed Rate Income", "P. Participating Income", "Q. Cumulative, Participating Income",
"A. Adjustable Rate Income", "N. Normal Rate Income", "X. UNDEFINED"},
new String[]{"F. Fixed rate Income", "C. Cumulative, Fixed Rate Income", "P. Participating Income", "Q. Cumulative, Participating Income",
"A. Adjustable Rate Income", "N. Normal Rate Income", "X. UNDEFINED"},
new String[]{"R. Real estate", "S. Securities", "M. Mixed-general", "C. Commodities", "D. Derivatives", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste10 = new String[][]{
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
// private static final String[][] liste11 = new String[][]{
// new String[]{"B. Basket", "S. Stock-Equities", "D. Intereste rate/Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"},
// new String[]{"B. Basket", "S. Stock-Equities", "D. Intereste rate/Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"},
// new String[]{"B. Basket", "S. Stock-Equities", "D. Intereste rate/Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"},
// new String[]{"B. Basket", "S. Stock-Equities", "D. Intereste rate/Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"},
// new String[]{"X. NOT APPLICABLE"}
// };
private static final String[][] liste12 = new String[][]{
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"}
};
private static final String[][] liste13 = new String[][]{
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste14 = new String[][]{
new String[]{"T. Government/Treasury guarantee", "G. Guaranteed", "S. Secured", "U. Unsecured/Unguarantee", "X. UNDEFINED"},
new String[]{"T. Government/Treasury guarantee", "G. Guaranteed", "S. Secured", "U. Unsecured/Unguarantee", "X. UNDEFINED"},
new String[]{"T. Government/Treasury guarantee", "G. Guaranteed", "S. Secured", "U. Unsecured/Unguarantee", "X. UNDEFINED"},
new String[]{"T. Government/Treasury guarantee", "G. Guaranteed", "S. Secured", "U. Unsecured/Unguarantee", "X. UNDEFINED"},
new String[]{"T. Government/Treasury guarantee", "G. Guaranteed", "S. Secured", "U. Unsecured/Unguarantee", "X. UNDEFINED"},
new String[]{"T. Government/Treasury guarantee", "G. Guaranteed", "S. Secured", "U. Unsecured/Unguarantee", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste15 = new String[][]{
new String[]{"F. Fixed maturity", "G. Fixed maturity with Call", "C. Fixed maturity with Put", "D. Fixed maturity with Put and Call", "A. Amortization plan",
"B. Amortization plan with Call", "T. Amortization plan with Put", "L. Amortization plan with Put and Call", "P. Perpetual", "Q. Perpetual with Call", "X. UNKNOWN"},
new String[]{"F. Fixed maturity", "G. Fixed maturity with Call", "C. Fixed maturity with Put", "D. Fixed maturity with Put and Call", "A. Amortization plan",
"B. Amortization plan with Call", "T. Amortization plan with Put", "L. Amortization plan with Put and Call", "P. Perpetual", "Q. Perpetual with Call", "X. UNKNOWN"},
new String[]{"F. Fixed maturity", "G. Fixed maturity with Call", "C. Fixed maturity with Put", "D. Fixed maturity with Put and Call", "A. Amortization plan",
"B. Amortization plan with Call", "T. Amortization plan with Put", "L. Amortization plan with Put and Call", "P. Perpetual", "Q. Perpetual with Call", "X. UNKNOWN"},
new String[]{"F. Fixed maturity", "G. Fixed maturity with Call", "C. Fixed maturity with Put", "D. Fixed maturity with Put and Call", "A. Amortization plan",
"B. Amortization plan with Call", "T. Amortization plan with Put", "L. Amortization plan with Put and Call", "P. Perpetual", "Q. Perpetual with Call", "X. UNKNOWN"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"F. Fixed maturity", "G. Fixed maturity with Call", "C. Fixed maturity with Put", "D. Fixed maturity with Put and Call", "A. Amortization plan",
"B. Amortization plan with Call", "T. Amortization plan with Put", "L. Amortization plan with Put and Call", "P. Perpetual", "Q. Perpetual with Call", "X. UNKNOWN"}
};
private static final String[][] liste16 = new String[][]{
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste17 = new String[][]{
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste18 = new String[][]{
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"T. Traditional warrants", "N. Naked warrants", "C. Covered warrants", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste19 = new String[][]{
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"C. Call", "P. Put", "B. Call and Put", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste20 = new String[][]{
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"B. Bearer", "R. Registered", "N. Bearer/Registered", "Z. Bearer depository receipt", "A. Registered depository receipt", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste100 = new String[][]{
new String[]{"B. Basket", "S. Stock-Equities", "D. Interest Rate / Notional Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"},
new String[]{"B. Basket", "S. Stock-Equities", "D. Interest Rate / Notional Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"},
new String[]{"B. Basket", "S. Stock-Equities", "D. Interest Rate / Notional Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"},
new String[]{"B. Basket", "S. Stock-Equities", "D. Interest Rate / Notional Debt Instruments", "T. Commodities", "C. Currencies", "I. Indices", "O. Options", "F. Futures", "W. Swaps", "M. Others", "X. UNDEFINED"}
};
private static final String[][] liste101 = new String[][]{
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"P. Physical", "C. Cash", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final String[][] liste102 = new String[][]{
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"S. Standardized", "N. Non-standardized", "X. UNDEFINED"},
new String[]{"X. NOT APPLICABLE"}
};
private static final Map<Integer, String[][]> Level3 = ImmutableMap.<Integer, String[][]>builder()
.put(0, liste2).put(1, liste3).put(2, liste4).put(3, liste5).put(4, liste6).put(5, liste7).build();
private static final Map<Integer, String[][]> Level4 = ImmutableMap.<Integer, String[][]>builder()
.put(0, liste8).put(1, liste14).put(2, liste18).put(3, liste100).put(4, liste12).put(5, liste17).build();
private static final Map<Integer, String[][]> Level5 = ImmutableMap.<Integer, String[][]>builder()
.put(0, liste9).put(1, liste15).put(2, liste19).put(3, liste101).put(4, liste13).put(5, liste17).build();
private static final Map<Integer, String[][]> Level6 = ImmutableMap.<Integer, String[][]>builder()
.put(0, liste10).put(1, liste16).put(2, liste20).put(3, liste102).put(4, liste17).put(5, liste17).build();
private static void sels(int s1, ImmutableMap.Builder<String, Sel> result) {
String[] l2Arr = liste[s1];
String[][] l3DblArr = Level3.get(s1);
String[][] l4DblArr = Level4.get(s1);
String[][] l5DblArr = Level5.get(s1);
String[][] l6DblArr = Level6.get(s1);
String l1 = liste0[s1];
for (int s2 = 0; s2 < l2Arr.length; s2++) {
String l2 = l2Arr[s2];
String[] l3Arr = l3DblArr[s2];
for (int s3 = 0; s3 < l3Arr.length; s3++) {
String l3 = l3Arr[s3];
String[] l4Arr = (s1 == 3) ? l4DblArr[s3] : l4DblArr[s2];
for (String l4 : l4Arr) {
String[] l5Arr = (s1 == 3) ? l5DblArr[s3] : l5DblArr[s2];
for (String l5 : l5Arr) {
String[] l6Arr = l6DblArr[s2];
for (String l6 : l6Arr) {
Sel sel = Sel.sel(l1, l2, l3, l4, l5, l6);
result.put(sel.code, sel);
}
}
}
}
}
}
@Test
public void genCodes() throws IOException {
ImmutableMap.Builder<String, Sel> result = ImmutableMap.builder();
for (int i = 0; i < 6; i++) { sels(i, result); }
Map<String, Sel> selMap = result.build();
try (PrintWriter pw = new PrintWriter(new FileWriter("/Users/svasudevan/temp/cficodes.tsv"))) {
selMap.values().forEach(pw::println);
}
System.out.println(selMap.size());
}
@RequiredArgsConstructor
private static class Sel {
private final String code;
private final String level1;
private final String level2;
private final String level3;
private final String level4;
private final String level5;
private final String level6;
@Override public String toString() {
return code + "\t" + level1 + "\t" + level2 + "\t" + level3 + "\t" + level4 + "\t" + level5 + "\t" + level6;
}
static Sel sel(String l1, String l2, String l3, String l4, String l5, String l6) {
return new Sel(code(l1, l2, l3, l4, l5, l6), l1, l2, l3, l4, l5, l6);
}
private static String code(String l1, String l2, String l3, String l4, String l5, String l6) {
return safePrefix(l1, ".") + safePrefix(l2, ".") + safePrefix(l3, ".")
+ safePrefix(l4, ".") + safePrefix(l5, ".") + safePrefix(l6, ".");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment