Skip to content

Instantly share code, notes, and snippets.

View tschm's full-sized avatar
🦧
Be sure to wear some flowers in your hair

Thomas Schmelzer tschm

🦧
Be sure to wear some flowers in your hair
  • Stanford & Team Q @ ADIA
  • Palo Alto & Abu Dhabi, United Arab Emirates
  • X @Thomster78
View GitHub Profile

{{ package }} Code of Conduct

Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

import time
import numpy as np
import cvxpy as cp
from mosek.fusion import Model, Domain, Expr, ObjectiveSense
def cvx_explicit(cov_factor, residual_var, F, mu, gamma, Lmax):
n, m = F.shape
@tschm
tschm / f1.py
Created March 9, 2020 10:36
f1 Precision and Recall
def f1(precision, recall):
return 2*(precision*recall)/(precision+recall)
if __name__ == '__main__':
# Matrix for crypto finance
TP = 70 # on how many days did you correctly predict the market goes up?
FP = 10 # on how many days did you predict the market goes up, but it actually went down?
FN = 8 # on how many days did you predict the market goes down, but it actually went up?
TN = 12 # on how many days did you correctly predict the market goes down?
FROM rocker/rstudio:3.6.1
# see https://arrow.apache.org/install/
# rocker/rstudio is based on debian
RUN apt update && \
apt install -y -V apt-transport-https curl gnupg lsb-release apt-utils
RUN echo "deb http://deb.debian.org/debian $(lsb_release --codename --short)-backports main contrib" >> /etc/apt/sources.list.d/backports.list && \
curl --output /usr/share/keyrings/apache-arrow-keyring.gpg https://dl.bintray.com/apache/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-keyring.gpg && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/apache-arrow-keyring.gpg] https://dl.bintray.com/apache/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/ $(lsb_release --codename --short) main" >> /etc/apt/sources.list.d/apache-arrow.list && \
@tschm
tschm / jupyter.py
Created February 7, 2019 08:58
Send production scripts to Jupyter
#!/usr/bin/env python3
import os
import nbformat as nbf
from config.config import logger
from pyutil.parent import Production
from pyutil.sql.interfaces.symbols.strategy import Strategy
from pyutil.sql.session import session
# We create a standard logger with two handlers
# One of them is using io.StringIO for streaming
# Subsequently we add the value() method to the logger, e.g. it will be possible to call
# logger.value() and get the entire history of all messages sent to the logger.
#
# I have never managed to get my head around logging in Python. Any comments are very appreciated.
import logging
import types
@tschm
tschm / client.py
Created July 9, 2018 18:56
Influxdb client
import os
import pandas as pd
from influxdb import DataFrameClient
class Client(DataFrameClient):
def __init__(self, host=None, port=8086, database=None):
host = host or os.environ["INFLUXDB_HOST"]
super().__init__(host, port)
# construct a random SO(3) matrix
import numpy as np
# We construct a random element in SO(3)
def rand_so3():
A = np.random.randn(3,3)
# normalize the first column
A[:,0]=A[:,0]/np.linalg.norm(A[:,0], 2)
# make the 2nd column orthogonal to first column
@tschm
tschm / Makefile
Created September 2, 2016 13:59
Makefile to document a python project
# Makefile
#
ROOT_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SPHINXBUILD = sphinx-build
BUILDDIR = ${ROOT_DIR}/build
SOURCEDIR = ${ROOT_DIR}/source
PROJECT = pylobnek