stock-tools


Namestock-tools JSON
Version 0.1.1 PyPI version JSON
download
home_page
Summary알고리즘 주식 투자를 위한 여러 툴을 모아놓은 라이브러리입니다.
upload_time2023-12-16 06:30:44
maintainer
docs_urlNone
authorilotoki0804
requires_python>=3.11.0,<3.12.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # stock-tools

알고리즘 주식 투자를 위한 여러 툴을 모아놓은 라이브러리입니다. 주식 데이터 불러오기, 호가 단위 맞추기, 주식 매매 시뮬레이션하기, 원숭이 투자자(임의로 사고 팔기를 반복하는 임의의 투자자), 통계 계산 외에도 많은 기능을 지원합니다.

## 설치 방법

다음의 명령어를 통해 설치 및 업데이트를 하실 수 있습니다.

```console
pip install stock-tools -U
```

그런 다음 다음의 명령어를 사용해 제대로 설치가 되었는지 확인하세요.

> [!NOTE]
> keys.json이 없다는 오류 메시지가 뜰 수 있습니다. 이 경우 keys.json을 설명하는 섹션에서 설명하는 keys.json 파일을 만드세요.

```python
import stock_tools
```

### keys.json

KEY 상수를 사용하려면 루트 디렉토리에 `keys.json`이 있어야 합니다.

우리 팀의 `keys.json`은 디스코드에 업로드되어 있으니 사용하시면 됩니다.

`keys.json`은 다음과 같은 형식으로 만들면 됩니다.

```json
{
    "api_key": "...",
    "api_secret": "...",
    "acc_no": "..."
}
```

설명은 아래의 '사용법'을 참고하세요.

### 기본 import

이 라이브러리에는 많은 파일들이 있고, 대부분은 top level에서 사용할 수 있습니다. 그러나 `fetch` 모듈과 `stock_statistics` 모듈은 묶여 있는 것이 더욱 어울리는 모듈이기에 직접 import 가 필요합니다.

```python
from stocks import PriceCache, Transaction  # 대부분의 모듈들은 바로 사용 가능합니다.
from stocks.fetch import fetch_prices_by_datetime  # fetch와 stock_statistics는 직접 import해야 합니다.
from stocks.stock_statistics import stock_volatility
```

## 사용법

### KEY 사용하기

KEY를 이용하려면 우선 `keys.json`을 폴더에 넣어야 합니다. 자세한 방법은 '설치 방법'을 참고하세요.

`keys.json`이 설치되었다면 다음과 같이 간편하게 mojito를 사용할 수 있습니다.

```python
from stocks import adjust_price_unit, KEY
import mojito

broker = mojito.KoreaInvestment(**KEY)
...
```

### adjust_price_unit 사용하기

`adjust_price_unit`은 지정가 매수 시 호가 단위를 맞출 수 있도록 합니다. 자세한 설명은 `adjust_price_unit`의 docs와 해당 함수가 선언된 모듈의 docs를 참고하세요.

### 매수, 매도 등 사용 및 예제 확인하기

Repo 내 examples.py에는 어떻게 adjust_price_unit를 사용하는지와 매수, 매도를 어떻게 하는 지에 대한 예제가 있습니다. 해당 내용을 참고하세요.

### 가격 불러오기

가격을 불러오는 방식은 세 가지가 있습니다.

1. PriceCache: 하루의 데이터를 알고 싶은 경우 사용
1. fetch.fetch_prices_by_datetime: 기간의 데이터를 알고 싶은 경우 사용
1. fetch._fetch_prices_unsafe: 위와 동일하고 더 빠르지만 100일 이상의 데이터를 불러올 수 없음.

일반적으로 3번을 사용할 일은 적을 것이고 PriceCache나 fetch_prices_by_datetime을 사용하게 될 가능성이 높습니다.

PriceCache과 fetch_prices_by_datetime의 차이점은 기간으로 불러올 수 있는지와 아닌지의 차이도 있지만 결정적인 것은 바로 캐싱의 여부입니다.
캐싱이란 데이터를 서버에서 불러온 후 만약 이미 전에 불러온 데이터라면 서버를 경유하지 않고 저장되어 있던 데이터에서 가져오는 것을 의미합니다.
fetch_prices_by_datetime는 캐싱이 되지 않지만 PriceCache는 캐싱이 됩니다.

캐싱을 사용한다면 같은 데이터를 여러 번 사용하는 경우 속도를 높일 수 있기 때문에 특별한 경우를 제외하면 fetch_prices_by_datetime 대신 PriceCache를 사용하는 것을 권장합니다.

#### fetch_prices_by_datetime 사용하기

fetch_prices_by_datetime은 다음과 같이 사용할 수 있습니다.

```python
from datetime import datetime
import mojito
from stocks import KEY
from stocks.fetch import _fetch_prices_unsafe, fetch_prices_by_datetime

broker = mojito.KoreaInvestment(**KEY)

fetch_prices_by_datetime(
    broker=broker,
    company_code="005930",  # 종목 코드
    date_type='D',  # 일봉 사용 ('D', 'M', 'Y' 사용 가능)
    start_day=datetime(2019, 5, 7),  # 2019년 5월 7일부터
    end_day=datetime(2023, 2, 15),  # 2023년 2월 14일까지 (2월 15일 데이터는 포함되지 않음!!!)
)
```

여기에서 주의해야 할 점은 파이썬의 `range()`나 slicing처럼 end_day에 그 당일은 포함되지 않는다는 점입니다.
mojito 모듈과 이 부분에서 다르니 주의하세요.

#### PriceCache 사용하기

PriceCache모듈은 다음과 같이 사용이 가능합니다.

```python
from datetime import datetime

from stocks import PriceCache

price_cache = PriceCache.from_keys_json(
    default_company_code='005930', # 기본 종목 코드가 설정되었기 때문에 get_price에서 company_code를 생략할 수도 있음.
)

# 혹은 brocker를 직접 넘겨줄 수도 있습니다.
broker = mojito.KoreaInvestment(**KEY)
price_cache = PriceCache(
    broker=broker,
    default_company_code=None,  # None이기 때문에 get_price에서는 항상 company_code를 정의해야 함.
)

price_cache.get_price(
    # 값을 가져올 날짜.
    day=datetime(2020, 1, 4),

    # 이 값은 만약 생략됐다면 default_company_code에 넘겨준 값을 사용하고, 만약 넘겨진 값이 없다면 오류가 남.
    company_code="005930",

    # 얼마나 가까운 날짜까지 사용할지 정함. None일 경우 100일로 설정됨.
    nearest_day_threshold=None,

    # 가져올 때 어느 방향으로 가져올지 정함. ('past': 과거의 데이터만, 'future' 미래의 데이터만, 'both': 양쪽 중 가까운 쪽)
    date_direction="past",
)
```

#### 불러오는 데이터

불러오는 데이터는 다음과 같습니다.

```json
{
    "stck_bsop_date": "20200103",
    "stck_clpr": "55500",
    "stck_oprc": "56000",
    "stck_hgpr": "56600",
    "stck_lwpr": "54900",
    "acml_vol": "15422255",
    "acml_tr_pbmn": "860206709400",
    "flng_cls_code": "00",
    "prtt_rate": "0.00",
    "mod_yn": "N",
    "prdy_vrss_sign": "2",
    "prdy_vrss": "300",
    "revl_issu_reas": ""
}
```

