Skip to content

Instantly share code, notes, and snippets.

View bestdan's full-sized avatar

Daniel P. Egan bestdan

View GitHub Profile
@bestdan
bestdan / audit_dart_test.sh
Created December 6, 2023 13:28
Easily audit the difference between two dart objects in a failed test
#!/usr/bin/env sh
# # These functions make it easy to look at the output of a dart
# # test with large non-matching objects.
#
# # To use:
# # One and done:
# auditDartTest test/example_test.dart 'this test fails'
#
@bestdan
bestdan / sp500_heatmap.R
Last active July 25, 2022 15:48
A file to create a triangle heatmap of investment performance
#' @title S&P 500 heatmap
#' @author Daniel Egan
#' @description Creates real and nominal triangle heatmaps based on the S&P 500.
#' @details Last update 2012-06-01
### ----
library(quantmod)
library(RColorBrewer)
#Some useful matrix functions
@bestdan
bestdan / medians_vs_logmeans.R
Created February 12, 2021 15:28
Medians vs Log-Means
#' @title Log-means versus Medians
#' @author Daniel Egan
#' @description When data has a power law or extremely skewed distribution,
#' using a log-mean usually results in more stable and useful central estimates
#' compared to a mean or a median.
#' https://towardsdatascience.com/on-average-youre-using-the-wrong-average-geometric-harmonic-means-in-data-analysis-2a703e21ea0
library(dplyr)
library(tidyr)
library(ggplot2)
@bestdan
bestdan / plotPolarDims.R
Created May 21, 2020 11:54
Plotting a polar radar chart in R
library(ggplot2)
library(tidyr)
library(dplyr)
# Normalize
data(mtcars)
mtcars_norm <- as.data.frame(apply(mtcars, 2, scale))
# Make long
@bestdan
bestdan / inflated_code.R
Last active April 18, 2019 14:44
Simple examples of lines of code
# Version 1: LOC incentive --> inflated code
add_up = function(inputs){
total = inputs[1]
for i in 2:length(inputs){
total = total + inputs[i]
}
return(total)
}
@bestdan
bestdan / customer_service_bot.py
Created June 23, 2018 02:47
Customer Service bot
def cs_service_bot():
welcome_message = """Hello! Welcome to the DNS Cable Company's Service Portal. Are you a new or existing customer?
\n[1] New Customer
\n[2] Existing Customer
\n"""
response = input(welcome_message)
if response == "1":
new_customer()
@bestdan
bestdan / keybase.md
Created November 7, 2017 13:39
keybase.md

Keybase proof

I hereby claim:

  • I am bestdan on github.
  • I am dpegan271 (https://keybase.io/dpegan271) on keybase.
  • I have a public key ASBCTT8RIBBl4GrD_mXa50Qkb8gxy2XmNULJld4SBNfB2wo

To claim this, I am signing this object:

rm(list=ls())
library(quantmod)
library(lubridate)
library(PerformanceAnalytics)
#' Required 'drawdown' size
#' Default: -6% return
drawdownHurdle<- -0.06
# Grab data -----------------------------------------------------------------------------------
@bestdan
bestdan / effFrontier_v1.R
Last active December 11, 2015 21:58
efficientFrontier_v1.R
effFrontier = function (data, nports = 20, shorts=T,wmin=0, wmax=1)
{
rcov<-cov(data)
averet<-colMeans(data)
mxret = max((colMeans(data)))
mnret = 0#-mxret Long only...
n.assets = ncol(data)
reshigh = rep(wmax,n.assets)
if( shorts )
{