Skip to content

Instantly share code, notes, and snippets.

@raposatech
raposatech / finance_helper_funcs.py
Created February 18, 2022 16:01
Helper functions to calculate backtest returns and strategy stats.
# A few helper functions
def calcReturns(df):
# Helper function to avoid repeating too much code
df['returns'] = df['Close'] / df['Close'].shift(1)
df['log_returns'] = np.log(df['returns'])
df['strat_returns'] = df['position'].shift(1) * df['returns']
df['strat_log_returns'] = df['position'].shift(1) * \
df['log_returns']
df['cum_returns'] = np.exp(df['log_returns'].cumsum()) - 1
df['strat_cum_returns'] = np.exp(
@eatonphil
eatonphil / cl-docker.asd
Last active December 21, 2022 19:49
cl-docker
(defsystem :cl-docker
:depends-on (:cl-ppcre)
:serial t
:components ((:file "package")
(:file "docker")))
@tartakynov
tartakynov / fourex.py
Last active July 15, 2024 16:24
Fourier Extrapolation in Python
import numpy as np
import pylab as pl
from numpy import fft
def fourierExtrapolation(x, n_predict):
n = x.size
n_harm = 10 # number of harmonics in model
t = np.arange(0, n)
p = np.polyfit(t, x, 1) # find linear trend in x
x_notrend = x - p[0] * t # detrended x
@jteneycke
jteneycke / gist:7947353
Last active June 20, 2024 12:29
How to install and configure Common Lisp for Emacs. (SBCL + Slime + Emacs24)

In your shell

sudo apt-get install sbcl
curl -O http://beta.quicklisp.org/quicklisp.lisp
sbcl --load quicklisp.lisp

Inside the context of sbcl

@tshatrov
tshatrov / lisp-setup.md
Created September 30, 2013 15:04
Setting up Common Lisp on Windows 7

1. Install a Common Lisp implementation, or several of them

2. Install Emacs. Official GNU Emacs Windows binaries should work: http://ftp.gnu.org/gnu/emacs/windows/

3. Create a directory where you will store your Lisp projects (you could use Quicklisp's default one but screw that, "c:/lisp" is better than "c:/users/<username>/quicklisp/local-projects")