Skip to content

Instantly share code, notes, and snippets.

View roarkemc's full-sized avatar
🔮

Roarke McNaught roarkemc

🔮
View GitHub Profile
@roarkemc
roarkemc / confidence-level-vs-interval.md
Last active October 26, 2024 05:44
Difference between confidence levels, intervals, bands, and regions, and credible and prediction intervals.

Within VaR modeling for quantitative market risk management, what is the difference between confidence levels and intervals? Also, compare to other similar types of statistical measures such as credible and prediction intervals, and confidence bands and regions.

Key Terms

  • Confidence Level: probability that the interval contains the true parameter (e.g., 95% means 95% confidence).
  • Confidence Interval: range of values derived from the sample data that is expected to contain the true parameter with a specified confidence level.
  • Credible Interval: used in Bayesian statistics, reflecting probability distributions rather than frequentist confidence.
  • Prediction Interval: estimates the range for future observations based on existing data.
  • Confidence Band: type of confidence interval for entire functions or curves rather than single estimates.
  • Confidence Region: generalization of confidence intervals for multiple parameters, indicating a range in multivar
@roarkemc
roarkemc / pyink-vscode-extension.md
Last active August 23, 2024 00:25
VS Code extension workaround for Pyink (fork of Black w/ a few different formatting behaviors)?

Is there a VS Code extension for Pyink?

No, but with a bit of a workaround, you can use the Black Formatter extension.

After installing Pyink and the extension, you can set these in VSCode's settings.json:

{
    "[python]": {
 "editor.defaultFormatter": "ms-python.black-formatter"
@roarkemc
roarkemc / plotly_timeseries.py
Last active August 26, 2023 15:43
Time series summary using plotly subplots
import numpy as np
import numpy.typing as npt
import pandas as pd
import plotly.graph_objects as go
import plotly.figure_factory as ff
import statsmodels.api as sm
import statsmodels.tsa.api as smt
from plotly.subplots import make_subplots
@roarkemc
roarkemc / sync-all-git-repos.ps1
Last active July 13, 2023 06:17
Powershell script to update all local Git repos on Windows
Get-ChildItem -Recurse -Depth 2 -Force |
Where-Object { $_.Mode -match "h" -and $_.FullName -like "*\.git" } |
ForEach-Object {
cd $_.FullName
cd ../
git pull --rebase
cd ../
}
@roarkemc
roarkemc / fix-ipython-fail-open-sqlite-hist.sh
Last active August 4, 2022 20:10
Quick fix for ipython startup error "Failed to open SQLite history"
ipython --ipython-dir=/tmp
@roarkemc
roarkemc / pip_install_trusted_host_pypi.sh
Created July 27, 2022 22:16
Python pip install package example w/ trusted host flags for pypi.org, pypi.python.org, and files.pythonhosted.org
pip install --upgrade --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org numpy
@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):
@roarkemc
roarkemc / var_cf.py
Last active March 28, 2023 10:21
Value-at-Risk (VaR) using the Cornish-Fisher approximation.
def var_cf(
hpr: pd.Series | pd.DataFrame, var_p: float = 0.01
) -> float | pd.Series:
"""Estimate Value-at-Risk (VaR) using the Cornish-Fisher approximation.
Parameters
----------
hpr : Series or DataFrame
Holding period returns (HPR), noncumulative.
var_p : float, default 0.01
@roarkemc
roarkemc / cvar_cf.py
Last active March 28, 2023 10:12
Conditional Value-at-Risk (CVaR) using the Cornish-Fisher approximation.
def cvar_cf(
hpr: pd.Series | pd.DataFrame, var_p: float = 0.01
) -> float | pd.Series:
"""Estimate Conditional Value-at-Risk (CVaR) using the Cornish-Fisher approximation.
Parameters
----------
hpr : Series or DataFrame
Holding period returns (HPR), noncumulative.
var_p : float, default 0.01
@roarkemc
roarkemc / forecasting_metrics.py
Created December 15, 2020 18:00 — forked from bshishov/forecasting_metrics.py
Python Numpy functions for most common forecasting metrics
import numpy as np
EPSILON = 1e-10
def _error(actual: np.ndarray, predicted: np.ndarray):
""" Simple error """
return actual - predicted