Skip to content

Instantly share code, notes, and snippets.

View 18182324's full-sized avatar
🎯
Focusing

Milton_FMR 18182324

🎯
Focusing
View GitHub Profile
EasyLanguage Code To TesT The Predictability Of An Event
Vars:
Event(false),
FuturePrice(0),
I(0),
CG(0),
Denom(0);
Arrays:
PredictBin[100](0);
}
variables:
Event( false ),
FuturePrice( 0 ),
j( 0 ),
CG( 0 ),
Denom( 0 ) ;
arrays:
PredictBin[100]( 0 );
@18182324
18182324 / Range Bound Strategy [EasyLanguage Code]
Created March 30, 2020 14:32
Range Bound Strategy [EasyLanguage Code]
INPUT:
MAXFLDUR(15), //Max Flag Duration
FLAGMIN(2.5), // Max Atr in lowest point in flag
PX(23), //Max Pole Duration.
UPT1BARS(70), // Bars for Uptrend leading to flag
POLEMIN(5.5), //Min ATR Height of the pole
LBF(50), // Min distance between flags
ATRmin(5),// Min volatility change
K(1.2), //Profit Target constant
timeexit(100), //Time exit bars
@18182324
18182324 / Pairs Trading Strategy Backtest for copula method [Python Code]
Last active February 7, 2023 02:57
Pairs Trading Strategy Backtest for copula method [Python Code]
import numpy as np
from scipy import stats
from statsmodels.distributions.empirical_distribution import ECDF
from scipy.stats import kendalltau, pearsonr, spearmanr
from scipy.optimize import minimize
from scipy.integrate import quad
import sys
from collections import deque
@18182324
18182324 / Pairs Trading Strategy Backtest for cointegration method [Python Code]
Created July 27, 2020 13:54
Pairs Trading Strategy Backtest for cointegration method [Python Code]
from sklearn import linear_model
import numpy as np
import pandas as pd
from scipy import stats
from math import floor
from datetime import timedelta
class PairsTradingAlgorithm(QCAlgorithm):
@18182324
18182324 / OpenDayRangeSP500
Last active May 12, 2024 15:27
Opening Range Breakout OHLC [Python]
from pandas import *
from datetime import *
import pdb as pdb
df = DataFrame.from_csv('aapl_1-2012_5min.csv')
dayCount=0
rangeHigh = -1
rangeLow = 9999
openDayRangeDict = {}
getRange = 1
class NetCurrentAssetValue(QCAlgorithm):
def Initialize(self):
#rebalancing should occur in July
self.SetStartDate(2007,5,15) #Set Start Date
self.SetEndDate(2018,7,15) #Set End Date
self.SetCash(1000000) #Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Daily
self.previous_fine = None
self.filtered_fine = None
def CalculateAccruals(self, current, previous):
accruals = []
for stock_data in current:
try:
prev_data = None
for x in previous:
if x.Symbol == stock_data.Symbol:
prev_data = x
break
def CoarseSelectionFunction(self, coarse):
if self.yearly_rebalance:
self.filtered_coarse = [x.Symbol for x in coarse if (x.HasFundamentalData)
and (x.Market == "usa")]
return self.filtered_coarse
else:
return []
def FineSelectionFunction(self, fine):
if self.yearly_rebalance:
model = RandomForestRegressor(n_jobs=-1, random_state=42, verbose=2)
grid = {'n_estimators': [10, 13, 18, 25, 33, 45, 60, 81, 110, 148, 200],
'max_features': [0.05, 0.07, 0.09, 0.11, 0.13, 0.15, 0.17, 0.19, 0.21, 0.23, 0.25],
'min_samples_split': [2, 3, 5, 8, 13, 20, 32, 50, 80, 126, 200]}
rf_gridsearch = GridSearchCV(estimator=model, param_grid=grid, n_jobs=4,
cv=cv, verbose=2, return_train_score=True)
rf_gridsearch.fit(X1, y1)