Skip to content

Instantly share code, notes, and snippets.

View sharavsambuu's full-sized avatar

sharavsambuu sharavsambuu

View GitHub Profile
@sharavsambuu
sharavsambuu / volume_bar_aggregator.py
Created September 22, 2022 09:59
Volume Bar Aggregator script found from internet, there were some interesting discussions on reddit.
#https://pastebin.com/jgr4ZBVK
#https://www.reddit.com/r/algotrading/comments/p4flbp/can_i_make_tick_volume_and_dollar_bars_from_ohlc/
class VolumeBarAggregator():
class NumpyWrapper():
def __init__(self, length):
self.arr = np.array(dtype=float, )
def __init__(self):
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_rt_ws.py
Created February 2, 2022 11:44
Binance-аас 1 минутын чартыг бодит хугацаанд татаж харуулах
#
# Binance-аас 1 минутын чартыг бодит хугацаанд татаж харуулах
#
# sudo apt-get install python3-pyqt5
# virtualenv -p python3 env && source env/bin/activate
# pip install finplot requests websocket scipy
import json
import requests
import websocket
@sharavsambuu
sharavsambuu / tensorflow-on-m1.txt
Created January 23, 2022 18:26
Install tensorflow on Apple M1
brew install hdf5
export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.12.0_4
pip3 install --no-binary=h5py h5py
virtualenv -p python env && source env/bin/activate
pip install h5py
pip install tensorflow-macos
pip install tensorflow-metal
@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 / metatrader5_live.py
Created October 28, 2020 14:22
Template for live algo with MetaTrader5 and Python
# References :
# - https://stackoverflow.com/questions/61776425/logic-for-real-time-algo-trading-expert
import pytz
import pandas as pd
import MetaTrader5 as mt5
import time
from datetime import datetime
from threading import Timer
@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()