Initial commit

This commit is contained in:
Kevin Keogh
2017-04-02 15:35:28 -04:00
commit 99b350a852
6 changed files with 203 additions and 0 deletions

32
src/black_scholes.c Normal file
View File

@@ -0,0 +1,32 @@
#define _XOPEN_SOURCE
#include "black_scholes.h"
#include <cblas.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
double normalcdf(double value)
{
return 0.5 * erfc(-value * M_SQRT1_2);
}
double bsm(double spot, double rfr, double vol, double strike,
struct tm expiry, struct tm value, int type)
{
double d1, d2, tte, price;
time_t value_date, expiry_date;
expiry_date = mktime(&expiry);
value_date = mktime(&value);
tte = difftime(expiry_date, value_date) / (60 * 60 * 24 * 365);
d1 = log(spot / strike) + tte * (rfr + pow(vol, 2) / 2)
/ (vol * pow(tte, 0.5));
d2 = d1 - (vol * pow(tte, 0.5));
price = spot * normalcdf(d1 * type) * type -
strike * exp(-rfr * tte) * normalcdf(d2 * type) * type;
return price;
}