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
View GitHub Profile
@tschm
tschm / kkt_cla.py
Created October 26, 2026 04:41
A complete Critical Line Algorithm in 39 lines of NumPy, written with the KKT conditions (cvxcla paper, Appendix C, Fig. 5). Run: uv run kkt_cla.py
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "cvxcla==2.7.1",
# "numpy>=2",
# ]
# ///
"""A complete Critical Line Algorithm in 39 lines of NumPy, written with the KKT conditions.
This is the listing of Figure 5 (Appendix C) of the cvxcla software paper, verbatim:
@tschm
tschm / portfolio_130_30.py
Last active October 9, 2026 11:49
130/30 portfolio frontier with the Critical Line Algorithm (cvxcla). Run: uv run portfolio_130_30.py
# /// script
# requires-python = ">=3.11"
# dependencies = ["cvxcla>=2.3.4", "numpy"]
# ///
import time
import numpy as np
from cvxcla import CLA
for n in (50, 500):
@tschm
tschm / minvar_frontier_challenge.py
Created June 7, 2026 18:36
Long-only efficient frontier benchmark challenge — Shrinkage as Preconditioning paper
"""
Long-Only Efficient Frontier Benchmark Challenge
=================================================
"Shrinkage as Preconditioning: Matrix-Free Methods for
Long-Only Portfolio Optimization"
Generate the exact input data from the paper's efficient frontier experiment
(Section 7, Figure 3) and benchmark your solver against the reference timings.
Challenge: compute all 50 frontier portfolios faster than warm-started CG.

{{ 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