Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Too Many Ideas....

James Dunkerley jdunkerley

:octocat:
Too Many Ideas....
View GitHub Profile
View barrier_numpy.py
from random import random
from math import sqrt, log, exp
from numba import njit
import numpy
from numpy.random import normal
def path_final_min_max(initial, steps, sdt, volatility, drift):
randoms = numpy.exp(normal(size=steps)*volatility*sdt) * drift
randoms[0] = 1
factors = numpy.cumprod(randoms) * initial
@jdunkerley
jdunkerley / barrier_numba.py
Last active Apr 27, 2021
barrier_numba.py
View barrier_numba.py
from random import random
from math import sqrt, log, exp
from numba import njit, jit, prange
@njit(fastmath=True)
def box_muller_rand():
while True:
x = random() * 2.0 - 1
y = random() * 2.0 - 1
d = x * x + y * y
@jdunkerley
jdunkerley / barrier.cpp
Created Apr 27, 2021
Barrier Pricing via MonteCarlo in C++
View barrier.cpp
#include <cstdlib>
#include <random>
#include <iostream>
namespace barrierpricer {
static std::random_device rd;
static std::mt19937_64 rand_generator(rd());
static std::normal_distribution<> dis;
double box_muller_rand() {
@jdunkerley
jdunkerley / barrier.py
Last active Apr 27, 2021
Barrier Pricer
View barrier.py
from random import random
from math import sqrt, log, exp
def box_muller_rand():
while True:
x = random() * 2.0 - 1
y = random() * 2.0 - 1
d = x * x + y * y
if d < 1:
return x * sqrt(-2 * log(d) / d)
View spline.py
from typing import Tuple, List
import bisect
def compute_changes(x: List[float]) -> List[float]:
return [x[i+1] - x[i] for i in range(len(x) - 1)]
def create_tridiagonalmatrix(n: int, h: List[float]) -> Tuple[List[float], List[float], List[float]]:
A = [h[i] / (h[i] + h[i + 1]) for i in range(n - 2)] + [0]
B = [2] * n
C = [0] + [h[i + 1] / (h[i] + h[i + 1]) for i in range(n - 2)]
@jdunkerley
jdunkerley / azure-pipelines.xml
Created Apr 13, 2020
React CI Pipeline for Azure DevOps
View azure-pipelines.xml
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
View .eslintrc.js
module.exports = {
env: {
browser: true,
es6: true,
"jest/globals": true
},
extends: [
'plugin:react/recommended',
'standard'
],
@jdunkerley
jdunkerley / GeoProjection.html
Last active Jan 4, 2019
AlterD3 Geo Projections
View GeoProjection.html
<!-- ref: https://d3js.org/d3.v5.min.js //-->
<!-- Input Expected: SpatialObj //-->
<div id="ChartHtml">
<div id="chart1" style="background-color: white;">
<svg id="chartSVG" style="width:1400px; height:700px;background-color: white;"></svg>
</div>
<script>
const getSpatial = r => r['SpatialObj']
const baseProjection = d3.geoAzimuthalEquidistant()
@jdunkerley
jdunkerley / StackedBarChart.html
Last active Nov 14, 2018
AlterD3 Stacked Bar Chart
View StackedBarChart.html
<!-- ref: https://d3js.org/d3.v5.min.js -->
<!-- Input Expected: Group, Set, Value -->
<div id="ChartHtml">
<div id="chart1" style="background-color: white;">
<svg id="chartSVG" style="width:800px; height:600px;background-color: white;"></svg>
</div>
<script>
const svg = d3.select("#chartSVG")
const width = +svg.style("width").replace(/px/,"")
const height = +svg.style("height").replace(/px/,"")
@jdunkerley
jdunkerley / Chart.html
Created Nov 13, 2018
AlterD3 Coloured Bar Chart
View Chart.html
<!-- ref: https://d3js.org/d3.v5.min.js //-->
<!-- Input Expected: Name, Value, Set //-->
<style>
</style>
<div id="ChartHtml">
<div id="chart1" style="background-color: white;">
<svg id="chartSVG" style="width:800px; height:600px;background-color: white;"></svg>
</div>
<script>