Skip to content

Instantly share code, notes, and snippets.

#' Saves symbols (from an environment) to a specified directory
#'
#' The files (one per symbol) are saved in \code{dir}. The file name
#' is the symbol itself, and the file extension is RData.
#'
#' @param symbols The symbols
#' @param dir The destination folder (file system directory). It must exist.
#' @param env The environment containing the symbols
#'
#' @examples
@ivannp
ivannp / test7.C
Created October 28, 2012 22:31
Maintaining sorted std::vector
// g++ -O3 -std=c++0x -o test test7.C
#include <iostream>
#include <cstdint>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cassert>
using namespace std;
'''
A module to load instruments and bars from a SQLite database.
'''
import pandas as pd
import toml
from sqlalchemy import create_engine
class CsiDb:
import cntk
import cntk.ops as C
import numpy as np
from sklearn.preprocessing import OneHotEncoder
from cntk.blocks import default_options, Input # Building blocks
from cntk.initializer import glorot_uniform
from cntk.layers import Dense # Layers
from cntk.learner import sgd, learning_rate_schedule, UnitType
import dshelper as dsh
import instrumentdb as idb
import logging
import numpy as np
import os
import pandas as pd
import psutil
import sys
import tensorflow as tf
import time
@ivannp
ivannp / opportunities.py
Last active August 16, 2017 21:27
Discovering trading opportunities in price series and generating possible predictors
import pandas as pd
import numpy as np
import instrumentdb as idb
import math
import pickle
def good_entries(ohlcv, min_days = 3, days_out = 15, vola_len = 35, days_pos = 0.6, stop_loss = 1.5):
if days_out <= min_days:
raise RuntimeError('days_out must be greater than min_days.')
@ivannp
ivannp / rallies.r
Last active November 28, 2017 20:14
POTUS Rallies since Election Day
require(quantmod)
require(ggplot2)
require(ggthemes)
# The starting index in the elections dates and president's arrays
# start.index = 7
start.index = 6
# sp = getSymbols("^GSPC", from="1900-01-01", auto.assign=F)
sp = as.xts(read.csv.zoo('dji.csv', format='%Y%m%d', header=F, sep=",")[,1:4])
@ivannp
ivannp / format_default
Created February 16, 2018 06:04
format/default to support lib.ivannp
#
# Copyright (C) 1996-2001, Thomas Andrews
#
# $Id: default 277 2008-10-27 17:36:14Z thomasoa $
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
require(R6)
require(quantmod)
# Db interface
YahooDb = R6Class("YahooDb",
public = list(
initialize = function(path="yahoo.sqlite") {
private$path = path
},
@ivannp
ivannp / dvi.r
Created September 24, 2014 16:24
DVI Indicator Backtesting with SIT
require(quantmod)
require(SIT)
dvi.indicator = function(prices) {
dvi = TTR:::DVI(prices)[,3]
indicator.long = ifelse(dvi <= 0.5, 1, 0)
indicator.short = ifelse(dvi > 0.5, -1, 0)
indicator = reclass(cbind(indicator.short + indicator.long), prices)