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 is_psd(A): | |
if np.array_equal(A, A.T): | |
try: | |
np.linalg.cholesky(A) | |
return True | |
except np.linalg.LinAlgError: | |
return False | |
else: | |
return 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
#Correlation | |
import plotly | |
import plotly.subplots | |
corr_combos = ['corr_sym1=atvi_sym2=dash', | |
'corr_sym1=dash_sym2=dis', 'corr_sym1=dash_sym2=nvda', | |
'corr_sym1=dash_sym2=wmt'] | |
# Construct a 2 x 1 Plotly figure | |
fig = plotly.subplots.make_subplots(rows=len(corr_combos), cols=1) | |
# price Line |
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 getEMA(df,M,K,col,out): | |
alpha=2./(1.+M) | |
df_a = df.select(['sym', | |
'ranked_indx', | |
'time' | |
]).alias('a').withColumnRenamed("ranked_indx", "ranked_indx_a") \ | |
.withColumnRenamed("time", "time_a") | |
df_b = df.select(['sym', | |
'ranked_indx', | |
'time', |
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 getSMABands(df,M,K): | |
df_a = df.select(['sym', | |
'ranked_indx', | |
'time']).alias('a').withColumnRenamed("ranked_indx", "ranked_indx_a") \ | |
.withColumnRenamed("time", "time_a") | |
df_b = df.select(['sym', | |
'ranked_indx', | |
'time', | |
'close', |
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 itertools | |
def getCorr(df,M,sym1,sym2): | |
stg=df.filter(sf.col(sym1).isNotNull()&sf.col(sym2).isNotNull()) | |
windowTime = Window.orderBy("time") | |
stg=stg.withColumn("ranked_indx",sf.row_number().over(windowTime)) | |
updatedWindowIndx = Window.orderBy("ranked_indx").rangeBetween(-M+1,0) | |
stg = stg.withColumn('corr_sym1={}_sym2={}'.format(sym1,sym2), | |
sf.corr(sf.col(sym2),sf.col(sym1)).over(updatedWindowIndx) |
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 boto3 | |
import pyspark as pyspark | |
from pyspark import SparkContext | |
from pyspark.sql.session import SparkSession | |
import os | |
#you might need to set these env vars | |
os.environ['PYSPARK_DRIVER_PYTHON']='jupyter' | |
os.environ['PYSPARK_DRIVER_PYTHON_OPTS']='notebook' | |
os.environ['PYSPARK_PYTHON']='python' | |
#create a user |
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 boto3 | |
client = boto3.client('ecs') | |
cluster_name = '' | |
task_definition = '' | |
def lambda_handler(event, context): | |
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 json | |
import base64 | |
import copy | |
def lambda_handler(event, context): | |
output = [] | |
for record in event['records']: | |
# Decode from base64 (Firehose records are base64 encoded) | |
payload = base64.b64decode(record['data']) |
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 sqlite3 as sq | |
import pandas as pd | |
sql_data = "3d0d7e5fb2ce288813306e4d4636395e047a3d28" #- Creates DB names SQLite | |
conn = sq.connect(sql_data) | |
cur = conn.cursor() | |
qry = """select datetime(message.date/1000000000 + strftime('%s','2001-01-01') ,'unixepoch','localtime') as date, | |
case when is_from_me=0 then 'Friend' else 'Me' end as name, text |
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
@tf.function | |
def MSE(ytrue,ypred): | |
loss = tf.reduce_mean(tf.square(ypred - ytrue)) | |
return loss | |
class ARMODEL(tf.keras.Model): | |
def __init__(self,shape): | |
super(ARMODEL,self).__init__(name='armodel') | |
NewerOlder