Microsoft MPI v10.0 설치
https://www.microsoft.com/en-us/download/details.aspx?id=57467
pip install gym
pip install pandas
pip install tensorflow==1.14.0
pip install stable-baselines[mpi]==2.10.0
pip install mpl_finance
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 backtrader as bt | |
class MyStrategy(bt.Strategy): | |
def next(self): | |
pass #Do something | |
#Instantiate Cerebro engine | |
cerebro = bt.Cerebro() | |
#Add strategy to Cerebro |
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 datetime | |
from pandas_datareader import data as pdr | |
import yfinance as yf | |
yf.pdr_override() | |
# 과거 주가 다운로드 함수 | |
# stock_no: 한국 주식 번호, 현재는 한국 주식만 다운로드 가능 | |
def get_stock_history_pdr(stock_no): | |
# 과거 주가 데이터, 기간은 3.5년으로 설정 | |
DT_DIFF = 365.25*3.5 |
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
def q_stick(Data, ema_lookback, opening, close, where): | |
# The variable Data refers to the OHLC array you are using | |
# The variable ema_lookback refers to the selected lookback period | |
# The variable opening refers to the open column in the OHLC array | |
# The variable close refers to the close column in the OHLC array | |
# The variable where refers to where the Q-Stick will be put | |
for i in range(len(Data)): | |
Data[i, where] = Data[i, close] - Data[i, opening] |
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
# 가중 이동평균 함수 | |
# 지수 이동평균 함수 | |
def ema(Data, alpha, lookback, what, where): | |
# alpha is the smoothing factor | |
# window is the lookback period | |
# what is the column that needs to have its average calculated | |
# where is where to put the exponential moving average | |
alpha = alpha / (lookback + 1.0) | |
beta = 1 - alpha |
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
# 파라미터 | |
# Data: 데이터(np.array), lookback: 이동 평균 기간(int), what: 대상 데이터 위치(int), where: 저장할 위치(int) | |
# ma: moving average | |
def ma(Data, lookback, what, where): | |
for i in range(len(Data)): | |
try: | |
Data[i, where] = (Data[i - lookback + 1:i + 1, what].mean()) | |
except IndexError: | |
pass | |
return Data |
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 gym | |
import numpy as np | |
import random | |
from keras.models import Sequential | |
from keras.layers import Dense, Dropout | |
from keras.optimizers import Adam | |
from collections import deque | |
class DQN: |
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 random | |
import json | |
import gym | |
from gym import spaces | |
import pandas as pd | |
import numpy as np | |
from StockTradingGraph import StockTradingGraph | |
MAX_ACCOUNT_BALANCE = 2147483647 |
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 numpy as np | |
import matplotlib | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
from matplotlib import style | |
# finance module is no longer part of matplotlib | |
# see: https://github.com/matplotlib/mpl_finance | |
from mpl_finance import candlestick_ochl as candlestick |
NewerOlder