Skip to content

Instantly share code, notes, and snippets.

@jckantor
jckantor / stock.m
Last active October 15, 2023 17:56
A Matlab class for obtaining quotes from Yahoo Finance.
% STOCK A Matlab class for obtaining quotes from Yahoo Finance.
%
% SYNOPSIS
%
% stock(symbol,speriod,sfreq)
% Creates an object for the current quote and historical prices for
% the stock denoted by SYMBOL.
%
% symbol String or cell array of strings denoting desired stocks.
%
@jckantor
jckantor / NYSE_tradingdays.py
Last active February 9, 2023 13:22
Python dateutil rule sets for NYSE trading days and holiday observances.
from dateutil import rrule
import datetime
# Generate ruleset for holiday observances on the NYSE
def NYSE_holidays(a=datetime.date.today(), b=datetime.date.today()+datetime.timedelta(days=365)):
rs = rrule.rruleset()
# Include all potential holiday observances
rs.rrule(rrule.rrule(rrule.YEARLY, dtstart=a, until=b, bymonth=12, bymonthday=31, byweekday=rrule.FR)) # New Years Day
<link href='http://fonts.googleapis.com/css?family=Fenix' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans:100,300,400,500,700,800,
900,100italic,300italic,400italic,500italic,700italic,800italic,900italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:300,400' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Crimson+Text' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Kameron' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Lato:200' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Lato:400' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro' rel='stylesheet' type='text/css'>
@jckantor
jckantor / molweight.m
Created January 15, 2014 03:41
Calculate the molecular weight of a species given a chemical formula.
function mw = molweight(varargin)
% MOLWEIGHT Computes the molecular weights for a set of chemical species.
%
% SYNTAX
%
% mw = molweight(formula)
% mw = molweight(species)
% mw = molweigth(r)
%
@jckantor
jckantor / standalone.tpbuild
Created April 29, 2014 13:33
Texpad tpbuild script for latex standalone class to produce .png file. Useful for creating tikz figures.
#!/bin/bash
# Texpad build (.tpbuild) for standalone
pdflatex "$TEXPAD_ROOTFILE"
convert -density 300 "$TEXPAD_ROOTFILE_NO_EXT".pdf "$TEXPAD_ROOTFILE_NO_EXT".png
rm "$TEXPAD_ROOTFILE_NO_EXT".aux
rm "$TEXPAD_ROOTFILE_NO_EXT".log
@jckantor
jckantor / sars-cov-2.ipynb
Last active February 27, 2020 01:54
SARS-CoV-2.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jckantor
jckantor / SimpyHistorian.py
Created September 6, 2019 01:59
Simple historian for SImpy simulations
class Historian():
"""A simple historian class for logging simulation data.
Args:
item_id (str): a name for the identifier of the tracked objects
data_callbacks (dict): a dictionary of name:function pairs where name
is a string label for the data element being recorded, and the function
returns the current value for the data element.
"""
import sys, shutil
if 'google.colab' in sys.modules:
!pip install -q pyomo
!wget -N -q "https://ampl.com/dl/open/ipopt/ipopt-linux64.zip"
!unzip -o -q ipopt-linux64
ipopt_executable = '/content/ipopt'
else:
ipopt_executable = shutil.which('ipopt')
if ipopt_executable is None:
raise FileNotFoundError('Could not locate the ipopt executable.')
@jckantor
jckantor / remove-remote-git-directory
Last active May 20, 2019 11:41
Remove remote directory after adding to .gitignore
git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master
@jckantor
jckantor / displaytable.m
Last active January 3, 2016 08:29
Format a matrix as a table with optional row and column labels, with optional export to plain text, latex, html, or csv output.
function str = displaytable(A,rnames,cnames,fmt,tableformat,fname)
% DISPLAYTABLE Convert a matrix to a printable table.
%
% STR = DISPLAYTABLE(A,RNAMES,CNAMES,FMT,TABLEFORMAT,FNAME)
% Formats a matrix as a table with row and column labels. The result is
% a string that will print as a formatted table. Useful labeling and
% annotating computational results.
%
% REQUIRED PARAMETERS