이 데이터는 api 원본 그대로로 각각의 의미는 다음과 같습니다. ([출처](https://apiportal.koreainvestment.com/apiservice/apiservice-domestic-stock-quotations#L_3cd9430c-e80e-4671-89a9-bd873dd047ae))

* stck_bsop_date: 날짜
* stck_clpr: 종가
* stck_oprc: 시가
* stck_hgpr: 고가
* stck_lwpr: 저가
* acml_vol: 누적 거래량
* acml_tr_pbmn: 누적 거래 대금
* prtt_rate: 분할 비율 (아마 액면분할 시 그 비율을 의미하는 것으로 보임)
* mod_yn: 분할변경여부 (액면분할 여부로 추정됨)
* prdy_vrss_sign: 전일 대비 부호 (1: 상한, 2: 상승, 3: 보합, 4: 하한, 5: 하락)
* prdy_vrss: 전일 대비
* revl_issu_reas: 재평가사유코드

모든 값을 일차적으로 string을 반환한다는 점을 잊지 마세요.

#### MojitoInvalidResponseError

모히토 모듈은 가끔씩 비정상적인 데이터를 결과로 내놓습니다. 이는 현재로서는 기다리는 것 외엔 해결 방법이 없습니다.

### Transaction Dataclass

Transaction은 한 독립적인 거래를 상징합니다.

#### Transaction의 상태

Transaction의 상태에는 다음과 같은 것들이 있습니다.

* date: 해당 거래가 이루어진 날짜입니다.
* company_code: 해당 회사의 종목 코드입니다.
* amount: 얼마나 사거나 팔았는지를 의미합니다.
    양수라면 매수를 의미하고 음수라면 매도를 의미합니다.
* sell_price: 얼마의 가격에 사거나 팔았는지를 설정합니다.

    이 값은 시가/종가/고가/저가로 정의할 수 있습니다.

    각각 시가는 'open'이고, 종가는 'close', 고가는 'high', 저가는 'low'입니다.

    혹은 직접 정수의 값으로 설정할 수 있습니다. 이때 이 가격은 고가 이하 저가 이상이어야 합니다.

#### Transaction 예시

예를 들어 다음과 같이 Transaction을 정의할 수 있습니다.

```python
from datetime import datetime
from stocks import Transaction

Transaction(
    datetime(2022, 11, 10),  # 2022년 11월 10일에
    '005930',  # 삼성전자를
    3,  # 3개 매수한다.
    'close',  # 일봉의 종가로
)
Transaction(
    datetime(2023, 10, 7),  # 2021년 1월 30일에
    '035720',  # 카카오를
    -24,  # 24개 매도한다.
    43060, # 43060원으로
)
```

### State Dataclass

해당 날짜나 거래 후의 상태를 나타내는 dataclass입니다.

#### State의 상태

State의 상태들은 다음과 같습니다.

* date: 해당하는 날짜입니다.
* total_appraisement: 총 평가액으로, 주식 평가액과 예산을 합친 금액입니다.
* budget: 예산으로, 현재 수중에 돈이 얼마나 있는지를 나타낸 금액입니다.
    이 값을 0으로 놓으면 total_appraisement가 음수일 경우 손실, 양수일 경우 이익이 되어 계산하기에 직관적입니다.
* stocks: 주식들입니다. type은 `dict[str, tuple[int, int]]`로 `dict[종목 코드, tuple[주수, 현재가]]`입니다.
    주수는 음수가 될 수 없습니다.
* privous_state: 이전 State입니다. None일 수도 있습니다.
* transaction: 해당 State의 stocks가 변경되는 데에 어떤 transaction이 기여했을 때 해당 transaction의 값입니다.

#### State 예시

* 실제로 State를 직접 정의해야 하는 상황은 드뭅니다. State가 무엇인지만 알면 충분합니다.

`State.from_previous_state`을 이용해 정의하는 방법은 다음과 같습니다.

```python
from datetime import datetime
from stocks import KEY, State, Transaction, PriceCache

price_cache = PriceCache.from_keys_json(**KEY)

State.from_previous_state(
    price_cache,
    datetime(2022, 6, 12),  # 2022년 6월 12일
    None,  # 이전 상태 없음
    Transaction(datetime(2023, 7, 15), '035720', -20, 'close'),  # 이러한 Transaction을 사용함.
)
```

### emulate_trade 사용하기

`emulate_trade`는 주식 매매 기록을 받으면 예산이나 주식 평가액 등을 계산해서 답을 내는 함수입니다.

#### 사전 준비

price_cache 인스턴스와 transactions(거래 내역)을 준비합니다.

```python
from datetime import datetime

import pandas as pd

from stocks import KEY, PriceCache, emulate_trade, Transaction, State

# 하기 전에 keys.json이 있는지 꼭 확인하세요!!
price_cache = PriceCache.from_keys_json()

# 자신이 원하는 거래 내역을 여기에 설정해주세요.
transactions = [
    Transaction(datetime(2022, 6, 10), '086520', 10, 'open'),
    Transaction(datetime(2022, 11, 10), '005930', 3, 'open'),
    Transaction(datetime(2023, 5, 23), '086520', -10, 'close'),
    Transaction(datetime(2023, 5, 23), '035720', 20, 'close'),
    Transaction(datetime(2023, 5, 23), '005930', 4, 'close'),
    Transaction(datetime(2023, 5, 30), '005930', -7, 'close'),
    Transaction(datetime(2023, 7, 15), '035720', -20, 'close'),
]
```

#### 결과 가져오기

price_cache와 transactions를 emulate_trade에 넘깁니다.

주의할 점은 emulate_trade의 결과값은 dataframe이 아닌 `list[State]`이기 때문에 dataframe으로 변경하려면 `pd.DataFrame()`을 통과시켜야 합니다. (추후에 에초에 Dataframe을 return하는 것으로 변경될 가능성이 있습니다.)

```python
result = pd.DataFrame(emulate_trade(price_cache, transactions, initial_state))
# print로 값을 확인하는 것 대신 jupyter notebook을 사용하는 것을 권장합니다.
# 여기에서는 텍스트로 보여주기 위해 print를 사용합니다.
print(result)
#           date  total_appraisement   budget                   stocks  \
# 0   2022-06-09              100000  1000000                       {}   
# 1   2022-06-10             1000000   249170  {'086520': (10, 75083)}   
# 2   2022-06-11              994170   249170  {'086520': (10, 74500)}   
...
# 401                                               None  
# 402                                               None  
# 403  {'date': 2023-07-15 00:00:00, 'company_code': ...  

# [404 rows x 6 columns]
```

`only_if_transaction_exists`가 True일 경우 transaction이 있었던 날의 State만을 불러옵니다.

```python
result = pd.DataFrame(emulate_trade(price_cache, transactions, initial_state, only_if_transaction_exists=True))
# print로 값을 확인하는 것 대신 jupyter notebook을 사용하는 것을 권장합니다.
# 여기에서는 텍스트로 보여주기 위해 print를 사용합니다.
print(result)
#         date  total_appraisement   budget  \
# 0 2022-06-09              100000  1000000   
# 1 2022-06-10             1000000   249170   
# 2 2022-11-10             1509950    64970   
...
# 5  {'date': 2023-05-23 00:00:00, 'company_code': ...  
# 6  {'date': 2023-05-30 00:00:00, 'company_code': ...  
# 7  {'date': 2023-07-15 00:00:00, 'company_code': ...  
```

#### 주식 수수료 적용

주식에는 수수료와 세금이 있습니다. 수수료는 매매와 매도 시 발생하고 세금은 매도 시에만 발생합니다. 두 금액은 매매한 금액에 비례합니다.

[이 글](https://stockplus.com/m/investing_strategies/articles/1620?scope=all)에 따르면 일반적인 매수 수수료는 0.015%, 매도 수수료 + 세금은 코스피 기준 0.3015%이며, 이 경우 commission을 `(0.00015, 0.003015)`으로 설정해 수수료를 적용할 수 있습니다.

다음과 같이 사용할 수 있습니다.

```python
from datetime import datetime
import pandas as pd
from stocks import monkey_investor, emulate_trade, PriceCache, State, Transaction

price_cache = PriceCache.from_keys_json()

args = monkey_investor(
    price_cache,
    '005930',
    datetime(2021, 1, 1),
    datetime(2021, 12, 31),
    (100, 30),
    36,
    1000,
)

not_commission_considered_result = pd.DataFrame(emulate_trade(*args))
commission_considered_result = pd.DataFrame(emulate_trade(*args, commission=(0.00015, 0.003015)))


initial_state = State.from_previous_state(price_cache, datetime(2021, 1, 1), None, None)
transactions = [Transaction(datetime(2021, 1, 1), company_code='005930', amount=300, sell_price='open')]

stock_itself = pd.DataFrame(emulate_trade(price_cache, transactions, initial_state, datetime(2021, 12, 31)))


total_appraisements = [result['total_appraisement'] for result in (not_commission_considered_result, commission_considered_result)]

df = pd.DataFrame()
df['Commission Not Considered'] = not_commission_considered_result['total_appraisement']
df['Commission Considered'] = commission_considered_result['total_appraisement']
df['Stock Price'] = stock_itself['total_appraisement']

df = df.set_index(not_commission_considered_result['date'])

df.plot(figsize=(10, 8), grid=True)
```

결과는 다음과 같습니다.

![img](images/commission_considered.png)

### 원숭이 투자자

원숭이 투자자란 무작위로 주식을 사거나 파는 모의 투자자를 의미합니다.

원숭이 투자자와의 비교를 통해 자신의 알고리즘이 효율적인지 테스트해볼 수 있습니다.

사용법은 다음과 같습니다.

```python
args = monkey_investor(
    price_cache=price_cache,
    company_code='005930',  # 투자할 회사의 종목 코드
    start_day=datetime(2021, 1, 1),  # 투자 시작일
    end_day=datetime(2021, 12, 31),  # 투자 종료일 (이 값을 포함함)
    invest_amount=(100, 30),  # 투자량, 자료: (평균, 표준편차)
    total_invest_count=36,  # 총 투자수
    seed=10,  # 랜덤값의 시드. None일 경우 별도로 정하지 않음.
)
```

`fetch_prices_by_datetime`와는 다르게 투자 종료일을 포함합니다. 주의해 주세요.

이 함수는 emulate_trade를 실행하지는 않으며, emulate_trade에 바로 사용할 수 있는 인자를 내보냅니다.

이를 unpacking으로 emulate_trade에 넣어 실행할 수 있습니다.

```python
args = monkey_investor(
    price_cache,
    '005930',
    datetime(2021, 1, 1),
    datetime(2021, 12, 31),
    (100, 30),
    36,
    1,
)
result = pd.DataFrame(emulate_trade(*args))
```

#### 응용

여러 원숭이 투자자들을 생성한 뒤 주식 자체의 값과 비교하는 코드는 다음과 같이 작성이 가능합니다.

```python
# 원숭이 투자자를 10개 생성
args_list = (monkey_investor(
    price_cache,
    '005930',
    datetime(2021, 1, 1),
    datetime(2021, 12, 31),
    (100, 30),
    36,
    1000 + i,
) for i in range(10))
results = [pd.DataFrame(emulate_trade(*args)) for args in args_list]

# 주식의 가격 변동을 확인함.
initial_state = State.from_previous_state(price_cache, datetime(2021, 1, 1), None, None)
transactions = [Transaction(datetime(2021, 1, 1), company_code='005930', amount=300, sell_price='open')]

stock_itself = pd.DataFrame(emulate_trade(price_cache, transactions, initial_state, datetime(2021, 12, 31)))

# 플롯 생성
total_appraisements = [result['total_appraisement'] for result in results]

df = pd.DataFrame()
for i, total_appraisement in enumerate(total_appraisements, 1):
    df[f'Monkey #{i}'] = total_appraisement
df['Stock Price'] = stock_itself['total_appraisement']

df = df.set_index(stock_itself['date'])

df.plot(figsize=(10, 8), grid=True, style=[':'] * 10 + ['b-'])
```

생성된 그래프는 다음과 같습니다.
![Plot shows total appraisement](images/monkey_investors.png)

### 다양한 데이터로 플롯 그리기

한 원숭이 투자자에 대한 주식 보유수와 주식 평가액으로 그린 플롯은 다음과 같습니다.

```python
from datetime import datetime

import pandas as pd
import matplotlib.pyplot as plt

from stocks import emulate_trade, PriceCache, monkey_investor

price_cache = PriceCache.from_keys_json()

args = monkey_investor(
    price_cache,
    '005930',
    datetime(2021, 1, 1),
    datetime(2021, 12, 31),
    (100, 30),
    36,
    1234,
)
result = pd.DataFrame(emulate_trade(*args))

fig, ax1 = plt.subplots()

color = 'tab:red'
ax1.set_xlabel('date')
ax1.set_ylabel('stock amount', color='tab:red')
ax1.plot(result['date'], [stock.get('005930', (0, 0))[0] for stock in result['stocks']], color=color)
ax1.set_ylim(-1500, 1500)
ax1.tick_params(axis='y', labelcolor=color)

ax2 = ax1.twinx()

color = 'tab:blue'
ax2.set_ylabel('total appraisement', color='tab:blue')
ax2.plot(result['date'],
         [total_appraisement for total_appraisement in result['total_appraisement']], color=color)
ax2.set_ylim(-15_000_000, 15_000_000)
ax2.tick_params(axis='y', labelcolor=color)

fig.tight_layout()
plt.grid(True)
plt.show()
```

생성된 그래프는 다음과 같습니다.

![plot about multiple data](images/multi_data.png)

### 주식 통계 계산하기

MDD, CAGR, 주식 변동성은 `stock_statistics` 모듈로 계산할 수 있습니다.

```python
from datetime import datetime

import mojito

from stocks import KEY, emulate_trade, monkey_investor, PriceCache
from stocks.stock_statistics import MDD, CAGR, stock_volatility

broker = mojito.KoreaInvestment(**KEY)
price_cache = PriceCache(broker)

args = list(monkey_investor(
    price_cache=price_cache,
    company_code='005930',
    start_day=datetime(2021, 1, 1),
    end_day=datetime(2021, 12, 31),
    invest_amount=(100, 30),
    total_invest_count=36,
    seed=10,
))

# Changing initial state
args[2].budget = 100_000_000  # type: ignore
args[2].total_appraisement = 100_000_000  # type: ignore

states = emulate_trade(*args)  # type: ignore

print(MDD(states))
print(CAGR(states))
print(stock_volatility(broker, '009530', 'D', datetime(2021, 1, 1), datetime(2021, 12, 31)))
```

### 주차별 Changelog

주의: 기능을 사용하기 전에 `git fetch`를 통해 업데이트해주세요.

1. 3주차 (~23/11/08)

    PriceDict 추가, PriceCache에 from_keys_json 추가, PriceCache의 get_price의 리턴값 변경, 여러 모듈 이름 변경, numpy int64 관련 버그 수정, Transaction에 check_price_unit 추가, stocks의 count가 음수가 되지 않도록 변경, emulate_trade에 final_date 추가, monkey_investor 및 stock_statistics 추가, commission 추가, 기본 import 개수 증가

1. 2주차 (~23/10/30)

    State, Transaction, emulate_trade 추가

1. 1주차

    프로젝트 시작, KEY 추가, adjust_price_unit 함수 추가

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "stock-tools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11.0,<3.12.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "ilotoki0804",
    "author_email": "ilotoki0804@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/50/e7/acf46b6054399357206029554bf91b62ceaa2b0900f6461f170c16d187fe/stock_tools-0.1.1.tar.gz",
    "platform": null,
    "description": "# stock-tools\n\n\uc54c\uace0\ub9ac\uc998 \uc8fc\uc2dd \ud22c\uc790\ub97c \uc704\ud55c \uc5ec\ub7ec \ud234\uc744 \ubaa8\uc544\ub193\uc740 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc785\ub2c8\ub2e4. \uc8fc\uc2dd \ub370\uc774\ud130 \ubd88\ub7ec\uc624\uae30, \ud638\uac00 \ub2e8\uc704 \ub9de\ucd94\uae30, \uc8fc\uc2dd \ub9e4\ub9e4 \uc2dc\ubbac\ub808\uc774\uc158\ud558\uae30, \uc6d0\uc22d\uc774 \ud22c\uc790\uc790(\uc784\uc758\ub85c \uc0ac\uace0 \ud314\uae30\ub97c \ubc18\ubcf5\ud558\ub294 \uc784\uc758\uc758 \ud22c\uc790\uc790), \ud1b5\uacc4 \uacc4\uc0b0 \uc678\uc5d0\ub3c4 \ub9ce\uc740 \uae30\ub2a5\uc744 \uc9c0\uc6d0\ud569\ub2c8\ub2e4.\n\n## \uc124\uce58 \ubc29\ubc95\n\n\ub2e4\uc74c\uc758 \uba85\ub839\uc5b4\ub97c \ud1b5\ud574 \uc124\uce58 \ubc0f \uc5c5\ub370\uc774\ud2b8\ub97c \ud558\uc2e4 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n```console\npip install stock-tools -U\n```\n\n\uadf8\ub7f0 \ub2e4\uc74c \ub2e4\uc74c\uc758 \uba85\ub839\uc5b4\ub97c \uc0ac\uc6a9\ud574 \uc81c\ub300\ub85c \uc124\uce58\uac00 \ub418\uc5c8\ub294\uc9c0 \ud655\uc778\ud558\uc138\uc694.\n\n> [!NOTE]\n> keys.json\uc774 \uc5c6\ub2e4\ub294 \uc624\ub958 \uba54\uc2dc\uc9c0\uac00 \ub730 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774 \uacbd\uc6b0 keys.json\uc744 \uc124\uba85\ud558\ub294 \uc139\uc158\uc5d0\uc11c \uc124\uba85\ud558\ub294 keys.json \ud30c\uc77c\uc744 \ub9cc\ub4dc\uc138\uc694.\n\n```python\nimport stock_tools\n```\n\n### keys.json\n\nKEY \uc0c1\uc218\ub97c \uc0ac\uc6a9\ud558\ub824\uba74 \ub8e8\ud2b8 \ub514\ub809\ud1a0\ub9ac\uc5d0 `keys.json`\uc774 \uc788\uc5b4\uc57c \ud569\ub2c8\ub2e4.\n\n\uc6b0\ub9ac \ud300\uc758 `keys.json`\uc740 \ub514\uc2a4\ucf54\ub4dc\uc5d0 \uc5c5\ub85c\ub4dc\ub418\uc5b4 \uc788\uc73c\ub2c8 \uc0ac\uc6a9\ud558\uc2dc\uba74 \ub429\ub2c8\ub2e4.\n\n`keys.json`\uc740 \ub2e4\uc74c\uacfc \uac19\uc740 \ud615\uc2dd\uc73c\ub85c \ub9cc\ub4e4\uba74 \ub429\ub2c8\ub2e4.\n\n```json\n{\n    \"api_key\": \"...\",\n    \"api_secret\": \"...\",\n    \"acc_no\": \"...\"\n}\n```\n\n\uc124\uba85\uc740 \uc544\ub798\uc758 '\uc0ac\uc6a9\ubc95'\uc744 \ucc38\uace0\ud558\uc138\uc694.\n\n### \uae30\ubcf8 import\n\n\uc774 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc5d0\ub294 \ub9ce\uc740 \ud30c\uc77c\ub4e4\uc774 \uc788\uace0, \ub300\ubd80\ubd84\uc740 top level\uc5d0\uc11c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uadf8\ub7ec\ub098 `fetch` \ubaa8\ub4c8\uacfc `stock_statistics` \ubaa8\ub4c8\uc740 \ubb36\uc5ec \uc788\ub294 \uac83\uc774 \ub354\uc6b1 \uc5b4\uc6b8\ub9ac\ub294 \ubaa8\ub4c8\uc774\uae30\uc5d0 \uc9c1\uc811 import \uac00 \ud544\uc694\ud569\ub2c8\ub2e4.\n\n```python\nfrom stocks import PriceCache, Transaction  # \ub300\ubd80\ubd84\uc758 \ubaa8\ub4c8\ub4e4\uc740 \ubc14\ub85c \uc0ac\uc6a9 \uac00\ub2a5\ud569\ub2c8\ub2e4.\nfrom stocks.fetch import fetch_prices_by_datetime  # fetch\uc640 stock_statistics\ub294 \uc9c1\uc811 import\ud574\uc57c \ud569\ub2c8\ub2e4.\nfrom stocks.stock_statistics import stock_volatility\n```\n\n## \uc0ac\uc6a9\ubc95\n\n### KEY \uc0ac\uc6a9\ud558\uae30\n\nKEY\ub97c \uc774\uc6a9\ud558\ub824\uba74 \uc6b0\uc120 `keys.json`\uc744 \ud3f4\ub354\uc5d0 \ub123\uc5b4\uc57c \ud569\ub2c8\ub2e4. \uc790\uc138\ud55c \ubc29\ubc95\uc740 '\uc124\uce58 \ubc29\ubc95'\uc744 \ucc38\uace0\ud558\uc138\uc694.\n\n`keys.json`\uc774 \uc124\uce58\ub418\uc5c8\ub2e4\uba74 \ub2e4\uc74c\uacfc \uac19\uc774 \uac04\ud3b8\ud558\uac8c mojito\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n```python\nfrom stocks import adjust_price_unit, KEY\nimport mojito\n\nbroker = mojito.KoreaInvestment(**KEY)\n...\n```\n\n### adjust_price_unit \uc0ac\uc6a9\ud558\uae30\n\n`adjust_price_unit`\uc740 \uc9c0\uc815\uac00 \ub9e4\uc218 \uc2dc \ud638\uac00 \ub2e8\uc704\ub97c \ub9de\ucd9c \uc218 \uc788\ub3c4\ub85d \ud569\ub2c8\ub2e4. \uc790\uc138\ud55c \uc124\uba85\uc740 `adjust_price_unit`\uc758 docs\uc640 \ud574\ub2f9 \ud568\uc218\uac00 \uc120\uc5b8\ub41c \ubaa8\ub4c8\uc758 docs\ub97c \ucc38\uace0\ud558\uc138\uc694.\n\n### \ub9e4\uc218, \ub9e4\ub3c4 \ub4f1 \uc0ac\uc6a9 \ubc0f \uc608\uc81c \ud655\uc778\ud558\uae30\n\nRepo \ub0b4 examples.py\uc5d0\ub294 \uc5b4\ub5bb\uac8c adjust_price_unit\ub97c \uc0ac\uc6a9\ud558\ub294\uc9c0\uc640 \ub9e4\uc218, \ub9e4\ub3c4\ub97c \uc5b4\ub5bb\uac8c \ud558\ub294 \uc9c0\uc5d0 \ub300\ud55c \uc608\uc81c\uac00 \uc788\uc2b5\ub2c8\ub2e4. \ud574\ub2f9 \ub0b4\uc6a9\uc744 \ucc38\uace0\ud558\uc138\uc694.\n\n### \uac00\uaca9 \ubd88\ub7ec\uc624\uae30\n\n\uac00\uaca9\uc744 \ubd88\ub7ec\uc624\ub294 \ubc29\uc2dd\uc740 \uc138 \uac00\uc9c0\uac00 \uc788\uc2b5\ub2c8\ub2e4.\n\n1. PriceCache: \ud558\ub8e8\uc758 \ub370\uc774\ud130\ub97c \uc54c\uace0 \uc2f6\uc740 \uacbd\uc6b0 \uc0ac\uc6a9\n1. fetch.fetch_prices_by_datetime: \uae30\uac04\uc758 \ub370\uc774\ud130\ub97c \uc54c\uace0 \uc2f6\uc740 \uacbd\uc6b0 \uc0ac\uc6a9\n1. fetch._fetch_prices_unsafe: \uc704\uc640 \ub3d9\uc77c\ud558\uace0 \ub354 \ube60\ub974\uc9c0\ub9cc 100\uc77c \uc774\uc0c1\uc758 \ub370\uc774\ud130\ub97c \ubd88\ub7ec\uc62c \uc218 \uc5c6\uc74c.\n\n\uc77c\ubc18\uc801\uc73c\ub85c 3\ubc88\uc744 \uc0ac\uc6a9\ud560 \uc77c\uc740 \uc801\uc744 \uac83\uc774\uace0 PriceCache\ub098 fetch_prices_by_datetime\uc744 \uc0ac\uc6a9\ud558\uac8c \ub420 \uac00\ub2a5\uc131\uc774 \ub192\uc2b5\ub2c8\ub2e4.\n\nPriceCache\uacfc fetch_prices_by_datetime\uc758 \ucc28\uc774\uc810\uc740 \uae30\uac04\uc73c\ub85c \ubd88\ub7ec\uc62c \uc218 \uc788\ub294\uc9c0\uc640 \uc544\ub2cc\uc9c0\uc758 \ucc28\uc774\ub3c4 \uc788\uc9c0\ub9cc \uacb0\uc815\uc801\uc778 \uac83\uc740 \ubc14\ub85c \uce90\uc2f1\uc758 \uc5ec\ubd80\uc785\ub2c8\ub2e4.\n\uce90\uc2f1\uc774\ub780 \ub370\uc774\ud130\ub97c \uc11c\ubc84\uc5d0\uc11c \ubd88\ub7ec\uc628 \ud6c4 \ub9cc\uc57d \uc774\ubbf8 \uc804\uc5d0 \ubd88\ub7ec\uc628 \ub370\uc774\ud130\ub77c\uba74 \uc11c\ubc84\ub97c \uacbd\uc720\ud558\uc9c0 \uc54a\uace0 \uc800\uc7a5\ub418\uc5b4 \uc788\ub358 \ub370\uc774\ud130\uc5d0\uc11c \uac00\uc838\uc624\ub294 \uac83\uc744 \uc758\ubbf8\ud569\ub2c8\ub2e4.\nfetch_prices_by_datetime\ub294 \uce90\uc2f1\uc774 \ub418\uc9c0 \uc54a\uc9c0\ub9cc PriceCache\ub294 \uce90\uc2f1\uc774 \ub429\ub2c8\ub2e4.\n\n\uce90\uc2f1\uc744 \uc0ac\uc6a9\ud55c\ub2e4\uba74 \uac19\uc740 \ub370\uc774\ud130\ub97c \uc5ec\ub7ec \ubc88 \uc0ac\uc6a9\ud558\ub294 \uacbd\uc6b0 \uc18d\ub3c4\ub97c \ub192\uc77c \uc218 \uc788\uae30 \ub54c\ubb38\uc5d0 \ud2b9\ubcc4\ud55c \uacbd\uc6b0\ub97c \uc81c\uc678\ud558\uba74 fetch_prices_by_datetime \ub300\uc2e0 PriceCache\ub97c \uc0ac\uc6a9\ud558\ub294 \uac83\uc744 \uad8c\uc7a5\ud569\ub2c8\ub2e4.\n\n#### fetch_prices_by_datetime \uc0ac\uc6a9\ud558\uae30\n\nfetch_prices_by_datetime\uc740 \ub2e4\uc74c\uacfc \uac19\uc774 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n```python\nfrom datetime import datetime\nimport mojito\nfrom stocks import KEY\nfrom stocks.fetch import _fetch_prices_unsafe, fetch_prices_by_datetime\n\nbroker = mojito.KoreaInvestment(**KEY)\n\nfetch_prices_by_datetime(\n    broker=broker,\n    company_code=\"005930\",  # \uc885\ubaa9 \ucf54\ub4dc\n    date_type='D',  # \uc77c\ubd09 \uc0ac\uc6a9 ('D', 'M', 'Y' \uc0ac\uc6a9 \uac00\ub2a5)\n    start_day=datetime(2019, 5, 7),  # 2019\ub144 5\uc6d4 7\uc77c\ubd80\ud130\n    end_day=datetime(2023, 2, 15),  # 2023\ub144 2\uc6d4 14\uc77c\uae4c\uc9c0 (2\uc6d4 15\uc77c \ub370\uc774\ud130\ub294 \ud3ec\ud568\ub418\uc9c0 \uc54a\uc74c!!!)\n)\n```\n\n\uc5ec\uae30\uc5d0\uc11c \uc8fc\uc758\ud574\uc57c \ud560 \uc810\uc740 \ud30c\uc774\uc36c\uc758 `range()`\ub098 slicing\ucc98\ub7fc end_day\uc5d0 \uadf8 \ub2f9\uc77c\uc740 \ud3ec\ud568\ub418\uc9c0 \uc54a\ub294\ub2e4\ub294 \uc810\uc785\ub2c8\ub2e4.\nmojito \ubaa8\ub4c8\uacfc \uc774 \ubd80\ubd84\uc5d0\uc11c \ub2e4\ub974\ub2c8 \uc8fc\uc758\ud558\uc138\uc694.\n\n#### PriceCache \uc0ac\uc6a9\ud558\uae30\n\nPriceCache\ubaa8\ub4c8\uc740 \ub2e4\uc74c\uacfc \uac19\uc774 \uc0ac\uc6a9\uc774 \uac00\ub2a5\ud569\ub2c8\ub2e4.\n\n```python\nfrom datetime import datetime\n\nfrom stocks import PriceCache\n\nprice_cache = PriceCache.from_keys_json(\n    default_company_code='005930', # \uae30\ubcf8 \uc885\ubaa9 \ucf54\ub4dc\uac00 \uc124\uc815\ub418\uc5c8\uae30 \ub54c\ubb38\uc5d0 get_price\uc5d0\uc11c company_code\ub97c \uc0dd\ub7b5\ud560 \uc218\ub3c4 \uc788\uc74c.\n)\n\n# \ud639\uc740 brocker\ub97c \uc9c1\uc811 \ub118\uaca8\uc904 \uc218\ub3c4 \uc788\uc2b5\ub2c8\ub2e4.\nbroker = mojito.KoreaInvestment(**KEY)\nprice_cache = PriceCache(\n    broker=broker,\n    default_company_code=None,  # None\uc774\uae30 \ub54c\ubb38\uc5d0 get_price\uc5d0\uc11c\ub294 \ud56d\uc0c1 company_code\ub97c \uc815\uc758\ud574\uc57c \ud568.\n)\n\nprice_cache.get_price(\n    # \uac12\uc744 \uac00\uc838\uc62c \ub0a0\uc9dc.\n    day=datetime(2020, 1, 4),\n\n    # \uc774 \uac12\uc740 \ub9cc\uc57d \uc0dd\ub7b5\ub410\ub2e4\uba74 default_company_code\uc5d0 \ub118\uaca8\uc900 \uac12\uc744 \uc0ac\uc6a9\ud558\uace0, \ub9cc\uc57d \ub118\uaca8\uc9c4 \uac12\uc774 \uc5c6\ub2e4\uba74 \uc624\ub958\uac00 \ub0a8.\n    company_code=\"005930\",\n\n    # \uc5bc\ub9c8\ub098 \uac00\uae4c\uc6b4 \ub0a0\uc9dc\uae4c\uc9c0 \uc0ac\uc6a9\ud560\uc9c0 \uc815\ud568. None\uc77c \uacbd\uc6b0 100\uc77c\ub85c \uc124\uc815\ub428.\n    nearest_day_threshold=None,\n\n    # \uac00\uc838\uc62c \ub54c \uc5b4\ub290 \ubc29\ud5a5\uc73c\ub85c \uac00\uc838\uc62c\uc9c0 \uc815\ud568. ('past': \uacfc\uac70\uc758 \ub370\uc774\ud130\ub9cc, 'future' \ubbf8\ub798\uc758 \ub370\uc774\ud130\ub9cc, 'both': \uc591\ucabd \uc911 \uac00\uae4c\uc6b4 \ucabd)\n    date_direction=\"past\",\n)\n```\n\n#### \ubd88\ub7ec\uc624\ub294 \ub370\uc774\ud130\n\n\ubd88\ub7ec\uc624\ub294 \ub370\uc774\ud130\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\n\n```json\n{\n    \"stck_bsop_date\": \"20200103\",\n    \"stck_clpr\": \"55500\",\n    \"stck_oprc\": \"56000\",\n    \"stck_hgpr\": \"56600\",\n    \"stck_lwpr\": \"54900\",\n    \"acml_vol\": \"15422255\",\n    \"acml_tr_pbmn\": \"860206709400\",\n    \"flng_cls_code\": \"00\",\n    \"prtt_rate\": \"0.00\",\n    \"mod_yn\": \"N\",\n    \"prdy_vrss_sign\": \"2\",\n    \"prdy_vrss\": \"300\",\n    \"revl_issu_reas\": \"\"\n}\n```\n\n\uc774 \ub370\uc774\ud130\ub294 api \uc6d0\ubcf8 \uadf8\ub300\ub85c\ub85c \uac01\uac01\uc758 \uc758\ubbf8\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4. ([\ucd9c\ucc98](https://apiportal.koreainvestment.com/apiservice/apiservice-domestic-stock-quotations#L_3cd9430c-e80e-4671-89a9-bd873dd047ae))\n\n* stck_bsop_date: \ub0a0\uc9dc\n* stck_clpr: \uc885\uac00\n* stck_oprc: \uc2dc\uac00\n* stck_hgpr: \uace0\uac00\n* stck_lwpr: \uc800\uac00\n* acml_vol: \ub204\uc801 \uac70\ub798\ub7c9\n* acml_tr_pbmn: \ub204\uc801 \uac70\ub798 \ub300\uae08\n* prtt_rate: \ubd84\ud560 \ube44\uc728 (\uc544\ub9c8 \uc561\uba74\ubd84\ud560 \uc2dc \uadf8 \ube44\uc728\uc744 \uc758\ubbf8\ud558\ub294 \uac83\uc73c\ub85c \ubcf4\uc784)\n* mod_yn: \ubd84\ud560\ubcc0\uacbd\uc5ec\ubd80 (\uc561\uba74\ubd84\ud560 \uc5ec\ubd80\ub85c \ucd94\uc815\ub428)\n* prdy_vrss_sign: \uc804\uc77c \ub300\ube44 \ubd80\ud638 (1: \uc0c1\ud55c, 2: \uc0c1\uc2b9, 3: \ubcf4\ud569, 4: \ud558\ud55c, 5: \ud558\ub77d)\n* prdy_vrss: \uc804\uc77c \ub300\ube44\n* revl_issu_reas: \uc7ac\ud3c9\uac00\uc0ac\uc720\ucf54\ub4dc\n\n\ubaa8\ub4e0 \uac12\uc744 \uc77c\ucc28\uc801\uc73c\ub85c string\uc744 \ubc18\ud658\ud55c\ub2e4\ub294 \uc810\uc744 \uc78a\uc9c0 \ub9c8\uc138\uc694.\n\n#### MojitoInvalidResponseError\n\n\ubaa8\ud788\ud1a0 \ubaa8\ub4c8\uc740 \uac00\ub054\uc529 \ube44\uc815\uc0c1\uc801\uc778 \ub370\uc774\ud130\ub97c \uacb0\uacfc\ub85c \ub0b4\ub193\uc2b5\ub2c8\ub2e4. \uc774\ub294 \ud604\uc7ac\ub85c\uc11c\ub294 \uae30\ub2e4\ub9ac\ub294 \uac83 \uc678\uc5d4 \ud574\uacb0 \ubc29\ubc95\uc774 \uc5c6\uc2b5\ub2c8\ub2e4.\n\n### Transaction Dataclass\n\nTransaction\uc740 \ud55c \ub3c5\ub9bd\uc801\uc778 \uac70\ub798\ub97c \uc0c1\uc9d5\ud569\ub2c8\ub2e4.\n\n#### Transaction\uc758 \uc0c1\ud0dc\n\nTransaction\uc758 \uc0c1\ud0dc\uc5d0\ub294 \ub2e4\uc74c\uacfc \uac19\uc740 \uac83\ub4e4\uc774 \uc788\uc2b5\ub2c8\ub2e4.\n\n* date: \ud574\ub2f9 \uac70\ub798\uac00 \uc774\ub8e8\uc5b4\uc9c4 \ub0a0\uc9dc\uc785\ub2c8\ub2e4.\n* company_code: \ud574\ub2f9 \ud68c\uc0ac\uc758 \uc885\ubaa9 \ucf54\ub4dc\uc785\ub2c8\ub2e4.\n* amount: \uc5bc\ub9c8\ub098 \uc0ac\uac70\ub098 \ud314\uc558\ub294\uc9c0\ub97c \uc758\ubbf8\ud569\ub2c8\ub2e4.\n    \uc591\uc218\ub77c\uba74 \ub9e4\uc218\ub97c \uc758\ubbf8\ud558\uace0 \uc74c\uc218\ub77c\uba74 \ub9e4\ub3c4\ub97c \uc758\ubbf8\ud569\ub2c8\ub2e4.\n* sell_price: \uc5bc\ub9c8\uc758 \uac00\uaca9\uc5d0 \uc0ac\uac70\ub098 \ud314\uc558\ub294\uc9c0\ub97c \uc124\uc815\ud569\ub2c8\ub2e4.\n\n    \uc774 \uac12\uc740 \uc2dc\uac00/\uc885\uac00/\uace0\uac00/\uc800\uac00\ub85c \uc815\uc758\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n    \uac01\uac01 \uc2dc\uac00\ub294 'open'\uc774\uace0, \uc885\uac00\ub294 'close', \uace0\uac00\ub294 'high', \uc800\uac00\ub294 'low'\uc785\ub2c8\ub2e4.\n\n    \ud639\uc740 \uc9c1\uc811 \uc815\uc218\uc758 \uac12\uc73c\ub85c \uc124\uc815\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c \uc774 \uac00\uaca9\uc740 \uace0\uac00 \uc774\ud558 \uc800\uac00 \uc774\uc0c1\uc774\uc5b4\uc57c \ud569\ub2c8\ub2e4.\n\n#### Transaction \uc608\uc2dc\n\n\uc608\ub97c \ub4e4\uc5b4 \ub2e4\uc74c\uacfc \uac19\uc774 Transaction\uc744 \uc815\uc758\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n```python\nfrom datetime import datetime\nfrom stocks import Transaction\n\nTransaction(\n    datetime(2022, 11, 10),  # 2022\ub144 11\uc6d4 10\uc77c\uc5d0\n    '005930',  # \uc0bc\uc131\uc804\uc790\ub97c\n    3,  # 3\uac1c \ub9e4\uc218\ud55c\ub2e4.\n    'close',  # \uc77c\ubd09\uc758 \uc885\uac00\ub85c\n)\nTransaction(\n    datetime(2023, 10, 7),  # 2021\ub144 1\uc6d4 30\uc77c\uc5d0\n    '035720',  # \uce74\uce74\uc624\ub97c\n    -24,  # 24\uac1c \ub9e4\ub3c4\ud55c\ub2e4.\n    43060, # 43060\uc6d0\uc73c\ub85c\n)\n```\n\n### State Dataclass\n\n\ud574\ub2f9 \ub0a0\uc9dc\ub098 \uac70\ub798 \ud6c4\uc758 \uc0c1\ud0dc\ub97c \ub098\ud0c0\ub0b4\ub294 dataclass\uc785\ub2c8\ub2e4.\n\n#### State\uc758 \uc0c1\ud0dc\n\nState\uc758 \uc0c1\ud0dc\ub4e4\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\n\n* date: \ud574\ub2f9\ud558\ub294 \ub0a0\uc9dc\uc785\ub2c8\ub2e4.\n* total_appraisement: \ucd1d \ud3c9\uac00\uc561\uc73c\ub85c, \uc8fc\uc2dd \ud3c9\uac00\uc561\uacfc \uc608\uc0b0\uc744 \ud569\uce5c \uae08\uc561\uc785\ub2c8\ub2e4.\n* budget: \uc608\uc0b0\uc73c\ub85c, \ud604\uc7ac \uc218\uc911\uc5d0 \ub3c8\uc774 \uc5bc\ub9c8\ub098 \uc788\ub294\uc9c0\ub97c \ub098\ud0c0\ub0b8 \uae08\uc561\uc785\ub2c8\ub2e4.\n    \uc774 \uac12\uc744 0\uc73c\ub85c \ub193\uc73c\uba74 total_appraisement\uac00 \uc74c\uc218\uc77c \uacbd\uc6b0 \uc190\uc2e4, \uc591\uc218\uc77c \uacbd\uc6b0 \uc774\uc775\uc774 \ub418\uc5b4 \uacc4\uc0b0\ud558\uae30\uc5d0 \uc9c1\uad00\uc801\uc785\ub2c8\ub2e4.\n* stocks: \uc8fc\uc2dd\ub4e4\uc785\ub2c8\ub2e4. type\uc740 `dict[str, tuple[int, int]]`\ub85c `dict[\uc885\ubaa9 \ucf54\ub4dc, tuple[\uc8fc\uc218, \ud604\uc7ac\uac00]]`\uc785\ub2c8\ub2e4.\n    \uc8fc\uc218\ub294 \uc74c\uc218\uac00 \ub420 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4.\n* privous_state: \uc774\uc804 State\uc785\ub2c8\ub2e4. None\uc77c \uc218\ub3c4 \uc788\uc2b5\ub2c8\ub2e4.\n* transaction: \ud574\ub2f9 State\uc758 stocks\uac00 \ubcc0\uacbd\ub418\ub294 \ub370\uc5d0 \uc5b4\ub5a4 transaction\uc774 \uae30\uc5ec\ud588\uc744 \ub54c \ud574\ub2f9 transaction\uc758 \uac12\uc785\ub2c8\ub2e4.\n\n#### State \uc608\uc2dc\n\n* \uc2e4\uc81c\ub85c State\ub97c \uc9c1\uc811 \uc815\uc758\ud574\uc57c \ud558\ub294 \uc0c1\ud669\uc740 \ub4dc\ubb45\ub2c8\ub2e4. State\uac00 \ubb34\uc5c7\uc778\uc9c0\ub9cc \uc54c\uba74 \ucda9\ubd84\ud569\ub2c8\ub2e4.\n\n`State.from_previous_state`\uc744 \uc774\uc6a9\ud574 \uc815\uc758\ud558\ub294 \ubc29\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\n\n```python\nfrom datetime import datetime\nfrom stocks import KEY, State, Transaction, PriceCache\n\nprice_cache = PriceCache.from_keys_json(**KEY)\n\nState.from_previous_state(\n    price_cache,\n    datetime(2022, 6, 12),  # 2022\ub144 6\uc6d4 12\uc77c\n    None,  # \uc774\uc804 \uc0c1\ud0dc \uc5c6\uc74c\n    Transaction(datetime(2023, 7, 15), '035720', -20, 'close'),  # \uc774\ub7ec\ud55c Transaction\uc744 \uc0ac\uc6a9\ud568.\n)\n```\n\n### emulate_trade \uc0ac\uc6a9\ud558\uae30\n\n`emulate_trade`\ub294 \uc8fc\uc2dd \ub9e4\ub9e4 \uae30\ub85d\uc744 \ubc1b\uc73c\uba74 \uc608\uc0b0\uc774\ub098 \uc8fc\uc2dd \ud3c9\uac00\uc561 \ub4f1\uc744 \uacc4\uc0b0\ud574\uc11c \ub2f5\uc744 \ub0b4\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.\n\n#### \uc0ac\uc804 \uc900\ube44\n\nprice_cache \uc778\uc2a4\ud134\uc2a4\uc640 transactions(\uac70\ub798 \ub0b4\uc5ed)\uc744 \uc900\ube44\ud569\ub2c8\ub2e4.\n\n```python\nfrom datetime import datetime\n\nimport pandas as pd\n\nfrom stocks import KEY, PriceCache, emulate_trade, Transaction, State\n\n# \ud558\uae30 \uc804\uc5d0 keys.json\uc774 \uc788\ub294\uc9c0 \uaf2d \ud655\uc778\ud558\uc138\uc694!!\nprice_cache = PriceCache.from_keys_json()\n\n# \uc790\uc2e0\uc774 \uc6d0\ud558\ub294 \uac70\ub798 \ub0b4\uc5ed\uc744 \uc5ec\uae30\uc5d0 \uc124\uc815\ud574\uc8fc\uc138\uc694.\ntransactions = [\n    Transaction(datetime(2022, 6, 10), '086520', 10, 'open'),\n    Transaction(datetime(2022, 11, 10), '005930', 3, 'open'),\n    Transaction(datetime(2023, 5, 23), '086520', -10, 'close'),\n    Transaction(datetime(2023, 5, 23), '035720', 20, 'close'),\n    Transaction(datetime(2023, 5, 23), '005930', 4, 'close'),\n    Transaction(datetime(2023, 5, 30), '005930', -7, 'close'),\n    Transaction(datetime(2023, 7, 15), '035720', -20, 'close'),\n]\n```\n\n#### \uacb0\uacfc \uac00\uc838\uc624\uae30\n\nprice_cache\uc640 transactions\ub97c emulate_trade\uc5d0 \ub118\uae41\ub2c8\ub2e4.\n\n\uc8fc\uc758\ud560 \uc810\uc740 emulate_trade\uc758 \uacb0\uacfc\uac12\uc740 dataframe\uc774 \uc544\ub2cc `list[State]`\uc774\uae30 \ub54c\ubb38\uc5d0 dataframe\uc73c\ub85c \ubcc0\uacbd\ud558\ub824\uba74 `pd.DataFrame()`\uc744 \ud1b5\uacfc\uc2dc\ucf1c\uc57c \ud569\ub2c8\ub2e4. (\ucd94\ud6c4\uc5d0 \uc5d0\ucd08\uc5d0 Dataframe\uc744 return\ud558\ub294 \uac83\uc73c\ub85c \ubcc0\uacbd\ub420 \uac00\ub2a5\uc131\uc774 \uc788\uc2b5\ub2c8\ub2e4.)\n\n```python\nresult = pd.DataFrame(emulate_trade(price_cache, transactions, initial_state))\n# print\ub85c \uac12\uc744 \ud655\uc778\ud558\ub294 \uac83 \ub300\uc2e0 jupyter notebook\uc744 \uc0ac\uc6a9\ud558\ub294 \uac83\uc744 \uad8c\uc7a5\ud569\ub2c8\ub2e4.\n# \uc5ec\uae30\uc5d0\uc11c\ub294 \ud14d\uc2a4\ud2b8\ub85c \ubcf4\uc5ec\uc8fc\uae30 \uc704\ud574 print\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.\nprint(result)\n#           date  total_appraisement   budget                   stocks  \\\n# 0   2022-06-09              100000  1000000                       {}   \n# 1   2022-06-10             1000000   249170  {'086520': (10, 75083)}   \n# 2   2022-06-11              994170   249170  {'086520': (10, 74500)}   \n...\n# 401                                               None  \n# 402                                               None  \n# 403  {'date': 2023-07-15 00:00:00, 'company_code': ...  \n\n# [404 rows x 6 columns]\n```\n\n`only_if_transaction_exists`\uac00 True\uc77c \uacbd\uc6b0 transaction\uc774 \uc788\uc5c8\ub358 \ub0a0\uc758 State\ub9cc\uc744 \ubd88\ub7ec\uc635\ub2c8\ub2e4.\n\n```python\nresult = pd.DataFrame(emulate_trade(price_cache, transactions, initial_state, only_if_transaction_exists=True))\n# print\ub85c \uac12\uc744 \ud655\uc778\ud558\ub294 \uac83 \ub300\uc2e0 jupyter notebook\uc744 \uc0ac\uc6a9\ud558\ub294 \uac83\uc744 \uad8c\uc7a5\ud569\ub2c8\ub2e4.\n# \uc5ec\uae30\uc5d0\uc11c\ub294 \ud14d\uc2a4\ud2b8\ub85c \ubcf4\uc5ec\uc8fc\uae30 \uc704\ud574 print\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.\nprint(result)\n#         date  total_appraisement   budget  \\\n# 0 2022-06-09              100000  1000000   \n# 1 2022-06-10             1000000   249170   \n# 2 2022-11-10             1509950    64970   \n...\n# 5  {'date': 2023-05-23 00:00:00, 'company_code': ...  \n# 6  {'date': 2023-05-30 00:00:00, 'company_code': ...  \n# 7  {'date': 2023-07-15 00:00:00, 'company_code': ...  \n```\n\n#### \uc8fc\uc2dd \uc218\uc218\ub8cc \uc801\uc6a9\n\n\uc8fc\uc2dd\uc5d0\ub294 \uc218\uc218\ub8cc\uc640 \uc138\uae08\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc218\uc218\ub8cc\ub294 \ub9e4\ub9e4\uc640 \ub9e4\ub3c4 \uc2dc \ubc1c\uc0dd\ud558\uace0 \uc138\uae08\uc740 \ub9e4\ub3c4 \uc2dc\uc5d0\ub9cc \ubc1c\uc0dd\ud569\ub2c8\ub2e4. \ub450 \uae08\uc561\uc740 \ub9e4\ub9e4\ud55c \uae08\uc561\uc5d0 \ube44\ub840\ud569\ub2c8\ub2e4.\n\n[\uc774 \uae00](https://stockplus.com/m/investing_strategies/articles/1620?scope=all)\uc5d0 \ub530\ub974\uba74 \uc77c\ubc18\uc801\uc778 \ub9e4\uc218 \uc218\uc218\ub8cc\ub294 0.015%, \ub9e4\ub3c4 \uc218\uc218\ub8cc + \uc138\uae08\uc740 \ucf54\uc2a4\ud53c \uae30\uc900 0.3015%\uc774\uba70, \uc774 \uacbd\uc6b0 commission\uc744 `(0.00015, 0.003015)`\uc73c\ub85c \uc124\uc815\ud574 \uc218\uc218\ub8cc\ub97c \uc801\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n\ub2e4\uc74c\uacfc \uac19\uc774 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n```python\nfrom datetime import datetime\nimport pandas as pd\nfrom stocks import monkey_investor, emulate_trade, PriceCache, State, Transaction\n\nprice_cache = PriceCache.from_keys_json()\n\nargs = monkey_investor(\n    price_cache,\n    '005930',\n    datetime(2021, 1, 1),\n    datetime(2021, 12, 31),\n    (100, 30),\n    36,\n    1000,\n)\n\nnot_commission_considered_result = pd.DataFrame(emulate_trade(*args))\ncommission_considered_result = pd.DataFrame(emulate_trade(*args, commission=(0.00015, 0.003015)))\n\n\ninitial_state = State.from_previous_state(price_cache, datetime(2021, 1, 1), None, None)\ntransactions = [Transaction(datetime(2021, 1, 1), company_code='005930', amount=300, sell_price='open')]\n\nstock_itself = pd.DataFrame(emulate_trade(price_cache, transactions, initial_state, datetime(2021, 12, 31)))\n\n\ntotal_appraisements = [result['total_appraisement'] for result in (not_commission_considered_result, commission_considered_result)]\n\ndf = pd.DataFrame()\ndf['Commission Not Considered'] = not_commission_considered_result['total_appraisement']\ndf['Commission Considered'] = commission_considered_result['total_appraisement']\ndf['Stock Price'] = stock_itself['total_appraisement']\n\ndf = df.set_index(not_commission_considered_result['date'])\n\ndf.plot(figsize=(10, 8), grid=True)\n```\n\n\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\n\n![img](images/commission_considered.png)\n\n### \uc6d0\uc22d\uc774 \ud22c\uc790\uc790\n\n\uc6d0\uc22d\uc774 \ud22c\uc790\uc790\ub780 \ubb34\uc791\uc704\ub85c \uc8fc\uc2dd\uc744 \uc0ac\uac70\ub098 \ud30c\ub294 \ubaa8\uc758 \ud22c\uc790\uc790\ub97c \uc758\ubbf8\ud569\ub2c8\ub2e4.\n\n\uc6d0\uc22d\uc774 \ud22c\uc790\uc790\uc640\uc758 \ube44\uad50\ub97c \ud1b5\ud574 \uc790\uc2e0\uc758 \uc54c\uace0\ub9ac\uc998\uc774 \ud6a8\uc728\uc801\uc778\uc9c0 \ud14c\uc2a4\ud2b8\ud574\ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n\uc0ac\uc6a9\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\n\n```python\nargs = monkey_investor(\n    price_cache=price_cache,\n    company_code='005930',  # \ud22c\uc790\ud560 \ud68c\uc0ac\uc758 \uc885\ubaa9 \ucf54\ub4dc\n    start_day=datetime(2021, 1, 1),  # \ud22c\uc790 \uc2dc\uc791\uc77c\n    end_day=datetime(2021, 12, 31),  # \ud22c\uc790 \uc885\ub8cc\uc77c (\uc774 \uac12\uc744 \ud3ec\ud568\ud568)\n    invest_amount=(100, 30),  # \ud22c\uc790\ub7c9, \uc790\ub8cc: (\ud3c9\uade0, \ud45c\uc900\ud3b8\ucc28)\n    total_invest_count=36,  # \ucd1d \ud22c\uc790\uc218\n    seed=10,  # \ub79c\ub364\uac12\uc758 \uc2dc\ub4dc. None\uc77c \uacbd\uc6b0 \ubcc4\ub3c4\ub85c \uc815\ud558\uc9c0 \uc54a\uc74c.\n)\n```\n\n`fetch_prices_by_datetime`\uc640\ub294 \ub2e4\ub974\uac8c \ud22c\uc790 \uc885\ub8cc\uc77c\uc744 \ud3ec\ud568\ud569\ub2c8\ub2e4. \uc8fc\uc758\ud574 \uc8fc\uc138\uc694.\n\n\uc774 \ud568\uc218\ub294 emulate_trade\ub97c \uc2e4\ud589\ud558\uc9c0\ub294 \uc54a\uc73c\uba70, emulate_trade\uc5d0 \ubc14\ub85c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub294 \uc778\uc790\ub97c \ub0b4\ubcf4\ub0c5\ub2c8\ub2e4.\n\n\uc774\ub97c unpacking\uc73c\ub85c emulate_trade\uc5d0 \ub123\uc5b4 \uc2e4\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n```python\nargs = monkey_investor(\n    price_cache,\n    '005930',\n    datetime(2021, 1, 1),\n    datetime(2021, 12, 31),\n    (100, 30),\n    36,\n    1,\n)\nresult = pd.DataFrame(emulate_trade(*args))\n```\n\n#### \uc751\uc6a9\n\n\uc5ec\ub7ec \uc6d0\uc22d\uc774 \ud22c\uc790\uc790\ub4e4\uc744 \uc0dd\uc131\ud55c \ub4a4 \uc8fc\uc2dd \uc790\uccb4\uc758 \uac12\uacfc \ube44\uad50\ud558\ub294 \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc774 \uc791\uc131\uc774 \uac00\ub2a5\ud569\ub2c8\ub2e4.\n\n```python\n# \uc6d0\uc22d\uc774 \ud22c\uc790\uc790\ub97c 10\uac1c \uc0dd\uc131\nargs_list = (monkey_investor(\n    price_cache,\n    '005930',\n    datetime(2021, 1, 1),\n    datetime(2021, 12, 31),\n    (100, 30),\n    36,\n    1000 + i,\n) for i in range(10))\nresults = [pd.DataFrame(emulate_trade(*args)) for args in args_list]\n\n# \uc8fc\uc2dd\uc758 \uac00\uaca9 \ubcc0\ub3d9\uc744 \ud655\uc778\ud568.\ninitial_state = State.from_previous_state(price_cache, datetime(2021, 1, 1), None, None)\ntransactions = [Transaction(datetime(2021, 1, 1), company_code='005930', amount=300, sell_price='open')]\n\nstock_itself = pd.DataFrame(emulate_trade(price_cache, transactions, initial_state, datetime(2021, 12, 31)))\n\n# \ud50c\ub86f \uc0dd\uc131\ntotal_appraisements = [result['total_appraisement'] for result in results]\n\ndf = pd.DataFrame()\nfor i, total_appraisement in enumerate(total_appraisements, 1):\n    df[f'Monkey #{i}'] = total_appraisement\ndf['Stock Price'] = stock_itself['total_appraisement']\n\ndf = df.set_index(stock_itself['date'])\n\ndf.plot(figsize=(10, 8), grid=True, style=[':'] * 10 + ['b-'])\n```\n\n\uc0dd\uc131\ub41c \uadf8\ub798\ud504\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\n![Plot shows total appraisement](images/monkey_investors.png)\n\n### \ub2e4\uc591\ud55c \ub370\uc774\ud130\ub85c \ud50c\ub86f \uadf8\ub9ac\uae30\n\n\ud55c \uc6d0\uc22d\uc774 \ud22c\uc790\uc790\uc5d0 \ub300\ud55c \uc8fc\uc2dd \ubcf4\uc720\uc218\uc640 \uc8fc\uc2dd \ud3c9\uac00\uc561\uc73c\ub85c \uadf8\ub9b0 \ud50c\ub86f\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\n\n```python\nfrom datetime import datetime\n\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nfrom stocks import emulate_trade, PriceCache, monkey_investor\n\nprice_cache = PriceCache.from_keys_json()\n\nargs = monkey_investor(\n    price_cache,\n    '005930',\n    datetime(2021, 1, 1),\n    datetime(2021, 12, 31),\n    (100, 30),\n    36,\n    1234,\n)\nresult = pd.DataFrame(emulate_trade(*args))\n\nfig, ax1 = plt.subplots()\n\ncolor = 'tab:red'\nax1.set_xlabel('date')\nax1.set_ylabel('stock amount', color='tab:red')\nax1.plot(result['date'], [stock.get('005930', (0, 0))[0] for stock in result['stocks']], color=color)\nax1.set_ylim(-1500, 1500)\nax1.tick_params(axis='y', labelcolor=color)\n\nax2 = ax1.twinx()\n\ncolor = 'tab:blue'\nax2.set_ylabel('total appraisement', color='tab:blue')\nax2.plot(result['date'],\n         [total_appraisement for total_appraisement in result['total_appraisement']], color=color)\nax2.set_ylim(-15_000_000, 15_000_000)\nax2.tick_params(axis='y', labelcolor=color)\n\nfig.tight_layout()\nplt.grid(True)\nplt.show()\n```\n\n\uc0dd\uc131\ub41c \uadf8\ub798\ud504\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\n\n![plot about multiple data](images/multi_data.png)\n\n### \uc8fc\uc2dd \ud1b5\uacc4 \uacc4\uc0b0\ud558\uae30\n\nMDD, CAGR, \uc8fc\uc2dd \ubcc0\ub3d9\uc131\uc740 `stock_statistics` \ubaa8\ub4c8\ub85c \uacc4\uc0b0\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n```python\nfrom datetime import datetime\n\nimport mojito\n\nfrom stocks import KEY, emulate_trade, monkey_investor, PriceCache\nfrom stocks.stock_statistics import MDD, CAGR, stock_volatility\n\nbroker = mojito.KoreaInvestment(**KEY)\nprice_cache = PriceCache(broker)\n\nargs = list(monkey_investor(\n    price_cache=price_cache,\n    company_code='005930',\n    start_day=datetime(2021, 1, 1),\n    end_day=datetime(2021, 12, 31),\n    invest_amount=(100, 30),\n    total_invest_count=36,\n    seed=10,\n))\n\n# Changing initial state\nargs[2].budget = 100_000_000  # type: ignore\nargs[2].total_appraisement = 100_000_000  # type: ignore\n\nstates = emulate_trade(*args)  # type: ignore\n\nprint(MDD(states))\nprint(CAGR(states))\nprint(stock_volatility(broker, '009530', 'D', datetime(2021, 1, 1), datetime(2021, 12, 31)))\n```\n\n### \uc8fc\ucc28\ubcc4 Changelog\n\n\uc8fc\uc758: \uae30\ub2a5\uc744 \uc0ac\uc6a9\ud558\uae30 \uc804\uc5d0 `git fetch`\ub97c \ud1b5\ud574 \uc5c5\ub370\uc774\ud2b8\ud574\uc8fc\uc138\uc694.\n\n1. 3\uc8fc\ucc28 (~23/11/08)\n\n    PriceDict \ucd94\uac00, PriceCache\uc5d0 from_keys_json \ucd94\uac00, PriceCache\uc758 get_price\uc758 \ub9ac\ud134\uac12 \ubcc0\uacbd, \uc5ec\ub7ec \ubaa8\ub4c8 \uc774\ub984 \ubcc0\uacbd, numpy int64 \uad00\ub828 \ubc84\uadf8 \uc218\uc815, Transaction\uc5d0 check_price_unit \ucd94\uac00, stocks\uc758 count\uac00 \uc74c\uc218\uac00 \ub418\uc9c0 \uc54a\ub3c4\ub85d \ubcc0\uacbd, emulate_trade\uc5d0 final_date \ucd94\uac00, monkey_investor \ubc0f stock_statistics \ucd94\uac00, commission \ucd94\uac00, \uae30\ubcf8 import \uac1c\uc218 \uc99d\uac00\n\n1. 2\uc8fc\ucc28 (~23/10/30)\n\n    State, Transaction, emulate_trade \ucd94\uac00\n\n1. 1\uc8fc\ucc28\n\n    \ud504\ub85c\uc81d\ud2b8 \uc2dc\uc791, KEY \ucd94\uac00, adjust_price_unit \ud568\uc218 \ucd94\uac00\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\uc54c\uace0\ub9ac\uc998 \uc8fc\uc2dd \ud22c\uc790\ub97c \uc704\ud55c \uc5ec\ub7ec \ud234\uc744 \ubaa8\uc544\ub193\uc740 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc785\ub2c8\ub2e4.",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9eeee473dded2631cf08d96ea1b5a92e7186696b507aa0bb51094888ea9ca97c",
                "md5": "6a41043cc26e7b0975d1f37a34f7767a",
                "sha256": "901e61146cb143a8eaf4c5cdb43703dd6f7e1eea6e68ed72cf1b33aa6b297c65"
            },
            "downloads": -1,
            "filename": "stock_tools-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a41043cc26e7b0975d1f37a34f7767a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11.0,<3.12.0",
            "size": 24627,
            "upload_time": "2023-12-16T06:30:42",
            "upload_time_iso_8601": "2023-12-16T06:30:42.056147Z",
            "url": "https://files.pythonhosted.org/packages/9e/ee/e473dded2631cf08d96ea1b5a92e7186696b507aa0bb51094888ea9ca97c/stock_tools-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50e7acf46b6054399357206029554bf91b62ceaa2b0900f6461f170c16d187fe",
                "md5": "ff71e2fb01c7003762c4f9b56ff51cb2",
                "sha256": "4db9be50156749495323ca1b333081d319f684a6578ecad3d289513c9c92d0b6"
            },
            "downloads": -1,
            "filename": "stock_tools-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ff71e2fb01c7003762c4f9b56ff51cb2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11.0,<3.12.0",
            "size": 25722,
            "upload_time": "2023-12-16T06:30:44",
            "upload_time_iso_8601": "2023-12-16T06:30:44.009404Z",
            "url": "https://files.pythonhosted.org/packages/50/e7/acf46b6054399357206029554bf91b62ceaa2b0900f6461f170c16d187fe/stock_tools-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-16 06:30:44",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "stock-tools"
}
        
Elapsed time: 1.27455s