Skip to content

Instantly share code, notes, and snippets.

Value Percentile TotalCount 1/(1-Percentile
5023.00 0.500000000000 502647 2.00
9023.00 0.900000000000 902416 10.00
9791.00 0.975000000000 979157 40.00
9919.00 0.990625000000 992103 106.67
9983.00 0.998046875000 998439 512.00
10047.00 0.998632812500 1000000 731.43
Value Percentile TotalCount 1/(1-Percentile)
1.00 0.000000000000 104 1.00
999.00 0.100000000000 100120 1.11
1999.00 0.200000000000 200638 1.25
3007.00 0.300000000000 301219 1.43
3999.00 0.400000000000 400228 1.67
5023.00 0.500000000000 502647 2.00
5503.00 0.550000000000 550255 2.22
6015.00 0.600000000000 601367 2.50
String dsl = args[0];
System.out.println(dsl);
CompilationContext context = new CompilationContext("FXTradeTemplate", dsl);
Function<CompilationContext, RuleEngine<FXTransaction>> pipeline = RuleEnginePipeline.pipeline();
RuleEngine<FXTransaction> rules = pipeline.apply(context);
System.out.format("Rule Name %s \n", rules.name);
public static List<CompilerOutput> compile(String className, String code) {
try {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> ds = new DiagnosticCollector<>();
try (StandardJavaFileManager mgr = compiler.getStandardFileManager(ds, null, null)) {
JavaFileObject file = new InMemoryJavaCode(className, code);
Iterable<? extends JavaFileObject> sources = Arrays.asList(file);
public class FXTradeTemplate$REPLACE {
static RuleSchema<FXTransaction> tradeSchema = schema("Trade", schema -> {
schema.attribute("source", FXTransaction::getSource);
schema.attribute("target", FXTransaction::getTarget);
schema.attribute("amount", FXTransaction::getAmount);
schema.attribute("date", FXTransaction::getTransactionDate);
schema.attribute("bankCode", FXTransaction::getBankCode);
schema.attribute("accountNo", FXTransaction::getAccountNum);
});
newOrder(equity("IBM"), (order, ts) -> {
order
.buy(100)
.at(126.07d);
ts.execute(order);
});
newOrder(equity("GOOG"), (order, ts) -> {
order
specification("A Stack", scenario -> {
scenario.should("Empty stack should have size 0", then -> {
Stack<String> stack = new Stack<>();
then.value(stack.size()).shouldBe(0);
});
scenario.should("pop values in last-in-first-out order", then -> {
Stack<String> stack = new Stack<>();
machine("Circuit Breaker", machine -> {
machine.startWith("OPEN");
machine.at("OPEN", rule -> {
rule.when("connect", failOp, "OPEN", "CLOSED");
});
machine.at("CLOSED", rule -> {
rule.when("connect", s -> {
}, "CLOSED");
decisionSystem("FX Transaction", tradeSchema, s -> {
s.rule("High Transfer discount", condition -> {
condition
.gt("amount", 1000d)
.eq("source", "SGD")
.eq("target", "INR")
.action((rule, row) -> row.setDiscount(2.0d));
});
public interface RecordContainer<T> extends Closeable {
boolean append(T message);
void read(RecordConsumer<T> reader);
void read(long offSet, RecordConsumer<T> reader);
default void close() {}
int size();
String formatName();
}