본문 바로가기

Language/python

(51)
[ Python backtrader ] backtrader 참고 사이트 # 복수개의 Backtesting 참고 https://jsp-dev.tistory.com/entry/PythonBacktrader-%EB%8B%A4%EC%A4%91-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EB%B0%B1%ED%85%8C%EC%8A%A4%ED%8C%85-Python-sqlite3backtrader-Mutliple-Data-Feeds-Pandas-DataFrame-to-Backtrader?category=808569 # muti data feed 참고 https://backtest-rookies.com/2017/08/22/backtrader-multiple-data-feeds-indicators/ # backtrader analyzer분석 : 코드 잘 실행됨.... https:/..
[ Python backtrader ] potfolio value 및 cash 그래프만 그리기 1. Standard plot() 출력 cerebro = bt.Cerebro() # stdstats (default: True)로 되어있음. ... cerebro.run() cerebro.plot() 위와 같이 cerebro생성 이후 plot()를 실행하면 기본적으로 아래와 같이 Broker, Data Trades, BuySell 3개의 그래프가 출력된다. 그 이유는 표준에는 묵시적으로 아래 3개의 observers가 추가되어있기 때문이다. cerebro.addobserver(bt.observers.Broker) cerebro.addobserver(bt.observers.Trades) cerebro.addobserver(bt.observers.BuySell) 2. stdstats False 처리 cere..
[ Python backtrader ] plot option System-wide plotting options def plot(self, plotter=None, numfigs=1, iplot=True, **kwargs): plotter: an object/class containing as attributes the options controlling the system wide plotting If None is passed a default PlotScheme object (see below) will be instantiated numfigs: in how many independent charts a plot has to be broken Sometimes a chart contains too many bars and will not be easily ..
[ Python library ] argparse 사용법 https://greeksharifa.github.io/references/2019/02/12/argparse-usage/님 글 참조 Python argparse 사용법 12 Feb 2019 | PyTorch Argparse usage 목차 Import argparse –help, -h argument 이름 정의 type 지정 positional / optional 인자 default 값 지정 action의 종류 지정 attribute name: -, _ 구분 dest: 적용 위치 지정 nargs: 값 개수 지정 choices: 값 범위 지정 metavar: 이름 재지정 References 이 글에서는 Python 패키지인 argparse에 대해 알아본다. Machine Learning 코드를 볼 때 꽤..
[ Python backtrader ] Multi 기본 하루 1주 매수전략 from __future__ import (absolute_import, division, print_function, unicode_literals) import datetime # For datetime objects import os.path # To manage paths import sys # To find out the script name (in argv[0]) import backtrader as bt import pandas as pd import psycopg2 import numpy as np companylist = ['A005930','A000660'] # 매수할 company리스트를 담는다. class TestStrategy(bt.Strategy): def log(self, tx..
[ Python backtrader ] 기본 하루 1주 매수 전략 from __future__ import (absolute_import, division, print_function, unicode_literals) import datetime # For datetime objects import os.path # To manage paths import sys # To find out the script name (in argv[0]) import backtrader as bt class TestStrategy(bt.Strategy): def log(self, txt, dt=None): # self.log함수 호출시 txt만 인자로 주면 앞에 일자를 넣어줌 ''' Logging function fot this strategy''' dt = dt or self.dat..
[ Python zipline ] Ingesting quandl 1) QUANDL_API_KEY 찾기 https://www.quandl.com/account/profile 2) command창에서 set QUANDL_API_KEY=Bvgc8zz1uFWzmgXpCwu5 입력 3) zipline ingest -b quandl - memory 에러로 실패 아래 url참조 하여 bundle만들기 시도 예정 https://towardsdatascience.com/backtesting-trading-strategies-using-custom-data-in-zipline-e6fd65eeaca0
[ django ] static/img 폴더에 이미지 저장하기 1. __file__ '__file__' 은 현재의 파일을 반환한다. 헌데 \가 /으로 표현되어 있어 변환이 필요하다. 2. os.path.abspath(__file__) abspath함수는 파일의 절대 경로를 반환한다. 3. os.path.dirname(os.path.abspath(__file__)) dirname은 인자의 파일이나 디렉토리가 포함된 디렉토리를 반환한다. 4. 아래와 같이 BASE_DIR에 웹의 기본 디렉토리의 절대경로가 저장되게 된다. 5. BASE_DIR + '\\static\\img'를 통해 img폴더의 절대경로를 생성할 수 있다. # 예제파일 import pandas_datareader.data as web import datetime import matplotlib.pyplot..