Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/693eaf5a-1494-8007-b1e3-00abefb11523
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== - Normalize date: use days since start scaled to [0,1] or use day-of-year normalized by 365. That stabilizes fit. === * Log transform: consider predicting log price if heteroskedasticity (variance grows with price). * Ensemble: average predictions from multiple tetrahedral variants (different lags, different h definitions). * Feature augment: include volatility, moving averages, and seasonality (sine/cosine of day-of-year) as additional inputs to the final linear blend with geometric outputs. * Stability: use clipped predictions to avoid unrealistic jumps (e.g., limit daily predicted change to Β±X%). * Interpretability: keep parameter count low unless you have lots of data. === <syntaxhighlight lang="python"># Inputs: price_series (p[0..T-1]), date_series (numeric d[0..T-1], or day-of-year D) === === Model: family (2) time-weighted tetrahedral === import numpy as np from scipy.optimize import minimize def tetra_predict(params, p_t, d_t): # params = [k, gamma, delta, beta, mu, nu] k,gamma,delta,beta,mu,nu = params h = k * np.sqrt(d_t'''gamma + p_t'''delta) L = np.sqrt(d_t'''2 + p_t'''2 + h**2) pred = beta '' L '' (p_t'''mu) / ((d_t'''2 + p_t'''2)'''(nu/2)) return pred def loss_on_window(params, p_window, d_window): # predict each next-day in the window (one-step-ahead inside window) or fit to a mapping: preds = [] targets = [] for i in range(len(p_window)-1): p_t = p_window[i] d_t = d_window[i] preds.append(tetra_predict(params, p_t, d_t)) targets.append(p_window[i+1]) preds = np.array(preds); targets = np.array(targets) mse = np.mean((preds-targets)**2) # add small L2 regularization return mse + 1e-4 * np.sum(np.array(params)'''2) === Walk-forward training to evaluate params globally: === def walk_forward_eval(price_series, date_series, window=180): T = len(price_series) errors = [] # we could re-fit params each step (expensive) or fit once on first window # simple approach: fit params on first window, then do rolling predictions p0 = price_series[:window+1]; d0 = date_series[:window+1] # initial guess init = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) bounds = [(0,10),(0.1,3),(0.1,3),(0,10),(0,3),(0,3)] res = minimize(lambda x: loss_on_window(x, p0, d0), init, bounds=bounds) params = res.x # predict forward one-by-one with periodic re-fit (e.g., refit every 30 days) preds = [] for t in range(window, T-1): p_t = price_series[t] d_t = date_series[t] pred = tetra_predict(params, p_t, d_t) preds.append(pred) # optional periodic re-fit if (t - window) % 30 == 0 and t+1 < T: start = max(0, t - window + 1) res = minimize(lambda x: loss_on_window(x, price_series[start:t+1], date_series[start:t+1]), params, bounds=bounds) params = res.x targets = price_series[window+1:T] preds = np.array(preds) rmse = np.sqrt(np.mean((preds - targets)'''2)) mape = np.mean(np.abs((preds-targets)/targets)) * 100 return {'rmse': rmse, 'mape': mape, 'preds': preds, 'targets': targets, 'params': params} </syntaxhighlight>
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)