Skip to content

Instantly share code, notes, and snippets.

@tomwhoiscontrary
tomwhoiscontrary / Time.java
Created November 6, 2017 13:04
Works out the correspondence between currentTimeMillis and nanoTime
import java.util.Arrays;
public class Time {
public static void main(String[] args) throws InterruptedException {
int n = 100;
int[] before = new int[n];
int[] after = new int[n];
// warmup
@tomwhoiscontrary
tomwhoiscontrary / Stamper.java
Last active December 18, 2017 11:20
A fun demo of unexpected (to me) file timestamp behaviour on Linux
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.time.Instant;
/**
@tomwhoiscontrary
tomwhoiscontrary / Main.java
Last active February 8, 2024 01:03
A simple Java web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
import com.sun.net.httpserver.Filter;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
@tomwhoiscontrary
tomwhoiscontrary / widget.cpp
Created March 29, 2018 17:08
Fresh as hell demonstration of perfect forwarding constructor with varargs in C++
#include <iostream>
#include <boost/make_shared.hpp>
class Widget {
public:
virtual int getMass() const = 0;
};
class SimpleWidget : Widget {
#include <iostream>
// modified from https://wandbox.org/permlink/YnHKdrHmMFiJsjOm
template <typename T, typename Deleter>
struct handle {
handle(T value, Deleter deleter = Deleter()) : value_(value), deleter_(deleter) {
}
~handle() {
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
public class Calculus {
public static void main(String[] args) {
double δx = 17.0;
double δy = 23.0;
double δxノδy = δx / δy;
System.out.println("δxノδy = " + δxノδy);
}
}
@tomwhoiscontrary
tomwhoiscontrary / blend.cpp
Last active June 11, 2018 16:46
Trying to make a curve by blending futures and swaps - see https://imgur.com/a/viMGk6J
#include <iostream>
#include <vector>
#include <boost/make_shared.hpp>
#include <ql/indexes/ibor/euribor.hpp>
#include <ql/math/interpolations/convexmonotoneinterpolation.hpp>
#include <ql/termstructures/yield/piecewiseyieldcurve.hpp>
#include <ql/termstructures/yield/ratehelpers.hpp>
#include <ql/time/daycounters/actual360.hpp>
@tomwhoiscontrary
tomwhoiscontrary / curve.cpp
Last active June 11, 2018 15:30
Simple attempt to build a Euribor curve
#include <iostream>
#include <vector>
#include <boost/make_shared.hpp>
#include <ql/indexes/ibor/euribor.hpp>
#include <ql/math/interpolations/all.hpp>
#include <ql/termstructures/yield/piecewiseyieldcurve.hpp>
#include <ql/termstructures/yield/ratehelpers.hpp>
#include <ql/time/daycounters/actual360.hpp>
@tomwhoiscontrary
tomwhoiscontrary / convexMonotoneClassic.csv
Last active July 25, 2018 14:37
Another demonstration that not all is right with the convex monotone implementation in QuantLib - https://imgur.com/a/ksS7OD8
term rate forward
0.0 -0.0033133321508 -0.0033133321508
0.1 -0.00329678287008599 -0.003263684308657968
0.2 -0.003247135027943958 -0.0031147407822318712
0.30000000000000004 -0.0031652069127224678 -0.00289212724033709
0.4 -0.00307524118684741 -0.002711931672110584
0.5 -0.0029812451740789943 -0.002491961467903277
0.6 -0.002878499729047622 -0.0022396014243447277
0.7 -0.0027726330307377965 -0.002047717424672988
0.7999999999999999 -0.002674128906090226 -0.0019474822563351547