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
def f_gradient(params,y,market_vols,tte,q): | |
c,d,abar = params | |
y = y[market_vols>0] | |
vols = market_vols[market_vols>0] | |
n = len(y) | |
Y1 = np.sum(y) | |
Y2 = np.sum(y**2) | |
Y3 = np.sum(np.sqrt(y**2+1)) | |
Y4 = np.sum(y*np.sqrt(y**2+1)) | |
var_t = vols**2*tte |
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
def optimize_weighted(y,max_vi,weights,market_vols,tte,s): | |
# {{{ | |
y = y[market_vols>0] | |
vols = market_vols[market_vols>0] | |
w = weights[market_vols>0] | |
n = len(y) | |
# R ends up n by 3 | |
R = np.concatenate([np.ones(n), np.sqrt(y**2+1), y]).reshape(3,n).T |
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 pandas as pd | |
import numpy as np | |
from bsm_implieds import implied_fut,implied_futs | |
def is_kospi(symbol_list): | |
s = pd.Series(symbol_list) | |
is_call = s.str[2:6]=='4201' | |
is_put = s.str[2:6]=='4301' | |
is_fut = s.str[2:6]=='4101' | |
return np.logical_or(is_call,np.logical_or(is_put,is_fut)) |
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 pandas as pd | |
import numpy as np | |
cimport numpy as np | |
cimport cython | |
from libc.math cimport exp, sqrt, pow, log, erf, abs, M_PI | |
ctypedef np.double_t DTYPE_t | |
@cython.cdivision(True) | |
@cython.boundscheck(False) |
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 bisect | |
def calc_pnl_futs(actions,observations): | |
pnls=[] | |
if observations.last_valid_index() == None: | |
return np.zeros(len(observations)) | |
settle = np.mean(observations[observations.last_valid_index()]) | |
for a,o in zip(actions,observations): | |
if a<0: | |
pnls.append(o[0]-settle) |
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 sklearn.ensemble import RandomForestClassifier | |
from sklearn.metrics import confusion_matrix | |
from sklearn.cross_validation import train_test_split | |
import pandas as pd | |
import numpy as np | |
def training_to_XY(hi,side='buy'): | |
X = pd.DataFrame(hi.implied_size) | |
if side == "buy": | |
X['Through2'] = hi.implied_trd-hi.AskPrice2 |
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 pandas as pd | |
import os,sys | |
from tcp_pcap2h5 import open_pcap | |
def main(pcap1,pcap2): | |
open_pcap(pcap1) | |
open_pcap(pcap2) | |
h5name1 = pcap1+'.h5' |
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 pandas as pd | |
import numpy as np | |
cimport numpy as np | |
cimport cython | |
from bsm_implieds import bs_tv,delta_py | |
ctypedef np.double_t DTYPE_t | |
cdef extern from "math.h": | |
bint isnan(double x) |
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
%%cython | |
import numpy as np | |
import pandas as pd | |
import sys | |
cimport cython | |
cimport numpy as np | |
ctypedef np.double_t DTYPE_t | |
cdef extern from "math.h": | |
bint isnan(double x) |
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 pykalman | |
import numpy as np | |
#model of the form -- I apologize for mathjax weirndess but too lazy to fix right now | |
#yt = β0,t +β1,txt +νt, νt ∼ N(0, σ2 ν) | |
#β0,t+1 = β0,t +ξt, ξt ∼ N(0, σ2 ξ) | |
#β1,t+1 = β1,t +ςt, ςt ∼ N(0, σ2 ς ) |
OlderNewer