Skip to content

Instantly share code, notes, and snippets.

View dmarx's full-sized avatar

David Marx dmarx

View GitHub Profile
@dmarx
dmarx / math504_hw3.ipynb
Created January 29, 2014 23:48
Math504 HW3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
library(TTR)
GetClosePrices=function(stocks, from=20090206, to=20140206){
# Returns a dataframe whose columns correspond to
# the prices of stocks in the input parameter.
#
# stocks: A character vector of ticker symbols
# from/to: Dates in YYYYMMDD format, from < to.
df = xts()
symbols=c()
# Using the first two stocks, can solve analytically.
colnames(nyse_prices2)[1:2]
# "A" "AA"
mu[1:2]
sigma[1:2,1:2]
v = c(-1,1)
@dmarx
dmarx / Math504_HW9.r
Last active August 29, 2015 13:57
Spline regression
# 1a)
#########################################
# Functions for constructing the spline #
#########################################
# Cubic
f = function(x){
c(1,x,x^2,x^3)
}
@dmarx
dmarx / Numerical DIfferentiation.r
Created April 3, 2014 20:29
Math504 HW11 Prob1
# Problem 2
h_reimann=function(f,a,b,n){
x = seq(a,b, length.out=n)
dx = x[2]-x[1]
sum(f(x)*dx)
}
h_trapezoid = function(f,a,b,n){
x = seq(a,b, length.out=n)
@dmarx
dmarx / edge list preprocessing.r
Created April 3, 2014 21:08
Math504 HW11 problem 3
library(igraph)
library(Matrix)
Remap_Node_IDs = function(edgelist){
# Given an edge list with N nodes, maps the given node ids
# to values in the range 1-N, returns the converted edge list
# and a vector whose indexes give the correspondence
# transformation
flat = sapply(edgelist,c)
raw_ids = unique(flat)
# Problem 3
library(Matrix)
library(igraph)
PowerMethod2 = function(M,w,eps=1e-9){
w = w/norm(w,type='F')
last=0
n=0
while(norm(last-w, type='F')>eps){
@dmarx
dmarx / math504_hw12_prob4.r
Created April 14, 2014 00:21
Develop a basis orthogonal to the separating hyperplane
iris = read.csv('iris.txt', skip=60, header=FALSE)
X = iris[,-5]
Y = iris[,5]
########### Separating Hyperplane Loss Function ###########
Predict_Class=function(beta, X){
# takes a vector of parameters beta and a design matrix X.
# Returns a vector of {-1,1} classifications
David Marx - Math 504 - HW 13
=================================
# Problem 1
a = c(
9.681,0.667,
9.400,2.041,
8.025,9.152,
2.196,0.415,