Skip to content

Instantly share code, notes, and snippets.

@darden1
darden1 / cpp_test_sum_.cpp
Created March 20, 2017 07:26
Test script for cumulative sum in c++. Definition part of member functions.
#include <vector>
#include "cpp_test_sum_.h"
using namespace std;
namespace cpp_test_sum{
// Constructor
cppTestSum::cppTestSum(int n_iter)
:
n_iter(n_iter),
@darden1
darden1 / cpp_test_sum_.h
Created March 20, 2017 07:24
Test header for cumulative sum in c++.
#ifndef CPPTESTSUM_H
#define CPPTESTSUM_H
#include <vector>
using namespace std;
namespace cpp_test_sum{
class cppTestSum{
public:
int n_iter;
@darden1
darden1 / tradingrrl.cpp
Last active September 16, 2018 12:41
c++ implementation of RRL.
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <iostream>
#include <math.h>
#include <ctime>
using namespace std;
@darden1
darden1 / main.py
Created March 14, 2017 12:18
For executing cython RRL.
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from tradingrrl import TradingRRL, plot_hist
def main():
fname = "USDJPY30.csv"
init_t = 6000
@darden1
darden1 / setup.py
Created March 14, 2017 12:17
For compiling tradingrrl.pyx.
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [
Extension("tradingrrl", sources=["tradingrrl.pyx"], include_dirs=[numpy.get_include()],)
]
@darden1
darden1 / tradingrrl.pyx
Created March 14, 2017 12:06
Cython imlementaion of RRL.
# -*- coding: utf-8 -*-
#cython: boundscheck=False
#cython: wraparound=False
#cython: nonecheck=False
import numpy as np
cimport numpy as np
cimport cython
ctypedef np.float64_t DOUBLE_t
@darden1
darden1 / speed_test.py
Created March 14, 2017 11:02
Comparing Python and Cython execution speed.
import time
import py_test_sum
import cy_test_sum
n_iter = 10000000
#--- Python sum
py_ts = py_test_sum.TestSum(n_iter)
tic = time.clock()
@darden1
darden1 / setup.py
Created March 14, 2017 11:00
For compiling cy_test_sum.pyx.
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [
Extension("cy_test_sum", sources=["cy_test_sum.pyx"], include_dirs=[numpy.get_include()],)
]
import numpy as np
cimport numpy as np
cimport cython
ctypedef np.float64_t DOUBLE_t
cdef class TestSum(object):
cdef public int n_iter
cdef public np.ndarray sum
@darden1
darden1 / py_test_sum.py
Created March 14, 2017 10:58
py_test_sum.py
import numpy as np
class TestSum(object):
def __init__(self, n_iter):
self.n_iter = n_iter
self.sum = np.zeros(n_iter)
def calc_sum(self):
for i in range(1, self.n_iter):