Skip to content

Instantly share code, notes, and snippets.

@fmarthoz
fmarthoz / gist:33227575768b63a82840b1617050d467
Last active August 3, 2021 08:07
Implementation of the Contingent Claim Model
def prob_default(ticker):
""" DEFINING THE FUNCTION WE WANT TO OPTIMISE"""
def fun(x):
va=x[0]
siga=x[1]
d1=(np.log(va/X)+(r+0.5*siga**2)*T)/(siga*np.sqrt(T))
d2=d1-siga*np.sqrt(T)
return [va*norm.cdf(d1)-X*np.exp(-r*T)*norm.cdf(d2)-ve,va*norm.cdf(d1)*siga/ve-sige]
"""DATA SELECTION"""
start_date='2018-01-01'
scaler = StandardScaler()
df=scaler.fit_transform(df)
kmeans_kwargs = {"init": "random","n_init": 20,"max_iter": 1000,"random_state": 1984}
cut_off=0.5
maxvars=3
kmin=2
kmax=8
cols=list(df.columns)
@fmarthoz
fmarthoz / Simple k-means
Last active July 7, 2021 05:00
For a Medium article
from sklearn.preprocessing import StandardScaler
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import random
import seaborn as sns
from sklearn.preprocessing import StandardScaler
# We define a function returning the centroid of a set of points and the distance between two points