Skip to content

Instantly share code, notes, and snippets.

@alecloudenback
alecloudenback / primes.md
Last active December 28, 2022 03:33
List of primes

Primes Benchmark

I got nerd-sniped from this LinkedIn post. On my computer, the R screenshot above ran in 1.564 minutes on my laptop for primes up to 1 million (Macbook Air M1 with arm64 binaries for Julia/R).

I had to give it a shot for comparison's sake. A basic 1:1 translation in Julia was 13.43 seconds (7x faster), and following the same conceptual algorithm (check for remainders up to sqrt(x)) but without as many intermediate allocations was 0.017 seconds (over 5,250x faster).

Prime divisibility check algorithim

R - 93.8 seconds

@alecloudenback
alecloudenback / aos_benchmark.jl
Created September 18, 2022 20:56
actuarialopensource / benchmarks alternative approaches
### A Pluto.jl notebook ###
# v0.19.11
using Markdown
using InteractiveUtils
# ╔═╡ f75704b5-fe24-4a1e-acdb-2e4123ec0906
using MortalityTables
# ╔═╡ dd21605c-6012-401e-a0aa-ed8dc989e00d
### A Pluto.jl notebook ###
# v0.19.11
using Markdown
using InteractiveUtils
# ╔═╡ 7121f532-2243-11ed-1a91-55b6e85bb022
using MortalityTables
# ╔═╡ 4dc4b2ec-c12e-4dfe-83b2-f8fda9a63838
@alecloudenback
alecloudenback / annuity_factors.jl
Last active December 9, 2021 03:13
Annuity Factors in Julia
### A Pluto.jl notebook ###
# v0.17.3
using Markdown
using InteractiveUtils
# ╔═╡ c0b5c423-01bc-4321-9531-02f1f014d7f1
using MortalityTables
# ╔═╡ 0a6b50cb-ec54-4e06-a88e-2178f8578c9e
@alecloudenback
alecloudenback / smith-wilson-grading.jl
Created October 25, 2021 02:47
Yields.jl Smith-Wilson Grading example (Solvency II)
using Yields, Plots
yields = [0.02,0.023,0.026,0.029,0.035]
maturities = [1,2,3,7,15]
price = [1,1,1,1,1]
payments = 1
observable_prices = Yields.BulletBondQuotes(yields,maturities,price,payments)
grading_speed = 0.01:0.01:0.25
ultimate_forward = 0.02
curves = [Yields.SmithWilson(observable_prices,ufr=ultimate_forward,α=g) for g in grading_speed ]
times = 0.5:0.5:30
__author__ = """Peter Davidson FIA"""
__email__ = 'peter.davidson@wefox.com'
__version__ = '0.1'
__license__ = 'If you find this helpful, please say thank you'
import pandas as pd, numpy as np
def shear_array(df):
# This function just shears an array
# E.g. x = np.arange(9).reshape(3,3)
# shear_array(x)
@alecloudenback
alecloudenback / apartment-therapy.js
Last active December 15, 2015 08:59
A userscript that allows you to browse Apartment Therapy Tours using the left and right keys.
// ==UserScript==
// @name Apartment Therapy Enhanced Tour Navigation
// @namespace
// @version 0.2
// @description Allows you to browse Apartment Therapy Tours using the left and right key. For Camille.
// @match http://*.apartmenttherapy.com/*
// @match http://www.apartmenttherapy.com/*
// @match http://apartmenttherapy.com/*
// @copyright MIT License
// ==/UserScript==