Skip to content

Instantly share code, notes, and snippets.

@accessnash
accessnash / wichern11.24.R
Created May 26, 2018 22:25
linear discriminant analysis - wichern
data <- read.table("C:/Users/DASA0/Desktop/Stat 524/wichern data/T11-4.dat", sep="")
data <- as.data.frame(data)
names(data) <- c("X1", "X2", "X3","X4", "X5")
summary(data)
xbar <- colMeans(data)
S <- cov(data)
Distance <- mahalanobis(data, xbar, S)
pairs(~X1+X2+X3+X4,data=data)
@accessnash
accessnash / sumsquarediff.py
Created June 1, 2018 13:11
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. - Project Euler
list = []
for i in range(1, 101):
list.append(i**2)
sumofsq = sum(list)
sumlist = sum(range(1,101))
sqofsum = sumlist**2
diff = sumofsq - sqofsum
print(diff)
@accessnash
accessnash / pythagoreantriplet.py
Created June 1, 2018 18:19
Project Euler Q 9 - There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
def pythagoreantriplet(sum):
for a in range(1, sum):
for b in range(a, sum):
c = sum - a - b
if a**2 + b**2 == c**2:
return a, b, c, a*b*c
@accessnash
accessnash / primesum.py
Created June 2, 2018 17:17
Find the sum of all the primes below n - Problem 10 Euler project
def sum_prime(n):
primes = []
for num in range(2, n):
if all(num%i!=0 for i in range(2,num)):
#print(i, "is prime")
primes.append(num)
return primes, sum(primes)
superherodata <- read.csv("C:/Users/DASA0/Desktop/books & research/superheroes.csv", sep=",")
superherodata <- as.data.frame(superherodata)
colSums(x, na.rm = FALSE, dims = 1)
superherochars <- read.csv("C:/Users/DASA0/Desktop/books & research/supercharstc.csv", sep=",")
slices <- c(sum(superherochars$Gender=="Female", na.rm=TRUE), sum(superherochars$Gender=="Male", na.rm=TRUE), sum(superherochars$Gender=="-", na.rm=TRUE))
lbls <- c("Female", "Male", "No data")
pie(slices, labels = lbls, main="Superheroes by Gender", col = colors)
slices2 <- c(sum(superherochars$Alignment=="good", na.rm=TRUE), sum(superherochars$Alignment=="bad", na.rm=TRUE),sum(superherochars$Alignment=="neutral", na.rm=TRUE), sum(superherochars$Alignment=="-", na.rm=TRUE))
@accessnash
accessnash / callprice.py
Created June 7, 2018 21:30
Call price with figure for both present value and intrinsic value
import math
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
import scipy.stats as sc
# Intrinsic Value of an European Call
K = 800
S = np.linspace(600, 1000, 50)
@accessnash
accessnash / putprice.py
Last active June 7, 2018 22:18
Put price with figure for both present value and intrinsic value
import math
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
import scipy.stats as sc
def BS_Put(St, K, t, T, r, sigma):
d1 = (math.log(St/K) + (r + 0.5*sigma**2)*(T-t))/(sigma*math.sqrt(T-t))
d2 = d1 - sigma*math.sqrt(T-t)
@accessnash
accessnash / calltheta.py
Created June 8, 2018 00:00
Plotting theta of a call option
import math
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
import scipy.stats as sc
def BS_Calltheta(St, K, t, T, r, sigma):
d1 = (math.log(St/K) + (r + 0.5*sigma**2)*(T-t))/(sigma*math.sqrt(T-t))
d2 = d1 - sigma*math.sqrt(T-t)
@accessnash
accessnash / puttheta.py
Created June 8, 2018 00:01
Plotting theta of a put option against stock price
import math
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
import scipy.stats as sc
def BS_Puttheta(St, K, t, T, r, sigma):
d1 = (math.log(St/K) + (r + 0.5*sigma**2)*(T-t))/(sigma*math.sqrt(T-t))
d2 = d1 - sigma*math.sqrt(T-t)
@accessnash
accessnash / greeks.py
Last active June 9, 2018 23:41
plotting Delta, Gamma, Rho, vega
import math
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
import scipy.stats as sc
#import mp_toolkits.mplot3d.axes3d as p3
def BS_Calldelta(St, K, t, T, r, sigma):
d1 = (math.log(St/K) + (r + 0.5*sigma**2)*(T-t))/(sigma*math.sqrt(T-t))