Skip to content

Instantly share code, notes, and snippets.

View jaymon0703's full-sized avatar

Jasen Mackie jaymon0703

View GitHub Profile
@jaymon0703
jaymon0703 / HRP.py
Last active December 17, 2022 10:59
Hierarchical Risk Parity implementation in Python
# Python 3 code
import matplotlib.pyplot as mpl
import scipy.cluster.hierarchy as sch,random
import numpy as np
import pandas as pd
# Now, take corMat and covMat generated from R, input into Marcos' Python, and check output is the same...
col_list = ["IGV.Close", "TLT.Close", "IAU.Close", "IYR.Close"]
corr = pd.read_csv("corMat_23072021.csv", usecols=col_list)
@jaymon0703
jaymon0703 / HRP.R
Last active August 28, 2021 21:54
Hierarchical Risk Parity implementation in R
# R code
corMat <- read.csv("corMat_23072021.csv")[,-1]
covMat <- read.csv("covMat_23072021.csv")[,-1]
clustOrder <- hclust(dist(corMat), method = 'single')$order
clustOrder
# Plot Dendogram for some visualization of the order
clust <- hclust(dist(corMat), method = 'single')
@jaymon0703
jaymon0703 / slack-notify-build.yml
Last active June 17, 2021 20:05
A YAML file for running an R-CMD-check on Ubuntu-latest using the rcmdcheck package and notifying Slack
name: R-CMD-check
on:
- push
- pull_request
jobs:
build:
runs-on: ubuntu-latest
env:
---
title: "Jane_Street_Kaggle"
author: "Jasen Mackie"
date: "18/12/2020"
output: html_document
---
```{r setup, include=FALSE}
require(data.table)
require(ggplot2)
@jaymon0703
jaymon0703 / macd_sig_yahoo.R
Created July 13, 2020 01:20
macd_sig fun - silly maybe not so silly strategy
# Simple MACD signal strategy
#
# blotter v 0.10.0
# quantstrat v 0.9.1739
# FinancialInstrument v 1.2.0
# Rblpapi v 0.3.4
#
#
# Author: Jasen
###############################################################################
@jaymon0703
jaymon0703 / quantstrat_test.ipynb
Created May 30, 2020 01:15
Running an R package's (quantstrat) demo in a Jupyter notebook using a Python3 Kernel
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jaymon0703
jaymon0703 / Bitcoin.cpp
Created October 8, 2018 07:49
Satoshi Nakamoto's C code from the Bitcoin whitepaper for determining an attacker on the network's probability of success
#include "math.h"
#include "stdio.h"
double AttackerSuccessProbability(double q, int z)
{
double p = 1.0 - q;
double lambda = z * (q / p);
double sum = 1.0;
int i;
int k;
@jaymon0703
jaymon0703 / CSCV3.Rmd
Last active October 6, 2018 16:08
Marcos Lopez de Prado - CSCV_3 program from Financial Charlatanism paper- http://www.ams.org/notices/201405/rnoti-p458.pdf
---
title: A replication of the Practical Application section in 'The Probability of Backtest
Overfitting' - Bailey et al.
output:
html_notebook:
# html_document:
# df_print: paged
---
In their paper "The Probability of Backtest
@jaymon0703
jaymon0703 / random_strategy_builder.R
Last active October 12, 2017 21:59
In preparation of my next blog post about txnsim, i would like to compare the txnsim output for some standard TTR backtests with the txnsim output for a purely randomised strategy. To do this, it makes sense to build a random strategy builder based on user specified stylized facts sampled from predefined distributions. Thanks Brian Peterson for …
require(blotter)
# Remove portfolio and account data if run previously
try(rm("portfolio.txnsim_rnorm_port","account.txnsim_rnorm_acct",pos=.blotter), silent = TRUE)
# load the example data
currency("USD")
stock("GSPC",currency="USD",multiplier=1)
getSymbols('^GSPC', src='yahoo', index.class=c("POSIXt","POSIXct"),from='1998-01-01')
@jaymon0703
jaymon0703 / profit.hurdle.R
Last active August 14, 2017 18:58
This is the Profit Hurdle implementation in R from Harvey & Liu's 'Backtesting' paper, Exhibit 6. It works as expected, so putting the code here for safekeeping until i complete the roxygen documentation and create a branch for issue 66 in braverock/quantstrat
###############################################################################
# R (http://r-project.org/) Quantitative Strategy Model Framework
#
# Copyright (c) 2009-2017
# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey Ryan, and Joshua Ulrich
#
# This library is distributed under the terms of the GNU Public License (GPL)
# for full details see the file COPYING
#
# $Id$