This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A Simple Strategy Trading Two Stocks | |
Original code: https://blog.csdn.net/qq_26948675/article/details/80016633 | |
Modified based on: https://www.backtrader.com/blog/posts/2018-04-22-improving-code/improving-code.html | |
Replaced the local CSV files with online data from IEX. | |
Unfortunately, this strategy is not profitable for the two stocks picked. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
@author: CeShine | |
Using keras-rl (https://github.com/matthiasplappert/keras-rl) to provide basic framework, | |
and embedding layer to make it essentially a Q-table lookup algorithm. | |
""" | |
import tempfile |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class STLR(torch.optim.lr_scheduler._LRScheduler): | |
def __init__(self, optimizer, max_mul, ratio, steps_per_cycle, decay=1, last_epoch=-1): | |
self.max_mul = max_mul - 1 | |
self.turning_point = steps_per_cycle // (ratio + 1) | |
self.steps_per_cycle = steps_per_cycle | |
self.decay = decay | |
super().__init__(optimizer, last_epoch) | |
def get_lr(self): | |
residual = self.last_epoch % self.steps_per_cycle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference: https://svds.com/jupyter-notebook-best-practices-for-data-science/ | |
import os | |
from subprocess import check_call | |
def post_save(model, os_path, contents_manager): | |
"""post-save hook for converting notebooks to .py scripts""" | |
if model['type'] != 'notebook': | |
return # only do this for notebooks | |
d, fname = os.path.split(os_path) | |
check_call(['jupyter', 'nbconvert', '--to', 'script', fname], cwd=d) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on tinrtgu's Python script here: | |
// https://www.kaggle.com/c/avazu-ctr-prediction/forums/t/10927/beat-the-benchmark-with-less-than-1mb-of-memory | |
package main | |
import ( | |
"encoding/csv" | |
"os" | |
"strconv" | |
"hash/fnv" | |
"math" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sqlite3 | |
import datetime | |
from typing import List | |
import faiss | |
import numpy as np | |
import pandas as pd | |
import joblib | |
import requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastcore.basics import patch_to | |
class Demo: | |
val = 10 | |
def __init__(self, val): | |
self.val = val | |
# ==================== | |
# The default mode |
NewerOlder