Skip to content

Instantly share code, notes, and snippets.

Avatar

charlie sando qorrect

View GitHub Profile
@qorrect
qorrect / main.py
Created Jun 26, 2020
Trying to visualize the Environment in evaluate()
View main.py
# Copyright 2018 Tensorforce Team. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@qorrect
qorrect / NATs-Replay.py
Created Aug 20, 2019 — forked from bdowling/NATs-Replay.py
These are just some sample scripts to dump the nats stream and replay it to a local NATs server.
View NATs-Replay.py
#!/usr/bin/env python
from nats.aio.client import Client as NATS
import json
import asyncio
import logging
import argparse
import gzip
import glob
import time
View run_backtests.py
import util.data as btu
from strategy import SMAStrategy
from joblib import Parallel, delayed
tickers = btu.get_nasdaq100()
def test_ticker(ticker):
cash = 100000
c = btu.run_backtest(SMAStrategy, ticker, '2019-05-01', '2019-05-14',cash)
percent_gain = ((c.broker.getvalue() - cash) / cash) * 100
print('Final Portfolio Value: {} for {} executing {} orders ( {}% )'.format(c.broker.getvalue(), ticker, len(c.broker.orders),percent_gain ))
View BaseStrategy.py
import backtrader as bt
import coloredlogs, logging
logger = logging.getLogger(__name__)
coloredlogs.install(fmt='%(name)s - %(levelname)s %(message)s', level='DEBUG')
class BaseStrategy(bt.Strategy):
def log(self, txt, dt=None):
View SMAStrategy.py
import backtrader as bt
from strategy import BaseStrategy
class SMAStrategy(BaseStrategy):
def __init__(self):
super().__init__()
self.sma_fast = bt.ind.ExponentialMovingAverage(period=10)
self.sma_slow = bt.ind.ExponentialMovingAverage(period=30)
View KitchenSinkAnalyzer.py
import backtrader as bt
from collections import defaultdict
class KitchenSinkAnalyzer(bt.Analyzer):
params = dict(sma_period=10, slow_sma_period=30, rsi_period=14, mean_period=10, moment_period=12, percent_period=15)
def start(self):
self.smas = {data: bt.indicators.SMA(data, period=self.p.sma_period)
for data in self.datas}
View KitchenSinkAnalyzer
import backtrader as bt
from collections import defaultdict
class KitchenSinkAnalyzer(bt.Analyzer):
params = dict(sma_period=10, slow_sma_period=30, rsi_period=14, mean_period=10, moment_period=12, percent_period=15)
def start(self):
self.smas = {data: bt.indicators.SMA(data, period=self.p.sma_period)
for data in self.datas}
View scanner.py
import backtrader as bt
import util.data as btu
import os
def run_stock_scanner(tickers, _from, _to, analyzers):
cerebro = bt.Cerebro()
for ticker in tickers:
DataFactory = btu.get_store().getdata
View x.py
l = [[1,2],[3,4]]
[x for y in l for x in y ]
View waitingTime.scala
object Solution {
def buyTicket(seq: Array[Int]): Array[Int] = {
seq.drop(1) ++ seq.take(1).map(_ - 1 )
}
def waitingTime(ts : Array[Int], p : Int ) : Int = {
var tickets = ts; var time_in_line = 0; var position = p