Skip to content

Instantly share code, notes, and snippets.

Avatar

Michy mick001

View GitHub Profile
View neuralnetR.R
# Set a seed
set.seed(500)
library(MASS)
data <- Boston
# Check that no data is missing
apply(data,2,function(x) sum(is.na(x)))
# Train-test random splitting for linear model
View solarSystem.py
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
@mick001
mick001 / taylor_series_improved.py
Last active Mar 5, 2022
Revised and improved version of Taylor series with Python and Sympy. You can find the original post at http://firsttimeprogrammer.blogspot.com/2015/03/taylor-series-with-python-and-sympy.html
View taylor_series_improved.py
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
View mice_imp.R
# Using airquality dataset
data <- airquality
data[4:10,3] <- rep(NA,7)
data[1:5,4] <- NA
# Removing categorical variables
data <- airquality[-c(5,6)]
summary(data)
#-------------------------------------------------------------------------------
@mick001
mick001 / Option_pricing_KDE_estimate.py
Last active Feb 7, 2022
Call option pricing using KDE estimate instead of the normality assumption
View Option_pricing_KDE_estimate.py
"""
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
View q-learning.py
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] ])
View copulas_R_3.R
# 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")
View MarkovChains_weather_example.py
# A simple Markov chain model for the weather in Python
import numpy as np
import random as rm
import time
# Let's define the statespace
states = ["Sunny","Cloudy"]
# Possible sequences of events
@mick001
mick001 / magnetic_field.py
Last active Nov 1, 2021
Biot-Savart law: magnetic field of a straight wire, Python simulation. Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/05/biot-savart-law-magnetic-field-of.html
View magnetic_field.py
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)
@mick001
mick001 / poly_reg.R
Last active Oct 22, 2021
Polynomial regression in R. Full article available at: http://datascienceplus.com/fitting-polynomial-regression-r/
View poly_reg.R
# 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)