Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1a) | |
| ######################################### | |
| # Functions for constructing the spline # | |
| ######################################### | |
| # Cubic | |
| f = function(x){ | |
| c(1,x,x^2,x^3) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, |
OlderNewer