Skip to content

Instantly share code, notes, and snippets.

View carloocchiena's full-sized avatar

Carlo Occhiena carloocchiena

View GitHub Profile
from statsmodels.tsa.statespace.sarimax import SARIMAX
from sklearn.metrics import mean_squared_error
# Drop NaNs from differencing (if any)
daily_data = df['Value'].resample('D').mean()
daily_data = daily_data.asfreq('D') # daily average
daily_data = daily_data.fillna(method='ffill') # safety fill if any missing
subset = daily_data['2024-01-01':'2024-03-31']
import matplotlib.dates as mdates
# 1. Riorganizza i dati: pivot con giorni sulle righe, ore sulle colonne
heatmap_data = df.copy()
heatmap_data['Date'] = heatmap_data.index.date
heatmap_data['Hour'] = heatmap_data.index.hour
pivot = heatmap_data.pivot_table(index='Date', columns='Hour', values='Value')
# 2. Plot della heatmap
# Add useful time-based features
df['Hour'] = df.index.hour
df['Day'] = df.index.day
df['Weekday'] = df.index.weekday # Monday=0, Sunday=6
df['Month'] = df.index.month
df['Date'] = df.index.date # useful for grouping by day
plt.figure(figsize=(10, 4))
sns.histplot(df['Value'], bins=50, kde=True)
plt.title('Distribution of values')
# --- 1. Libraries ---
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import timedelta
# --- 2. Load the Excel file ---
# Replace with your actual filename
df = pd.read_excel('20240101_20241231_sample.xlsx')
"""
I'm starting to like the Variance-Gamma model quite a bit.
Here is a quick and dirty Octave (Matlab) code for generating the IV skew given VG parameters
I took the parameters from the Madan, Carr and Chang paper.
Instead of evaluating a double integral I use the mixing formula, which results in a single integral.
From Linkedin profile of Frido Rolloos
""
import numpy as np
@carloocchiena
carloocchiena / aziona_SQL_tutorial.sql
Created December 28, 2023 17:37
SQL code for tutorial for Aziona blog
-- create our table
CREATE TABLE Videogiochi (
ID INT PRIMARY KEY AUTO_INCREMENT,
Nome VARCHAR(100) NOT NULL,
AnnoUscita INT NOT NULL,
Rating INT CHECK (Rating >= 1 AND Rating <= 5)
);
-- insert the data
INSERT INTO Videogiochi (Nome, AnnoUscita, Rating) VALUES
@carloocchiena
carloocchiena / zencastr backup script
Last active February 16, 2023 18:10
Put this script in console to download a corrupted track from the browser (Google Chrome)
app.location.recordings.each(function (recording) {
recording.tracks.each(function (track) {
track.downloadFromLocal(window.location.href);
})
})
# copy and paste the script on a Jupyter Notebook to have the
# table printed on screen
import numpy as np
import pandas as pd
from scipy.integrate import quad
def normal_probability_density(x):
constant = 1.0 / np.sqrt(2 * np.pi)
return(constant * np.exp((-x**2) / 2))
# TSP with heuristic dynamic programming
# Solution is based on "always picking the shortest route available" on the matrix
from itertools import permutations
def travel_salesman_problem(graph: list, path_sum: int = 0) -> int:
vertex = []
min_path = []