
$ python -m venv [가상환경이름]
$ [가상환경이름]\Scripts\activate # 맥은 source [가상환경이름]\Scripts\activate
$ python -m pip install --upgrade pip # pip 업그레이드
$ pip install streamlit # $ conda install streamlit
$ streamlit hello
$ streamlit run 파일명.py
$ pip freeze > requirements.txt
$ deactivate # 가상환경 비활성화
streamlit.text_input() 형식의 모듈을 호출하여 DOM 객체를 생성할 수 있다.st.plotly_chart(fig)를 호출하여 만들어진 ployly fig 차트 객체를 페이지에 표시할 수 있다.requirements.txt 파일에 pip freeze 출력을 저장하여 버전을 통일했다.
🔗Candlestick Charts in Python - plotly
ta(Technical Analysis) 라이브러리를 발견했고 상정한 지표인 MA, EMA, RSI, 볼린저밴드를 객체의 메서드 형태로 계산하여 반환해주는 것을 확인했다.🔗Technical Analysis Library in Python

FinanceDataReader의 GitHub를 확인하니 ohlcv정보를 요청할 때 일 단위로 요청하도록 하드코딩되어 있는 것을 확인했다.
💡 추후 yfinance 혹은 유료 API를 이용하여 분단위 ohlcv 정보를 받아와 분봉, 1시간봉 등을 제공할 수 있도록 해야겠다.
다음과 같이 기술 지표 입력값을 받았고, streamlit의 session_state에 list of dictionary로 저장하여 시각화 모듈에서 값을 읽어 시각화하도록 로직을 구성했다.
def chart_indicator_form():
st.header("차트 지표 입력")
MA = '이동평균선(MA)'
EMA = '지수이동평균선(EMA)'
BOLLINGER = '볼린저 밴드(BB)'
RSI = '상대강도지수(RSI)'
indicator_list = [MA, EMA, RSI, BOLLINGER]
selectbox, confirm = st.columns([3, 1])
with selectbox:
indicator_choice = st.selectbox(
'지표선택',
indicator_list,
key="indicator_choice",
label_visibility="collapsed" # 라벨 숨기기
)
with confirm:
add_btn = st.button("추가")
if indicator_choice in [MA, EMA, RSI]: # 이동평균선 & 지수이동평균선 & rsi
period = st.number_input("기간", min_value=1, max_value=1000, value=20)
line_color, line_width = _line_form("#0000FF", 2)
if add_btn:
indicator_dict = {
'period': period,
'line_color': line_color,
'line_width': line_width
}
# 선택한 인디케이터 이름 설정
if indicator_choice == MA:
indicator_dict['name'] = 'ma'
elif indicator_choice == EMA:
indicator_dict['name'] = 'ema'
elif indicator_choice == RSI:
indicator_dict['name'] = 'rsi'
# session_state에 선택한 인디케이터 저장
st.session_state['indicators'].append(indicator_dict)
elif indicator_choice == BOLLINGER: # 볼린저 밴드
period = st.number_input("기간", min_value=1, max_value=100, value=20)
std_dev = st.number_input("표준편차", min_value=1, max_value=5, value=2)
line_color, line_width = _line_form("#0000FF", 2)
if add_btn:
indicator_dict = {
'name': 'bollinger',
'period': period,
'std_dev': std_dev,
'line_color': line_color,
'line_width': line_width
}
# 선택한 인디케이터 저장
st.session_state['indicators'].append(indicator_dict)
# 삭제 버튼 추가
if st.session_state['indicators']:
_add_delete_btn()
