Skip to content

Instantly share code, notes, and snippets.

View OpenGamma-Blog's full-sized avatar

OpenGamma OpenGamma-Blog

View GitHub Profile
Expression expr = sin(mul(sq('x'), sq('y')));
Vector1D g_expr = vector(expr, d(expr, 'x'), d(expr, 'x'));
System.out.println(g_expr.describe());
Expression:
[(sin (* (sq x) (sq y)))
(d (sin (* (sq x) (sq y))) x)
(d (sin (* (sq x) (sq y))) x)]
gets turned into:
import static com.lambder.deriva.Deriva.*;
public class Formulas {
public static Expression black(final boolean isCall) {
// Logistic aproximation of Cumulated Standard Normal Distribution
// 1/( e^(-0.07056 * x^3 - 1.5976*x) + 1)
Expression N = div(1.0,
add(
(use 'com.lambder.deriva.core)
(def N
'(/ 1
(+ 1
(exp (-
(* -0.07056 (pow x 3))
(* -1.5976 x)))))
(def d1 '(/ (+ (/ F K) (* T (/ (sq sigma) 2)))))
@OpenGamma-Blog
OpenGamma-Blog / gist:4943722
Last active December 13, 2015 16:58
MATLAB and OpenGamma 3
package com.opengamma.externalanalytics.test;
import java.net.URL;
import com.mathworks.mps.client.MWClient;
import com.mathworks.mps.client.MWHttpClient;
import com.opengamma.externalanalytics.matlab.CustomMatlabModel;
public class StandAloneRunner {
public static void main(String[] args) {
@OpenGamma-Blog
OpenGamma-Blog / gist:4943711
Created February 13, 2013 10:34
MATLAB and OpenGamma 1
function r = MatlabBlackScholes(isCall, Price, Strike, Rate, Time, Volatility, Yield)
[Call, Put] = blsprice(Price, Strike, Rate, Time, Volatility, Yield);
if isCall
r = Call;
else
r = Put;
end
end
@OpenGamma-Blog
OpenGamma-Blog / gist:4943695
Last active December 13, 2015 16:58
MATLAB and OpenGamma 2
package com.opengamma.externalanalytics.matlab;
import java.io.IOException;
import com.mathworks.mps.client.MATLABException;
public interface CustomMatlabModel {
public double MatlabBlackScholes(boolean isCall, double Price, double Strike, double Rate, double Time, double Volatility, double Yield) throws IOException, MATLABException;
}
@OpenGamma-Blog
OpenGamma-Blog / gist:3799535
Created September 28, 2012 12:31
slf4j example 4
18:14:40.075 [main] INFO c.o.m.n.OGSLATECRawWrapper - Logging started for native SLATEC calls
18:14:40.080 [main] WARN c.o.m.n.OGSLATECRawWrapper - MESSAGE FROM ROUTINE DERFC IN LIBRARY SLATEC.
18:14:40.080 [main] WARN c.o.m.n.OGSLATECRawWrapper - POTENTIALLY RECOVERABLE ERROR, PROG CONTINUES, TRACEBACK REQUESTED
18:14:40.080 [main] WARN c.o.m.n.OGSLATECRawWrapper - X SO BIG ERFC UNDERFLOWS
18:14:40.080 [main] WARN c.o.m.n.OGSLATECRawWrapper - ERROR NUMBER = 1
@OpenGamma-Blog
OpenGamma-Blog / gist:3799238
Created September 28, 2012 11:14
slf4j example 3
// global cache
extern JavaVM JVMCache; // global JVM pointer cache
static jclass wrappedClass = NULL; // holds the class that wraps the native code
static jclass slf4jLoggerClass = NULL; // holds the slf4j class
static jfieldID loggerFieldID = 0; // the ID of the Logger field "log" (this is a static reference set each time by the classloader)
static jmethodID loggerMethodID = 0; // the ID of the logger method (it's the ID obtained from the slf4j class (interface), the vtable is used to look up the particular method in the object which instantiated from this class)
// C code for the initialisation (we leave out exception handling for brevity)
#ifdef __cplusplus
@OpenGamma-Blog
OpenGamma-Blog / gist:3799233
Created September 28, 2012 11:13
slf4j example 2
public class OGNativeCodeWrapper {
// initialises the logger by caching the static references to the method IDs etc
private static native void initialiseLogger();
private static Logger log;
static
{
try
{
@OpenGamma-Blog
OpenGamma-Blog / gist:3799224
Created September 28, 2012 11:12
slf4j example 1
public class OGNativeCodeWrapper {
private static Logger log;
static {
try {
System.loadLibrary("NativeLibraryWrapper"); // Load the native library wrapper with symbols to logging routines overridden
} catch (UnsatisfiedLinkError e) {
System.err.println("Cannot find system library.\n" + e);
// handle error
}
initialiseLogger();