Skip to content

Instantly share code, notes, and snippets.

View JustinGuese's full-sized avatar

Justin Güse JustinGuese

View GitHub Profile
@JustinGuese
JustinGuese / storj-kubernetes.yaml
Last active October 18, 2022 15:49
an example on how to deploy storj to kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
service: storagenode
name: storagenode
namespace: storj
spec:
replicas: 1
selector:
def getDecision(dfrow):
if dfrow['trend_aroon_ind'] <= 10.0:
if dfrow['volatility_dcp'] <= 0.69:
if dfrow['volatility_dcp'] <= 0.46:
return 0
else: # if dfrow['volatility_dcp'] > 0.46
if dfrow['trend_aroon_down'] <= 34.0:
return 1
else: # if dfrow['trend_aroon_down'] > 34.0
return 0
@JustinGuese
JustinGuese / decision-tree-convert-to-if-else.py
Created October 7, 2022 11:40
converts an sklearn decision tree to if/else statements
from sklearn.tree import _tree
def tree_to_code(tree, feature_names):
tree_ = tree.tree_
feature_name = [
feature_names[i] if i != _tree.TREE_UNDEFINED else "undefined!"
for i in tree_.feature
]
feature_names = [f.replace(" ", "_")[:-5] for f in feature_names]
print("def getDecision(dfrow):")
import graphviz
dot_data = export_graphviz(clf, out_file=None,
feature_names=X.columns,
class_names=["sell", "buy"],
filled=True, rounded=True,
special_characters=True)
graph = graphviz.Source(dot_data)
graph
from tqdm import tqdm
bestDepth = -1
bestLeafes = -1
bestLookback = -1
bestDepthWin = -9999
collection = []
# explicitly force a max of 20 to prevent overfitting
for depth in tqdm([100,70,50,40,30,20,15]):
for leafes in [100,70,50,40,30,20,15]:
bigDf = []
for ticker in ["CWEG.L", "IWDA.AS", "EEM", "AAPL", "MSFT", "GOOG", "TSLA", 'AMD', 'AMZN', 'DG', "ETH-USD", "BTC-USD"]:
print("geddin stock: " + ticker)
tmp = getData(ticker = ticker, start = date(2010,1,1))
tmp = getTrend(tmp)
bigDf.append(tmp)
bigDf = pd.concat(bigDf)
bigDf.shape
@JustinGuese
JustinGuese / decisiontree.py
Created October 7, 2022 11:17
decision tree example for medium post
from sklearn import metrics, DecisionTreeClassifier
X, Y = df.drop(["signal"], axis=1), df["signal"]
clf = DecisionTreeClassifier()
clf.fit(X, Y)
preds = clf.predict(X)
print(metrics.classification_report(Y, preds))
print(metrics.confusion_matrix(Y, preds))
@JustinGuese
JustinGuese / fakemodel.py
Created October 7, 2022 11:12
A fake sklearn model for benchmarking
from random import random
class FakeModel:
def predict(self, X):
# random decision for demo purposes
preds = []
for i in range(len(X)):
if random() > .5:
preds.append(1)
else:
preds.append(-1)
@JustinGuese
JustinGuese / onerun.py
Last active October 7, 2022 11:13
Function to simulate a trade/backtrade. Needs "getdata.py"
def oneRun(model):
global X
bestLookbackWin = -9999
bestLookbackPortfolio = []
money = startMoney
nrStocks = 0
portfolio = []
for i in range(len(X)):
prednow = model.predict(X.iloc[i])[0]
print("prednow is, " , prednow)
@JustinGuese
JustinGuese / baseline.py
Created October 7, 2022 11:00
Getting a baseline of data. See "getdata.py" on how to get data
startMoney = 10000
COMMISSION = 0.00025 # interactive brokers commission
howmany = startMoney / msft.iloc[0]["Adj Close"]
win = howmany * msft.iloc[-1]["Adj Close"] - startMoney
days = (msft.index[-1] - msft.index[0]).days
print("with just holding you would have made %.2f$" % win)
winPerMonth = win / (days / 30)
winPctPerYear = winPerMonth * 12 / startMoney * 100