This file contains 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 | |
from bigfloat import * | |
import matplotlib.pyplot as plt | |
from visual import * | |
# A class to handle the time ranges | |
class timeHoursSeconds(object): | |
def __init__(self,s,h,d,y): | |
self.s = s | |
self.h = h |
This file contains 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 numpy as np | |
# R matrix | |
R = np.matrix([ [-1,-1,-1,-1,0,-1], | |
[-1,-1,-1,0,-1,100], | |
[-1,-1,-1,0,-1,-1], | |
[-1,0,0,-1,0,-1], | |
[-1,0,0,-1,-1,100], | |
[-1,0,-1,-1,0,100] ]) |
This file contains 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 sympy as sy | |
import numpy as np | |
from sympy.functions import sin, cos, ln | |
import matplotlib.pyplot as plt | |
plt.style.use("ggplot") | |
# Factorial function | |
def factorial(n): | |
if n <= 0: | |
return 1 |
This file contains 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
""" | |
MONTE CARLO PLAIN VANILLA OPTION PRICING | |
This script is used to estimate the price of a plain vanilla | |
option using the Monte Carlo method and assuming that returns | |
can be simulated using an estimated probability density (KDE estimate) | |
Call option quotations are available at: | |
http://www.google.com/finance/option_chain?q=NASDAQ%3AAAPL&ei=fNHBVaicDsbtsAHa7K-QDQ |
This file contains 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
# Pseudo observations | |
p_obs <- pobs(mat) | |
plot(p_obs[,1],p_obs[,2],main="Pseudo/simulated observations: BLUE/RED",xlab="u",ylab="v",col="blue") | |
# Simulate data | |
set.seed(100) | |
u1 = rCopula(500,normalCopula(coef(fit.cop),dim=2)) | |
points(u1[,1],u1[,2],col="red") |
This file contains 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
from mpl_toolkits.mplot3d import axes3d | |
import matplotlib.pyplot as plt | |
import numpy as np | |
x = np.linspace(-4,4,10) | |
y = np.linspace(-4,4,10) | |
z = np.linspace(-4,4,10) | |
x,y,z = np.meshgrid(x,y,z) |
This file contains 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
# Example 1 | |
p <- 0.5 | |
q <- seq(0,100,1) | |
y <- p*q | |
plot(q,y,type='l',col='red',main='Linear relationship') | |
# Example 2 | |
y <- 450 + p*(q-10)^3 | |
plot(q,y,type='l',col='navy',main='Nonlinear relationship',lwd=3) |
This file contains 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 numpy as np | |
import matplotlib.pyplot as plt | |
plt.style.use('ggplot') | |
l = 0.0229 #Inductance (H) | |
r = 3.34 #Resistance (Ohm) | |
v = 5 #Voltage (V) DC | |
i = v/r #Peak current (A) | |
tau = l/r #Tau time constant |
This file contains 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 | |
from visual import * | |
# Data in units according to the International System of Units | |
G = 6.67 * math.pow(10,-11) | |
# Mass of the Earth | |
ME = 5.973 * math.pow(10,24) | |
# Mass of the Moon | |
MM = 7.347 * math.pow(10,22) |
This file contains 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 numpy as np | |
from matplotlib import pyplot as plt | |
# Differential equation | |
# diff = y'= y/x (or say x+y) | |
def diff(x,y): | |
return y/x # try also x+y | |
x = np.linspace(-10,10,50) | |
y = np.linspace(-10,10,50) |