Skip to content

Instantly share code, notes, and snippets.

View solalatus's full-sized avatar

Levente Szabados solalatus

View GitHub Profile
@solalatus
solalatus / finetune.py
Created January 6, 2023 12:17
NHiTS model loading and finetuning
#loading model
loaded_model = NHiTSModel.load_from_checkpoint("old_checkpoint","/content/", best=True)
#defining new parameters
MODEL_NAME = "finetune_only"
from torch.optim import RAdam
OPTIMIZER_CLS = RAdam
BASE_LR = 0.00001
EPOCHS = 25
import pandas as pd
import numpy as np
class DiffNormalizer():
def __init__(self, diff_len=1):
self.diff_len = diff_len
self.fitted = False
self.first_values = None
from orderbook import OrderBook
class ElectraOrderBook(OrderBook):
def get_executed_trades(self):
trades_list=[]
#...
# do some magic with self.idontknowwhat variables, put them into the trades_list...
#...
return trades_list
from orderbook import OrderBook
contract_ids = [111,2222,3333,4444]#df...contractId.unique()
orderbooks={}
for contract_id in contract_ids:
orderbooks[contract_id]=OrderBook()
Fltered by area and by contractid.
Unsorted is sorted only by created_at, "sorted" is sorted by revisionNo.
Unsorted: Sorted:
469 469
470 470
471 471
472 472
473 473
import pandas as pd
from sqlalchemy import create_engine
...
engine = create_engine('postgresql://'+user+':'+password+'@'+host+':'+port+'/'+dbname,echo=False)
df_orderbook = pd.read_sql_query('select * from "public_orderbook"',con=engine)
my_dict={"key1":13,"key2":14}
assert type(my_dict) == type({})
print(my_dict.keys())
print(my_dict.values())
print(my_dict.items())
for i in my_dict.items():
print(i)
my_dict={"key1":(1,2,13141), "key2":(1,2,4354365462)}
for k,v in my_dict.items():
tmp = my_dict[k]
tmp = (tmp[0],tmp[1],"owerwritten")
my_dict[k]=tmp
print(my_dict)
assert my_dict["key1"]==my_dict["key2"]
# -*- coding: utf-8 -*-
import threading
import time
#import queue
#import logging
from unittest import TestCase
from HFTOrderbook.lob import LimitOrderBook, Order
import _thread
import ...whatever the orderbook needs to be..
def multi_order_sumit(thread_num):
print("This is thread",thread_num)
LOB = instance of an orderbook please ()
for i in range(1000):
result = LOB.submit_order( some test cases with incermentally groving price or such...) #or whatever it is callled
return whatever we ecpect result to be