This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
NewerOlder