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
| 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) | |
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
| 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) |
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
| 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 |
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
| 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) |
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
| 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)) |
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
| 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) |
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
| 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) |
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
| 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) |
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
| 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) |
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
| 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)) |