내가 열심히 개조한 노트북을 소개합니다~ 5분이면 이 노트북을 만들 수 있어요!
13581 단어 Python
의 목적
제 생업은 주로 정량 분석 투자이고 Jupter notebook도 즐겨 사용합니다.
그래서 이번에는 제가 직접 만든 notebook을 소개하고 싶어요!
여러분의 노트북에 조금이라도 유용한 정보가 있다면 좋겠습니다!
다음 그림은 맞춤형 나의 notebook입니다.

Jupter notebook 설치
Anaconda를 아직 다운로드하지 않은 사람은 여기(Individual Edition Anaconda)에서 다운로드할 수 있습니다!
다운로드에 관해서는 영어지만 다운로드만 하고 지시를 따르기 때문에 계속하고 싶어요!
사용자 정의
이번 맞춤 제작의 내용은 다음과 같다.
코드 명명 규칙 자동 수정(Black)
코드를 너무 많이 써서 문법이 잘 모를 때 클릭하면 예뻐진다.

jupyter nbextension install https://github.com/drillan/jupyter-black/archive/master.zip --user
jupyter nbextension enable jupyter-black-master/jupyter-black
만약 이것이 설치되어 있다면, Jupter notebook 도구 모음에서 Black 이 단추를 만들 것입니다. 이 단추를 누르기만 하면, 칸 안의 코드는 PEP8 규칙에 따라 정확합니다.참조: https://github.com/drillan/jupyter-black
notebook 테마 변경
여기, notebook의 테마를 변경합니다.내가 사용하는 주제는 원파크다.
# install jupyterthemes
pip install jupyterthemes
jt -t onedork -T -N -kl
도구막대, 이름, 로고 등을 표시할 수 있습니다.옵션을 선택하면 도구 모음 등이 더 이상 표시되지 않습니다.또한 코드를 실행해도 이미 열린 notebook에 반영되지 않습니다. 반영된 notebook을 보려면 notebook을 다시 시작하십시오.
참조: https://github.com/dunovank/jupyter-themes
틀화하다
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install jupytemplate
jupyter nbextension install --py jupytemplate --sys-prefix
jupyter nbextension enable jupytemplate/main --sys-prefix
이렇게 되면 본보기화된 준비가 다 되었다.다음은 템플릿 편집입니다.
템플릿의 경우 아래 코드를 실행하고 notebook 파일을 직접 사용하십시오.
import jupytemplate
print(jupytemplate.get_template_path())
notebook 파일을 놀고 나면 다음 명령을 입력하고 템플릿을 반영하십시오.jupyter nbextension install --py jupytemplate --sys-prefix
jupyter nbextension enable jupytemplate/main --sys-prefix
참조: https://github.com/xtreamsrl/jupytemplate너비 변경
이전 장에서 만든 템플릿 화면에 다음 명령을 붙여 넣으십시오.
이것은 가로 화면을 사용하는 사람들이 자주 직면하는 문제이지만 가로 페이지의 간격이 매우 많아 코드, 표와 도표를 자주 볼 수 없다.
이걸 처리하고 싶은 분들은 넓이를 넓히는 걸 추천합니다.
%%HTML
<style>
div#notebook-container { width: 95%; }
div#menubar-container { width: 65%; }
div#maintoolbar-container { width: 99%; }
</style>
그래프 형식 등
다음은 예쁜 그래프를 만들기 위해 기본적으로 여러 가지를 설정하면 편리하다.
템플릿에 다음 명령을 붙여 넣으십시오.
그러나 가로 너비와 쓰기를 변경하는 명령을 다른 칸에 붙여넣으십시오.이유는%%% HTML이라고 쓰여 있는데, 그 칸에서 HTML이 실행되었기 때문에 ptyhon 명령을 실행할 수 없습니다.
# Data manipulation
import pandas as pd
import numpy as np
# Options for pandas
pd.options.display.max_columns = 50
pd.options.display.max_rows = 30
# Visualizations
# import jtplot module in notebook
from jupyterthemes import jtplot
# choose which theme to inherit plotting style from
# onedork | grade3 | oceans16 | chesterish | monokai | solarizedl | solarizedd
jtplot.style(theme='onedork')
# set "context" (paper, notebook, talk, poster)
# scale font-size of ticklabels, legend, etc.
# remove spines from x and y axes and make grid dashed
jtplot.style(context='talk', fscale=1.4, spines=False, gridlines='--')
# turn on X- and Y-axis tick marks (default=False)
# turn off the axis grid lines (default=True)
# and set the default figure size
jtplot.style(ticks=True, grid=False, figsize=(6, 4.5))
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
import cufflinks as cf
cf.set_config_file(offline=True, theme="space", offline_show_link=False)
# Autoreload extension
if 'autoreload' not in get_ipython().extension_manager.loaded:
%load_ext autoreload
%autoreload 2
마지막 놀이
위에서 실행한 코드가 부족한 프로그램 라이브러리는 pip install로 적당히 보충하십시오.
닛케이 평균 주가를 좀 봅시다.
from datetime import datetime
import pandas_datareader.data as web
start = datetime(2000, 1, 1)
end = datetime(2020, 12, 3)
symbol = "^N225"
df = web.DataReader(symbol, 'yahoo', start, end)
df
아래와 같다.
다음 명령을 실행하십시오.
qf = cf.QuantFig(df, title="Nikkei 225", legend='top', name="N225")
qf.add_bollinger_bands()
qf.add_sma([10,20],width=2,color=['green','lightgreen'],legendgroup=True)
qf.add_rsi(periods=20,color='java')
qf.add_bollinger_bands(periods=20,boll_std=2,colors=['magenta','grey'],fill=True)
qf.add_volume()
qf.add_macd()
qf.iplot()
다음 차트를 표시합니다.그리고 도표는plotly이기 때문에 만져도 돼요.
참조: https://github.com/santosjorge/cufflinks
참조: https://plotly.com/python/
총결산
어때요?
더 멋진 주제가 있다고 생각해요. 취향에 맞게 완성했으면 좋겠어요!
가능하면 꼭 해보세요!!
Reference
이 문제에 관하여(내가 열심히 개조한 노트북을 소개합니다~ 5분이면 이 노트북을 만들 수 있어요!), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kanawoinvest/items/47b055f45354d126d98f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)