본문 바로가기

Python78

[Python] finterstellar를 사용하여 Envelope로 주식 매매 시그널 만들기 2021.12.09 - [Python] - [Python] finterstellar를 사용하여 RSI로 주식 매매 시그널 만들기 먼저 finterstellar가 처음이라면 이전 글을 보고 와주세요. Envelope Envelope는 주가를 감싸고 있어서 붙은 이름입니다. 그림처럼 주가의 위아래를 감싸고 있습니다. 가운데 이동평균선을 중심으로 각각 ±X%의 선을 만든 것입니다. 보통 위에 있는 선을 저항선, 아래에 있는 선을 지지선이라 부릅니다. Envelope를 사용한 투자전략은 모멘텀, 평균회귀에 모두 사용될 수 있습니다. 모멘텀 투자를 한다면 주가가 envelope를 상향 돌파하면 매수하여 다시 envelope 안으로 들어가면 매도를 할 것이고, 평균회귀 투자를 한다면 주가가 envelope의 아래쪽.. 2021. 12. 11.
[Python] Getting Started with Kaggle Kaggle is the most famous machine learning competition site. Sign Up Let's visit the site and sign up. Kaggle: Your Machine Learning and Data Science Community Kaggle is the world’s largest data science community with powerful tools and resources to help you achieve your data science goals. www.kaggle.com Overview Now, you can see this screen. Competitions: You can select competitions that you w.. 2021. 12. 11.
[Python] finterstellar를 사용하여 MACD로 주식 매매 시그널 만들기 2021.12.09 - [Python] - [Python] finterstellar를 사용하여 RSI로 주식 매매 시그널 만들기 먼저 핀터스텔라가 처음이라면 이전 글을 보고 와주세요. MACD (Moving Average Convergence Divergence) MACD는 이동평균수렴확산지수라고 말하며, 대표적인 보조 지표 중 하나입니다. MACD를 계산할 때 MA(Moving Average)를 사용하여 주가 추이를 보면, 몇 일간의 누적 데이터가 필요하므로 실제 추이보다 늦어질 수 밖에 없습니다. 이를 해결하기 위해 최근의 데이터에 더 높은 가중치를 주고 계산한 EMA(Exponential Moving Average)를 사용합니다. 이 EMA를 사용하여 MACD의 보조 지표들을 계산할 수 있습니다. .. 2021. 12. 10.
[Python] finterstellar를 사용하여 RSI로 주식 매매 시그널 만들기 이번 포스팅에서는 finterstellar module을 사용하여 주가 정보를 얻고, RSI를 사용한 투자 전략을 적용하여 투자 성과를 분석해보겠습니다. finterstellar module 설치 pip를 사용하여 간단히 설치할 수 있습니다. $ pip install finterstellar import finterstellar 사용을 위해 간단히 fs로 가져와 보겠습니다. import finterstellar as fs 주가 정보 가져오기 다음의 메소드로 쉽게 가져올 수 있습니다. get_price(종목 코드, 시작일, 종료일) 실제로, 엔비디아의 올해 주가 정보를 가져와 보겠습니다. df = fs.get_price('NVDA', start_date='2021-01-01', end_date='2021-.. 2021. 12. 9.
[Python] Singleton Pattern Singleton is a creational design pattern, which ensures that only one object of its kind exists and provides a single point of access to it for any other code. Singleton is alike to the global variable. Code class SingletonMeta(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls._instances: instance = super().__call__(*args, **kwargs) cls._instances[cls] = instance retur.. 2021. 11. 2.
[Python] String Let's take a look at the string in Python. Changing Case We can simply change the case of string via upper() and lower() functions. test_string = "Hello, World" print(test_string.upper()) # HELLO, WORLD print(test_string.lower()) # hello, world It works well in the English alphabet case. What about the other language in Unicode? test_string = "ß" print(test_string.upper()) # SS print(test_string.. 2021. 10. 31.
[Python] Testing The test is the one of most important parts of development. pytest and unittest are generally used for testing in Python. Example of unittest Module Let's use unittest module. This is a built-in module, so you just use it. It is highly recommended as follows: The name of the test module starts with test. Test class inherits from unittest.TestCase. The name of the test method starts with test. Te.. 2021. 10. 30.
[Python] Debugging Debugging is an important thing to fix a problem of code. Debugger pdb pdb is a command-line tool to debug Python code. import pdb pdb.set_trace() ipdb ipdb is the same kind of tool. In addition, ipdb can debug IPython as well. But, this is not a built-in module. $ pip install ipdb import ipdb ipdb.set_trace() pudb pudb is a more useful debugger than pdb and ipdb. But, this is not a built-in mod.. 2021. 10. 27.
[Python] logging Python has logging module. It helps us to log the code flow. Import logging module import logging logging.getLogger(__name__).addHandler(logging.NullHandler()) We can simply import the logging module and config it. Use logging module (with Stack Trace) import logging def divide_by_zero(): try: c = 3 / 0 except Exception as e: logging.error("Exception ", exc_info=True) divide_by_zero() # ERROR:ro.. 2021. 10. 25.
[Python] Docstring Docstring is a powerful tool to document in Python. Docstring becomes a __doc__ property for the object. You can find the official Docstring Conventions in the below link. https://www.python.org/dev/peps/pep-0257/ Docstring Syntax Python recommends using """triple double quotes""" for Docstring. You can start with r for raw string and u for Unicode string. Docstring Specification One-line Docstr.. 2021. 10. 18.
[Python] Running Python with Docker In this posting, we will be looking into running python with docker. Install Docker I will use docker on MAC with homebrew. $ brew install --cask docker Please refer to the official site for installing docker if you want to use it another way or use another OS. https://docs.docker.com/get-docker/ Get Docker docs.docker.com Now, run the docker. Then docker is automatically downloaded and you can .. 2021. 8. 28.
[PyQt6] Getting Started In this posting, we will learn how to create the desktop application using PyQt6. Installation $ pip install pyqt6 Now, we prepared for using PyQt6. Create Application Using Function import sys from PyQt6.QtWidgets import QApplication, QWidget def main(): w = QWidget() w.resize(320, 240) w.setWindowTitle('PyQt6 Example') w.show() sys.exit(app.exec()) if __name__ == '__main__': app = QApplication.. 2021. 8. 10.