Search
📝

예제25. Monthly,Weekly 옵션 중 만기가 가까운 옵션거래

예제식의 기본은 예제8과 같은 합성선물전략입니다. 예제8은 Monthly 옵션을 대상으로 하는 전략이었습니다. 이번 예제는 Monthly와 Weekly 월요일 옵션과 목요일 옵션 중 만기가 가장 가까운 상품을 선택해서 ATM종목으로 주문을 집행하는 내용입니다.
1.
전략내용
선물차트에서 매수신호가 발생하면 콜매수+풋매도 선물차트에서 매수청산신호가 발생하면 매수신호시 주문종목 청산 선물차트에서 매도신호가 발생하면 콜매도+풋매수 선물차트에서 매도청산신호가 발생하면 매도신호시 주문종목 청산
2.
스크립트 객체화면 설정
a.
옵션객체
옵션객체는 3개가 필요합니다. 옵션객체 추가 후 속성에서 객체명은 Option1, 코스피200옵션이나 코스닥150옵션으로 지정 옵션객체 추가 후 속성에서 객체명은 Option2, 월요일 옵션으로 지정 옵션객체 추가 후 속성에서 객체명은 Option3, 목요일 옵션으로 지정
b.
계좌객체
계좌객체를 추가한 후 속성에서 객체명은 Account1로 지정하고 주문 낼 계좌번호를 지정합니다.
c.
차트객체
차트객체를 추가한 후 속성에서 객체명은 Chart1로 지정하고 신호가 발생하는 차트와 동일한 아디디를 지정해 줍니다.
3.
스팟수식
var Start; var MinRemain,MinRemainOption; var BuyCallCode,BuyPutcode; var BuyCallPrice,BuyPutPrice; var SellCallCode,SellPutcode; var SellCallPrice,SellPutPrice; var 수량 = 1; function Main_OnStart() { Main.MessageList(Option1.GetRemainDays(0,0)); Main.MessageList(Option2.GetRemainDays(0,0)); Main.MessageList(Option3.GetRemainDays(0,0)); var R1 = Option1.GetRemainDays(0,0); var R2 = Option2.GetRemainDays(0,0); var R3 = Option3.GetRemainDays(0,0); MinRemain = 0; MinRemainOption = 0; if (MinRemainOption == 0 || (MinRemain > 0 && R1 < MinRemain)) { MinRemain = R1; MinRemainOption = 1; } if (MinRemainOption == 0 || (MinRemain > 0 && R2 < MinRemain)) { MinRemain = R2; MinRemainOption = 2; } if (MinRemainOption == 0 || (MinRemain > 0 && R3 < MinRemain)) { MinRemain = R3; MinRemainOption = 3; } Main.MessageList(MinRemain, MinRemainOption); Start = 0; } function Chart1_OnRiseSignal(Signal) { if (Signal.signalKind == 1) { Main.MessageList("매수진입신호발생 - 합성선물매수(콜매수+풋매도)"); Start = 1; BuyCallCode = ""; BuyPutCode = ""; BuyCallPrice = 0; BuyPutPrice = 0; if (MinRemainOption == 1) { BuyCallCode = Option1.GetATMCallRecent(0,0); BuyPutCode = Option1.GetATMPutRecent(0,0); BuyCallPrice = Option1.GetAskByCode(BuyCallCode,2); BuyPutPrice = Option1.GetBidByCode(BuyPutCode,2); } if (MinRemainOption == 2) { BuyCallCode = Option2.GetATMCallRecent(0,0); BuyPutCode = Option2.GetATMPutRecent(0,0); BuyCallPrice = Option2.GetAskByCode(BuyCallCode,2); BuyPutPrice = Option2.GetBidByCode(BuyPutCode,2); } if (MinRemainOption == 3) { BuyCallCode = Option3.GetATMCallRecent(0,0); BuyPutCode = Option3.GetATMPutRecent(0,0); BuyCallPrice = Option3.GetAskByCode(BuyCallCode,2); BuyPutPrice = Option3.GetBidByCode(BuyPutCode,2); } if (BuyCallPrice > 0 && BuyPutPrice > 0) { Account1.OrderBuy(BuyCallCode, 수량, BuyCallPrice, 0); Account1.OrderSell(BuyPutCode, 수량, BuyPutPrice, 0); Main.MessageList("콜매수:",BuyCallCode,"|주문가:",BuyCallPrice); Main.MessageList("풋매도:",BuyPutCode,"|주문가:",BuyPutPrice); } } if (Start == 1 && Signal.signalKind == 2 ) { Main.MessageLog("매수청산신호발생"); Start = 0; BxCallPrice = 0; BxPutPrice = 0; if (MinRemainOption == 1) { BxCallPrice = Option1.GetBidByCode(BuyCallCode,2); BxPutPrice = Option1.GetAskByCode(BuyPutCode,2); } if (MinRemainOption == 2) { BxCallPrice = Option2.GetBidByCode(BuyCallCode,2); BxPutPrice = Option2.GetAskByCode(BuyPutCode,2); } if (MinRemainOption == 3) { BxCallPrice = Option3.GetBidByCode(BuyCallCode,2); BxPutPrice = Option3.GetAskByCode(BuyPutCode,2); } if (BxCallPrice > 0 && BxPutPrice > 0) { Account1.OrderSell(BuyCallCode, 수량, BxCallPrice, 0); Account1.OrderBuy(BuyPutCode, 수량, BxPutPrice, 0); Main.MessageList("콜매수청산:",BuyCallCode,"|주문가:",BxCallPrice); Main.MessageList("풋매도청산:",BuyPutCode,"|주문가:",BxPutPrice); } } if (Signal.signalKind == 3 ) { Main.MessageList("매도진입신호발생 - 합성선물매도(콜매도+풋매수)"); Start = -1; SellCallCode = ""; SellPutCode = ""; SellCallPrice = 0; SellPutPrice = 0; if (MinRemainOption == 1) { SellCallCode = Option1.GetATMCallRecent(0,0); SellPutCode = Option1.GetATMPutRecent(0,0); SellCallPrice = Option1.GetBidByCode(SellCallCode,2); SellPutPrice = Option1.GetAskByCode(SellPutCode,2); } if (MinRemainOption == 2) { SellCallCode = Option2.GetATMCallRecent(0,0); SellPutCode = Option2.GetATMPutRecent(0,0); SellCallPrice = Option2.GetBidByCode(SellCallCode,2); SellPutPrice = Option2.GetAskByCode(SellPutCode,2); } if (MinRemainOption == 3) { SellCallCode = Option3.GetATMCallRecent(0,0); SellPutCode = Option3.GetATMPutRecent(0,0); SellCallPrice = Option3.GetBidByCode(SellCallCode,2); SellPutPrice = Option3.GetAskByCode(SellPutCode,2); } if (SellCallPrice > 0 && SellPutPrice > 0) { Account1.OrderSell(SellCallCode, 수량, SellCallPrice , 0); Account1.OrderBuy(SellPutCode, 수량, SellPutPrice, 0); Main.MessageList("콜매도:",SellCallCode,"|주문가:",SellCallPrice); Main.MessageList("풋매수:",SellPutCode,"|주문가:",SellPutPrice); } } if (Start == -1 && Signal.signalKind == 4 ) { Main.MessageLog("매도청산신호발생"); if (MinRemainOption == 1) { SxCallPrice = Option1.GetAskByCode(SellCallCode,2); SxPutPrice = Option1.GetBidByCode(SellPutCode,2); } if (MinRemainOption == 2) { SxCallPrice = Option2.GetAskByCode(SellCallCode,2); SxPutPrice = Option2.GetBidByCode(SellPutCode,2); } if (MinRemainOption == 3) { SxCallPrice = Option3.GetAskByCode(SellCallCode,2); SxPutPrice = Option3.GetBidByCode(SellPutCode,2); } if (SxCallPrice > 0 && SxPutPrice > 0) { Account1.OrderBuy(SellCallCode, 수량, SxCallPrice, 0); Account1.OrderSell(SellPutCode, 수량, SxPutPrice, 0); Main.MessageList("콜매도청산:",SellCallCode,"|주문가:",SxCallPrice); Main.MessageList("풋매수청산:",SellPutCode,"|주문가:",SxPutPrice); } } }
JavaScript
복사