Skip to content

Instantly share code, notes, and snippets.

View sharavsambuu's full-sized avatar
🐌

sharavsambuu sharavsambuu

🐌
View GitHub Profile
@sharavsambuu
sharavsambuu / OrderFlow.ipynb
Created November 27, 2022 04:14 — forked from sebjai/OrderFlow.ipynb
Optimal trading with order-flow and short-term alpha
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def cpcv_generator(t_span, n, k, verbose=True):
# split data into N groups, with N << T
# this will assign each index position to a group position
group_num = np.arange(t_span) // (t_span // n)
group_num[group_num == n] = n-1
# generate the combinations
test_groups = np.array(list(itt.combinations(np.arange(n), k))).reshape(-1, k)
C_nk = len(test_groups)
n_paths = C_nk * k // n
@sharavsambuu
sharavsambuu / binance-liquidation-calculator.py
Created November 26, 2021 17:32 — forked from highfestiva/binance-liquidation-calculator.py
CLI Binance liquidation calculation formula
#!/usr/bin/env python3
'''2021-03-26: Reverse-engineer by searching for the following terms in features*.js:
- bracketMaintenanceMarginRate
- cumFastMaintenanceAmount
- bracketNotionalFloor
- bracketNotionalCap'''
# (max) position, maintenance margin, maintenance amount
maint_lookup_table = [
# Store the short term moving average in a new column 'window_ST'
prices.loc[:, 'window_ST'] = prices['close'].rolling(
context.short_term_window).mean()
# Store the long term moving average in a new column 'window_LT'
prices.loc[:, 'window_LT'] = prices['close'].rolling(
context.long_term_window).mean()
# Get the latest signal, 1 for golden cross, -1 for death cross
prices.loc[:, 'signal'] = np.where(
@sharavsambuu
sharavsambuu / data.csv
Created December 27, 2020 06:56 — forked from jxm262/data.csv
TT VWAP in Python
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Date Open High Low Close Volume
2020-05-06 18:15:00-04:00 2832 2838.5 2832 2838 3750
2020-05-06 18:30:00-04:00 2838 2838.5 2826 2827.75 6864
2020-05-06 18:45:00-04:00 2827.75 2830.5 2827 2829.5 2937
2020-05-06 19:00:00-04:00 2829.5 2830.5 2823 2826.5 4619
2020-05-06 19:15:00-04:00 2826.75 2829.5 2825.25 2827.75 3610
2020-05-06 19:30:00-04:00 2827.75 2829.5 2825.5 2826.75 2460
2020-05-06 19:45:00-04:00 2826.75 2830.75 2826.25 2830.5 2531
2020-05-06 20:00:00-04:00 2830.5 2833.5 2830.25 2833.5 2361
@sharavsambuu
sharavsambuu / listen_pg.py
Created June 26, 2020 09:33 — forked from dtheodor/listen_pg.py
Listen for pg_notify with Psycopg2
import select
import datetime
import psycopg2
import psycopg2.extensions
conn = psycopg2.connect(database="postgres", user="vagrant")
#conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
curs = conn.cursor()
@sharavsambuu
sharavsambuu / listen_sqla.py
Created June 26, 2020 09:23 — forked from dtheodor/listen_sqla.py
Listen for pg_notify with SQL Alchemy + Psycopg2
import select
import datetime
import psycopg2
import psycopg2.extensions
from sqlalchemy import create_engine, text
engine = create_engine("postgresql+psycopg2://vagrant@/postgres")
@sharavsambuu
sharavsambuu / triplet.py
Created December 23, 2019 11:49 — forked from dkohlsdorf/triplet.py
Triplet Loss Experiments For Audio Data with Tensorflow 2.0
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow.keras.layers as layers
import tensorflow.keras.losses as loss
import tensorflow_datasets.public_api as tfds
from sys import argv
from random import Random
from os import walk
@sharavsambuu
sharavsambuu / audio_lstm_keras.ipynb
Created June 30, 2019 21:55 — forked from naotokui/audio_lstm_keras.ipynb
Audio generation with LSTM in keras
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sharavsambuu
sharavsambuu / textured_tri.py
Created December 29, 2018 23:16 — forked from binarycrusader/textured_tri.py
pysdl2 pyopengl "modern" opengl textured triangle example
#!/usr/bin/python2.7
"""Quick hack of 'modern' OpenGL example using pysdl2 and pyopengl
that shows a textured triangle; assumes there is a 'hazard.png' image
file in working directory.
Based on:
pysdl2 OpenGL example
http://www.tomdalling.com/blog/modern-opengl/02-textures/
http://www.arcsynthesis.org/gltut/Basics/Tut02%20Vertex%20Attributes.html