민서네집

YesTrader에서 저장한 가격 파일 변형하기 본문

Python

YesTrader에서 저장한 가격 파일 변형하기

브라이언7 2019. 8. 21. 10:48

YesTrader에서 지표 만들기

- 시뮬레이션 차트에서는 가격 파일이 안 만들어지고, 전략 차트에서만 만들어지기 때문에, 최대 10000개의 가격 데이터만 저장되는 제약사항이 있다.

Var: 종목명("");
Var: 파일명("");
Var: 소숫점자릿수(0), cnt(0), temp(0), DP("");

// 해당 종목의 소숫점자릿수 계산
If DP=="" Then {
	temp = PriceScale*1000000;
	For cnt = 0 To 6 {
		If temp % 10 > 0 Then { 소숫점자릿수 = 6-cnt; cnt = 99; }
		temp = temp / 10;
	}
	DP = NumToStr(소숫점자릿수,0);
}

If GloBalBarIndex==0 Then {
    종목명 = SymbolName; 
    If InStr(종목명,"연결_")==1 Then {
        종목명 = RightStr(종목명, StrLen(종목명) - StrLen("연결_"));
        If InStr(종목명,"-")!=0 Then
        	종목명 = LeftStr(종목명, InStr(종목명,"-")-1);
    }
    파일명 = "price_" + 종목명 + ".csv";
    Print(파일명, "date,time,open,high,low,close,volume");
    MessageLog("%s,%s,%s",SymbolCode, SymbolName, 종목명);
}
Print(파일명, ",%."+DP+"f,%."+DP+"f,%."+DP+"f,%."+DP+"f,%.0f", O, H, L, C, V);

파일이 생성되는 위치

C:\eFriend Global YesTrader\efriendglobalyestrader\YesLang

 

Notepad++에서 바꾸기로 파일 변형

1. notepad++ 에서 맨 윗 줄(헤더)를 다음과 같이 바꾼다.
date,time,open,high,low,close,volume

2. notepad++ 에서 바꾸기 메뉴 선택. (연도 바꾸기)
검색 모드: 정규표현식
찾을 내용: (\d{4})-(\d{2})-(\d{2})\s
바꿀 내용: $1/$2/$3,

3. notepad++ 에서 바꾸기 메뉴 선택. (시간 바꾸기)
검색 모드: 정규표현식
찾을 내용: (.{2}):(.{2}):(.{2})\s{2}
바꿀 내용: $1:$2

4. 공백을 찾아서 0 으로 바꿈. (시간에 공백이 들어있음)
검색 모드: 일반
찾을 내용: {한 칸 공백}
바꿀 내용: 0

 

Python 프로그램으로 가격 파일을 변형시키는 코드 (Jupyter Notebook)

## 맨 첫 줄의 header를 아래와 같이 변경
2019-05-10  7:40:00  date,open,high,low,close,volume

date_time,open,high,low,close,volume


# [index_col 참고] https://chrisalbon.com/python/data_wrangling/pandas_dataframe_importing_csv/
# [decimal 로 읽어들이기] https://stackoverflow.com/questions/38114654/pandas-read-csv-column-dtype-is-set-to-decimal-but-converts-to-string
import pandas as pd
import decimal as D
df = pd.read_csv("price_Crude Oil.csv",
                 converters={'open': D.Decimal, 'high': D.Decimal, 'low': D.Decimal, 'close': D.Decimal }
                )
df.head()

def get_date(x):
    return x[11:16].replace (" ", "0")

df['date'] = df['date_time'].map(lambda x : x[:10].replace("-","/"))
df['time'] = df['date_time'].map(lambda x : get_date(x))
# df[50:70]
df.tail()


df = df.reindex(columns=['date','time','open','high','low','close','volume'])
df = df.set_index(['date','time'])
df

df.to_csv('price_10m_test.csv')

 

'Python' 카테고리의 다른 글

mpld3 - Python Graphic Library  (0) 2019.08.11
plotly - Python Graphing Libraries  (0) 2019.08.11
Jupyter Notebook - Variable Viewer  (0) 2019.08.10
Jupyter Notebook - 디버깅, PixieDebugger  (0) 2019.08.10
matplotlib 한글폰트 사용하기  (2) 2019.03.31
Comments