Skip to content

Instantly share code, notes, and snippets.

rm(list = ls())
gc()
library(knitr)
library(blotter)
if (!exists('.blotter')) .blotter <- new.env()
suppressWarnings(try(rm(list=c("account.forex","portfolio.forex"),pos=.blotter),silent=TRUE))
suppressWarnings(try(rm(list=c("b.strategy","myTheme","EURUSD",".getSymbols")),silent=TRUE))
@mg64ve
mg64ve / optimal_strategy.py
Created October 8, 2017 08:06 — forked from lukovkin/optimal_strategy.py
Compute optimal trading strategy for the algorithm described in http://arxiv.org/abs/1508.00317
import numpy as np
import pandas as pd
def compute_market_prices(prices):
"""Compute market prices according to the trading competition recipe.
Parameters
----------
prices : DataFrame
@mg64ve
mg64ve / timeseries_cnn.py
Created November 17, 2018 22:37 — forked from jkleint/timeseries_cnn.py
Example of using Keras to implement a 1D convolutional neural network (CNN) for timeseries prediction.
#!/usr/bin/env python
"""
Example of using Keras to implement a 1D convolutional neural network (CNN) for timeseries prediction.
"""
from __future__ import print_function, division
import numpy as np
from keras.layers import Convolution1D, Dense, MaxPooling1D, Flatten
from keras.models import Sequential
from btgym import BTgymEnv
import IPython.display as Display
import PIL.Image as Image
from gym import spaces
import gym
import numpy as np
import random
@mg64ve
mg64ve / Policy Gradient with Cartpole and PyTorch (Medium Version).ipynb
Created August 19, 2019 09:45
Solution to the Cartpole problem with policy gradients published on Medium
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mg64ve
mg64ve / chartmill-backtest.py
Created October 23, 2019 20:33 — forked from makuchaku/chartmill-backtest.py
chartmill-backtest.py
import json
from datetime import datetime, timedelta
# Copies logic from https://www.quantconnect.com/tutorials/strategy-library/fundamental-factor-long-short-strategy
# Algo storing - https://www.quantconnect.com/docs/algorithm-framework/algorithm-scoring
class ChartMillBackTester(QCAlgorithm):
def Initialize(self):
self.SetCash(1000*100) # Are't we rich? :D
@mg64ve
mg64ve / residual_network.py
Created December 10, 2019 13:49 — forked from mjdietzx/residual_network.py
Clean and simple Keras implementation of residual networks (ResNeXt and ResNet) accompanying accompanying Deep Residual Learning: https://blog.waya.ai/deep-residual-learning-9610bb62c355.
"""
Clean and simple Keras implementation of network architectures described in:
- (ResNet-50) [Deep Residual Learning for Image Recognition](https://arxiv.org/pdf/1512.03385.pdf).
- (ResNeXt-50 32x4d) [Aggregated Residual Transformations for Deep Neural Networks](https://arxiv.org/pdf/1611.05431.pdf).
Python 3.
"""
from keras import layers
from keras import models