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 optimize(y,max_vi,market_vols,tte,s,weights): | |
y = y[market_vols>0] | |
vols = market_vols[market_vols>0] | |
w = weights[market_vols>0] | |
n = len(y) | |
R = np.concatenate([np.ones(n), np.sqrt(y**2+1), y]).reshape(3,n).T | |
W = np.diag(w) | |
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 numpy as np | |
import sympy as sy | |
from sympy.statistics import Normal as syNormal | |
sy.init_printing() | |
#spot, strike, vol, days till expiry, interest rate, call or put (1,-1) | |
S, K, vol, dte, r,cp = sy.symbols('S,K,vol,dte,r,cp') | |
T = dte / 260. | |
N = syNormal(0.0, 1.0) |
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
from cvxopt import lapack, solvers, matrix, mul | |
from cvxopt.modeling import op, variable, max, sum | |
#def const_spline(n=12): | |
# """ Adapted from example on CVXOPT site -- Changing as little as possible """ | |
#t = matrix(v.index.values[::4]) | |
#y = matrix(v.values[::4]) | |
t, y = data['t'], data['y'] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 seaborn | |
import pandas as pd | |
import numpy as np | |
import matplotlib.patches as mpatches | |
#create random trade pnls | |
n = 5000 | |
sigma = .1 | |
pnl1 = pd.DataFrame(np.random.randn(n,15)) * sigma |
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 seaborn | |
import pandas as pd | |
import numpy as np | |
import matplotlib.patches as mpatches | |
#create random trade pnls | |
n = 5000 | |
sigma = .1 | |
pnl1 = pd.DataFrame(np.random.randn(n,15)) * sigma |
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 numpy as np | |
import numpy.random as rnd | |
from cvxopt import matrix | |
from cvxopt import blas | |
from cvxopt import solvers | |
from cvxopt.modeling import op | |
class IndexReplication(object): | |
def __init__(self): | |
self.G = None # number of groups undergoes mutation |
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 pandas as pd | |
from scipy import stats, linalg | |
def partial_corr(C): | |
""" | |
Returns the sample linear partial correlation coefficients between pairs of variables in C, controlling | |
for the remaining variables in C. | |
Parameters |
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 fit_ab_kf(single_cumulative_returns,dex_cumulative_returns): | |
n_steps = len(dex_cumulative_returns) | |
A = np.matrix([[1,0],[0,1]]) | |
# Transition matrix is dependent on previous B0/B1 with no inherent cross dependency | |
C = map(lambda x: np.matrix(np.append(1,x[0])),np.reshape(dex_cumulative_returns,(n_steps,1,1))) | |
# Observation matrix is tensor of [1,x_t] (of length equal to our observations) | |
# Initial hidden state means are 0 for intercept and 1 for slope |
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
#model of the form -- I apologize for mathjax weirndess but too lazy to fix right now | |
#yt = a_tx_t + νt ∼ N(0, σ2 ν) | |
#at = a_t-1 + b_t-1 + 1/2 c_t-1 | |
#bt = b_t-1 + c_t-1 | |
#ct = c_t-1 + ut ~ N(0,..) | |