Skip to content

Instantly share code, notes, and snippets.

View carloocchiena's full-sized avatar

Carlo Occhiena carloocchiena

View GitHub Profile
# Augmented Dickey-Fuller Test (ADF)
from statsmodels.tsa.stattools import adfuller
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
"""
Se p-value < 0.05 possiamo rifiutare l’ipotesi nulla e concludere che la serie è stazionaria.
Se p-value > 0.05, la serie non è stazionaria e necessita di trasformazioni.
"""
import matplotlib.dates as mdates
# Create a heatmap
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='Prezzo')
# 2. Plot della heatmap
# Boxplot by hour of day
plt.figure(figsize=(12, 5))
sns.boxplot(data=df, x='Hour', y='Prezzo')
plt.title('Hourly Distribution of PUN Prices')
plt.xlabel('Hour of Day')
plt.ylabel('€/MWh')
plt.grid(True)
plt.tight_layout()
plt.show()
# --- 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_PUN.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 = []