Skip to content

Instantly share code, notes, and snippets.

View roarkemc's full-sized avatar
🔮

Roarke McNaught roarkemc

🔮
View GitHub Profile
@jbwhit
jbwhit / example-ruff-formatting.ipynb
Last active October 23, 2025 03:44
Steps to use `ruff` in JupyterLab with the `jupyterlab_code_formatter` plugin.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@roarkemc
roarkemc / tsplot.py
Last active March 28, 2022 20:54
tsplot function
import matplotlib.pyplot as plt
from scipy import stats as scs
import statsmodels.tsa.api as smt
import statsmodels.api as sm
def tsplot(y, lags=None, figsize=(10, 8), style='bmh'):
if not isinstance(y, pd.Series):
y = pd.Series(y)
with plt.style.context(style):
@josef-pkt
josef-pkt / ex_kde_asymmetric.ipynb
Created March 12, 2021 18:58
kernel density and cdf estimation using asymmetric kernels for interval and positive data (version at merge)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@roarkemc
roarkemc / to_xarray_fast.py
Last active August 17, 2023 22:10
Fast "to_xarray" function for large pandas DataFrames (e.g., 10k rows x 1k columns).
import numpy as np
import pandas as pd
import xarray as xr
def to_xarray(data: pd.DataFrame) -> xr.Dataset:
r"""Quickly transforms a pandas DataFrame into a xarray Dataset.
For large dataframes, much faster than the existing built-in
"to_xarray" method.
@roarkemc
roarkemc / FRFGarch.jl
Created December 13, 2019 14:59
Julia package from Danielsson's Financial Risk Forecasting book implements GARCH(1,1), t-GARCH(1,1) and APARCH(1,1)
add # Julia GARCH(1,1), t-GARCH(1,1) and APARCH(1,1) estimation/simulation package
# Copyright Jon Danielsson and Jia Rong Fan, June 2018
# Based on Jon Danielsson's work in Financial Risk Forecasting (FRF)
# Estimation/simulation of GARCH(1,1), t-GARCH(1,1) and APARCH(1,1) in Julia.
module FRFGarch
using Optim, Distributions
export GARCHfit, GARCHsim
def ef(stocks, log_ret, m3, m4):
np.random.seed(10)
trials = 10000
all_weights = np.zeros((trials, len(stocks.columns)))
ret_arr = np.zeros(trials)
vol_arr = np.zeros(trials)
coskew_arr = np.zeros(trials)
cokurt_arr = np.zeros(trials)
def cokurt(df):
# Number of stocks
num = len(df.columns)
#First Tensor Product Matrix
mtx1 = np.zeros(shape = (len(df), num**2))
#Second Tensor Product Matrix
mtx2 = np.zeros(shape = (len(df), num**3))
def coskew(df):
# Number of stocks
num = len(df.columns)
# Two dimionsal matrix for tensor product
mtx = np.zeros(shape = (len(df), num**2))
v = df.values
means = v.mean(0,keepdims=True)
@josef-pkt
josef-pkt / ex_gam_mpg_basic.ipynb
Created January 30, 2019 00:50
Basic GAM example with formula after merge
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@roarkemc
roarkemc / bobp-python.md
Created January 24, 2019 19:03 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens