2021년 8월 27일 금요일

주식 벡테스트[2021년8월23일~8월28]


상세 그래프를 보려면 html 파일확인 에서 확인할수있습니다.

------------------------------23일

파일경로 :2021-08-23Stock_Record


026890 손익가:-53470

035080 손익가:7233.0

102460 손익가:153864

220630 손익가:-13043

241520 손익가:-21484

323410 손익가:85669

(94) 총손익!!!:158769.0












------------------------------24일

파일경로 :2021-08-24Stock_Record


005880 손익가:4772

006910 손익가:3048

009270 손익가:2355

014190 손익가:3109

021080 손익가:6372.0

027830 손익가:3591

033160 손익가:19289.0

035080 손익가:8620

037270 손익가:11021

047820 손익가:1174.0

064260 손익가:5479

089140 손익가:-16355

089890 손익가:9157.0

148150 손익가:23882

205470 손익가:15872

(85) 총손익!!!:101386.0

















------------------------------25일

파일경로 :2021-08-25Stock_Record


025750 손익가:1512

035080 손익가:9991.0

052220 손익가:1725.0

064260 손익가:4371.0

064550 손익가:151479.0

148150 손익가:11013.0

950130 손익가:25340.0

(95) 총손익!!!:205431.0










------------------------------26일

파일경로 :2021-08-26Stock_Record


002720 손익가:6643

015860 손익가:7236

(83) 총손익!!!:13879





------------------------------27일

파일경로 :2021-08-27Stock_Record


009520 손익가:10925.0

041930 손익가:20760

104480 손익가:13339.0

(100) 총손익!!!:45024.0






------------------------------28일

100개의 종목으로 28일 하루거래 테스트


 009520 손익가:10925.0

041930 손익가:20760

104480 손익가:13339.0

(100) 총손익!!!:45024.0







ananconda python ta-lib install(py37_32)

 C:\Users\사용자\anaconda3 에다가


TA_Lib-0.4.21-cp37-cp37m-win32.whl 다운받아서


아나콘다 프롬프트 키고 해당 경로에서 설치하면 된다!


pip install TA_Lib-0.4.21-cp37-cp37m-win32.whl





2021년 8월 21일 토요일

주식 벡테스트 [8월20일 기준]

5분봉 데이터로 백테스트 진행하였습니다.


각각 20일 기준으로 수집했습니다.(8월4일 11시55분~8월20일 3시30분)


분봉이기 때문에 실시간이랑 다를 수 있으므로 가장 최악의 경우로 테스트 진행


매수:  고가에서 매수

매도: 저가에서 매도


수수료율은 키움 실거래계좌 기준





조건검색은 2가지로 진행했습니다.

1.거래량상위

2.시윤주식


매매방식

1.하나의 종목당 10만원 투자

2.-tsar,dmi 사용




20일 당일거래 수익율

거래량상위버전


그래프
138250


078890


038880

026890







시윤주식버전




그래프

000250



002290






018620










모든기간 계산시 수익율


1.거래량상위


2.시윤주식































python calculation Psar

 





def 계산psar(self,barsdata, iaf=0.02, maxaf=0.2):
length = len(barsdata)
first_index = 0
high = list(barsdata['high'])
low = list(barsdata['low'])
close = list(barsdata['y'])
psar = close[0:len(close)]
bull = True
af = iaf

hp = high[first_index]
lp = low[first_index]


for i in range(first_index+2, length):
if bull:
psar[i] = psar[i - 1] + af * (hp - psar[i - 1])
else:
psar[i] = psar[i - 1] + af * (lp - psar[i - 1])
reverse = False
if bull:
if low[i] < psar[i]:
bull = False
reverse = True
psar[i] = hp
lp = low[i]
af = iaf
else:
if high[i] > psar[i]:
bull = True
reverse = True
psar[i] = lp
hp = high[i]
af = iaf
if not reverse:
if bull:
if high[i] > hp:
hp = high[i]
af = min(af + iaf, maxaf)
if low[i - 1] < psar[i]:
psar[i] = low[i - 1]
if low[i - 2] < psar[i]:
psar[i] = low[i - 2]
else:
if low[i] < lp:
lp = low[i]
af = min(af + iaf, maxaf)
if high[i - 1] > psar[i]:
psar[i] = high[i - 1]
if high[i - 2] > psar[i]:
psar[i] = high[i - 2]


barsdata["psar"] = psar





def 실시간계산psar(self,barsdata, iaf=0.02, maxaf=0.2):

length = len(barsdata)
first_index = len(barsdata)-2
high = list(barsdata['high'])
low = list(barsdata['low'])

bull = True
af = iaf

hp = high[first_index]
lp = low[first_index]

for i in range(first_index + 2, length):
if bull:
barsdata["psar"].iloc[i] = barsdata["psar"].iloc[i - 1] + af * (hp - barsdata["psar"].iloc[i - 1])
else:
barsdata["psar"].iloc[i] = barsdata["psar"].iloc[i - 1] + af * (lp - barsdata["psar"].iloc[i - 1])
reverse = False
if bull:
if low[i] < barsdata["psar"].iloc[i]:
bull = False
reverse = True
barsdata["psar"].iloc[i] = hp
lp = low[i]
af = iaf
else:
if high[i] > barsdata["psar"].iloc[i]:
bull = True
reverse = True
barsdata["psar"].iloc[i] = lp
hp = high[i]
af = iaf
if not reverse:
if bull:
if high[i] > hp:
hp = high[i]
af = min(af + iaf, maxaf)
if low[i - 1] < barsdata["psar"].iloc[i]:
barsdata["psar"].iloc[i] = low[i - 1]
if low[i - 2] < barsdata["psar"].iloc[i]:
barsdata["psar"].iloc[i] = low[i - 2]
else:
if low[i] < lp:
lp = low[i]
af = min(af + iaf, maxaf)
if high[i - 1] > barsdata["psar"].iloc[i]:
barsdata["psar"].iloc[i] = high[i - 1]
if high[i - 2] > barsdata["psar"].iloc[i]:
barsdata["psar"].iloc[i] = high[i - 2]

2021년 8월 18일 수요일

python calculate DMI(원본)

 






def cal_dmi(self,data, n=14,n_ADX=14):
i = 0
UpI = [0]
DoI = [0]

data["UpI"]=0
data["DoI"]=0

while i + 1 <= data.index[-1] :
UpMove = data.loc[i + 1, "high"] - data.loc[i, "high"]
DoMove = data.loc[i, "low"] - data.loc[i+1, "low"]
if UpMove > DoMove and UpMove > 0 :
UpD = UpMove
else :
UpD = 0
data["UpI"].iloc[i] = UpD
# UpI.append(UpD)

if DoMove > UpMove and DoMove > 0 :
DoD = DoMove
else :
DoD = 0

# DoI.append(DoD)
data["DoI"].iloc[i] = DoD
i = i + 1

i = 0
TR_l = [0]
data["TR_l"]=0
while i < data.index[-1]:
TR = max(data.loc[i + 1, 'high'], data.loc[i, 'y']) - min(data.loc[i + 1, 'low'], data.loc[i, 'y'])
# TR_l.append(TR)
data["TR_l"].iloc[i]=TR
i = i + 1


TR_s = pd.Series(TR_l)
# ATR = pd.Series(TR_s.ewm(span=n, min_periods=1).mean())
ATR = pd.Series(data["TR_l"].ewm(span=n, min_periods=1).mean())
# UpI = pd.Series(UpI)
# DoI = pd.Series(DoI)
# PosDI = pd.Series(UpI.ewm(span=n, min_periods=1).mean() / ATR)
# NegDI = pd.Series(DoI.ewm(span=n, min_periods=1).mean() / ATR)

PosDI = pd.Series(data["UpI"].ewm(span=n, min_periods=1).mean() / ATR)
NegDI = pd.Series(data["DoI"].ewm(span=n, min_periods=1).mean() / ATR)

ADX = pd.Series((abs(PosDI - NegDI) / (PosDI + NegDI)).ewm(span=n_ADX, min_periods=1).mean(), name='ADX_' + str(n) + '_' + str(n_ADX))
data["DIMinus"] =round(NegDI*100,2)
data["DIPlus"] = round(PosDI*100,2)
data["ADX"] =round(ADX*100,2)











######실시간용과 전체용

def 계산DMI(self,data, n=14,n_ADX=14):


data["UpI"]=0
data["DoI"]=0
data["TR_l"]=0

# first_index = 803

# print("111:[%s] 222:[%s]"%(data.index[-1],len(data)-1))

# i = first_index
i=0

while i + 1 <= len(data)-1:
# UpMove = data.loc[i+1 , "high"] - data.loc[i, "high"]
# DoMove = data.loc[i, "low"] - data.loc[i+1, "low"]
# print("i:[%s][%s]"%(i,data["ds"].iloc[i]))
UpMove = data["high"].iloc[i + 1] - data["high"].iloc[i]
DoMove = data["low"].iloc[i] - data["low"].iloc[i + 1]

if UpMove > DoMove and UpMove > 0 :
UpD = UpMove
else :
UpD = 0

data["UpI"].iloc[i+1] = UpD

if DoMove > UpMove and DoMove > 0 :
DoD = DoMove
else :
DoD = 0

data["DoI"].iloc[i+1] = DoD
i = i + 1

i = 0

while i < len(data)-1:
TR = max(data["high"].iloc[i + 1], data["y"].iloc[i]) - min(data["low"].iloc[i + 1], data["y"].iloc[i])
data["TR_l"].iloc[i+1]=TR
i = i + 1

ATR = pd.Series(data["TR_l"].ewm(span=n, min_periods=1).mean())
PosDI = pd.Series(data["UpI"].ewm(span=n, min_periods=1).mean() / ATR)
NegDI = pd.Series(data["DoI"].ewm(span=n, min_periods=1).mean() / ATR)
ADX = pd.Series((abs(PosDI - NegDI) / (PosDI + NegDI)).ewm(span=n_ADX, min_periods=1).mean(), name='ADX_' + str(n) + '_' + str(n_ADX))

data["DIMinus"] =round(NegDI*100,2)
data["DIPlus"] = round(PosDI*100,2)
data["ADX"] =round(ADX*100,2)












def 실시간dmi(self,code,n=14,n_ADX=14):


i = len(self.실시간차트용데이터[code])-5

while i + 1 <= len(self.실시간차트용데이터[code]) - 1:
UpMove = self.실시간차트용데이터[code]["high"].iloc[i + 1] - self.실시간차트용데이터[code]["high"].iloc[i]
DoMove = self.실시간차트용데이터[code]["low"].iloc[i] - self.실시간차트용데이터[code]["low"].iloc[i + 1]

if UpMove > DoMove and UpMove > 0:
UpD = UpMove
else:
UpD = 0

# self.실시간차트용데이터[code]["UpI"].iloc[i + 1] = UpD

if DoMove > UpMove and DoMove > 0:
DoD = DoMove
else:
DoD = 0

# self.실시간차트용데이터[code]["DoI"].iloc[i + 1] = DoD
##마지막값만 변경
if i+1 == len(self.실시간차트용데이터[code]) - 1:
print("여기안타나??? [%s %s ]"%(self.실시간차트용데이터[code]["ds"].iloc[i+1],i))
print("UpD:[%s]"%UpD)
print("Dod:[%s]"%DoD)
print("UpMove DoMove:[%s,%s]"%(UpMove,DoMove))
self.실시간차트용데이터[code]["UpI"].iloc[i+1] = UpD
self.실시간차트용데이터[code]["DoI"].iloc[i+1] = DoD

i = i + 1

i = len(self.실시간차트용데이터[code])-5

while i < len(self.실시간차트용데이터[code]) - 1:
TR = max(self.실시간차트용데이터[code]["high"].iloc[i + 1], self.실시간차트용데이터[code]["y"].iloc[i]) - min(self.실시간차트용데이터[code]["low"].iloc[i + 1], self.실시간차트용데이터[code]["y"].iloc[i])
if i==len(self.실시간차트용데이터[code])-2:
self.실시간차트용데이터[code]["TR_l"].iloc[i+1] = TR
i = i + 1

ATR = pd.Series(self.실시간차트용데이터[code]["TR_l"].ewm(span=n, min_periods=1).mean())
PosDI = pd.Series(self.실시간차트용데이터[code]["UpI"].ewm(span=n, min_periods=1).mean() / ATR)
NegDI = pd.Series(self.실시간차트용데이터[code]["DoI"].ewm(span=n, min_periods=1).mean() / ATR)
print("NegDI%s"%NegDI.tail(5))
print()
ADX = pd.Series((abs(PosDI - NegDI) / (PosDI + NegDI)).ewm(span=n_ADX, min_periods=1).mean(),
name='ADX_' + str(n) + '_' + str(n_ADX))

self.실시간차트용데이터[code]["DIMinus"].iloc[len(self.실시간차트용데이터[code]) - 1] = round(NegDI.iloc[len(NegDI) - 1] * 100, 2)
self.실시간차트용데이터[code]["DIPlus"].iloc[len(self.실시간차트용데이터[code]) - 1] = round(PosDI.iloc[len(PosDI) - 1] * 100, 2)
self.실시간차트용데이터[code]["ADX"].iloc[len(self.실시간차트용데이터[code]) - 1] = round(ADX.iloc[len(ADX) - 1] * 100, 2)

2021년 7월 22일 목요일

[Unity] 기즈모 카메라

 


기즈모 방법 요약

1_기즈모캡쳐
Camera_Gizmo  Compass Gizmo Control를 넣는다

2 3DOBJ
- 객체마다 BoxCollider를 가지고있고 Compass Mouse Event코드를 넣는다

-이쁘게 하기위한 Sprite_Base도 넣는다(Sprite Renderer)

3 Canvas

ort,per 나누기위한용
-Compass Ui Control 코드 넣기

Toggle은 각자 위 코드를 참조하여 모드를 변경한다.





기즈모를 화면에 안보이는 상단위에 위치시킨다




카메라의 빈부모 Pivot을 잡는다




기즈모를 보여줄 Base카메라를 하나 더 올린다
Compass Gizmo Control 코드를 추가한다.









실제 기즈모 객체는 LocalPosition으로 적용될것임
가장 부모인 3dObjectsCompass_Gizmo의 자식으로 두고 0,0,0에위치하도록한다.


실제 기즈모 객체를 만든다_(트랜스폼 위치참조)

실제 기즈모 객체를 만든다_(트랜스폼 위치참조)

실제 기즈모 객체 바닥을 만든다(Sprite Renderer)






기즈모카메라에 보일 캔버스를 하나 준비하여 토글 기능을 추가


Screen Space - Camera에 두고
Compass Ui Control 코드 추가

각 토글에는 알맞는 토글기능을 넣는다

각 토글에는 알맞는 토글기능을 넣는다











CompassGizmoControl

using System;
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;

[RequireComponent(typeof(Camera))]
public class CompassGizmoControl : MonoBehaviour
{

    //public CameraMovement cameraMovement;
    public CameraMove cameraMovement;

    [HideInInspector]
    public bool IsGizmoClick = false;

    private float ScreenWidth = 400;
    private float ScreenHeight = 300;
    public float xPos = 750;
    public float yPos = 300f;
    private Vector2 lastScreenSize;

    private const float CAMERA_MOVE_TIME_DURATION = 0.5f;
    private const float DEFAULT_CAMERA_PIVOT_DISTANT = 10F; 축을 어디로 둘지 정하는 변수

    private Camera cam_Gizmo;
    private Transform cam_Gizmo_Pivot;

    private GameObject mainCameraTargetObject;
    private Coroutine c;
    private Rect viewportRect;
    private float viewportX = 0.88f;

    void Reset()
    {
        cam_Gizmo = gameObject.GetComponent<Camera>();
        cam_Gizmo.gameObject.name = "Camera_Gizmo";
        cam_Gizmo.clearFlags = CameraClearFlags.Depth;
        cam_Gizmo.depth = 100;

        cam_Gizmo.pixelRect = new Rect(Screen.width - xPosScreen.height - yPosScreenWidthScreenHeight);
        cam_Gizmo.fieldOfView = 25f;
        cam_Gizmo.nearClipPlane = 0.01f;
        cam_Gizmo.farClipPlane = 10f;

        cam_Gizmo.transform.localPosition = transform.parent.transform.forward * -8f;//new Vector3(4f, 4f, 6f);
        cam_Gizmo.transform.LookAt(transform.parent.transform);
    }

    void Start()
    {
        cam_Gizmo = gameObject.GetComponent<Camera>();
        cam_Gizmo_Pivot = transform.parent.transform;
        mainCameraTargetObject = new GameObject();

        viewportRect = cam_Gizmo.rect;
    }

    void Update()
    {
        if (Camera.main != null)
        {
            cam_Gizmo_Pivot.localRotation = Camera.main.transform.rotation;
            //ResizeScreenCheck();
        }
    }

    private void ResizeScreenCheck()
    {
        //Vector2 screenSize = new Vector2(Screen.width, Screen.height);
        //if (this.lastScreenSize != screenSize)
        //{
        //    this.lastScreenSize = screenSize;
        //    cam_Gizmo.pixelRect = new Rect(Screen.width - xPos, Screen.height - yPos, ScreenWidth, ScreenHeight);
        //}
    }


    /// called from CompassMouseEvent.cs
    public void clickedGizmoObject(Transform clickedGizmoObject)
    {
        if (EventSystem.current.IsPointerOverGameObject())
            return;

        IsGizmoClick = true;

        Camera.main.transform.parent = null;

        Vector3 normalVector3 = Vector3.Normalize(clickedGizmoObject.localPosition);
        Vector3 MainCameraPivot = findMainCameraPivot();

        mainCameraTargetObject.transform.position = MainCameraPivot + (normalVector3 * Vector3.Distance(Camera.main.transform.positionMainCameraPivot));
        mainCameraTargetObject.transform.LookAt(MainCameraPivot);

        if (c != null)
        {
            StopCoroutine(c);
            c = null;
        }

        c = StartCoroutine(moveCamera(mainCameraTargetObject.transform));
    }



    private IEnumerator moveCamera(Transform target_Point)
    {
        Vector3 destposition = target_Point.position;
        Quaternion destrotation = target_Point.rotation;
        Transform cam_transform = Camera.main.transform;
        float time = 0f;
        float duration_lerf = 0f;

        while (cam_transform.position != destposition && cam_transform.rotation != destrotation)
        {
            time = Mathf.Clamp(time0CAMERA_MOVE_TIME_DURATION);
            duration_lerf = time / CAMERA_MOVE_TIME_DURATION;
            cam_transform.position = Vector3.Lerp(cam_transform.positiondestpositionduration_lerf);
            cam_transform.rotation = Quaternion.Lerp(cam_transform.rotationdestrotationduration_lerf);

            yield return null;
            time += Time.deltaTime;

            cameraMovement.SetTarget();
        }

        cameraMovement.SetTarget();
        IsGizmoClick = false;
    }

    private Vector3 findMainCameraPivot()
    {
        Vector3 v3 = Camera.main.transform.position + Camera.main.transform.forward * DEFAULT_CAMERA_PIVOT_DISTANT;// 레이 타겟이 없을때 카메라 전방 10m

        Ray ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2Screen.height / 2));
        RaycastHit hitpoint;
        if (Physics.Raycast(rayout hitpoint))
        {
            v3 = hitpoint.point;
        }

        return v3;
    }

    private float findMainCameraPivotDist()
    {
        Vector3 MainCameraPivot = findMainCameraPivot();
        return (Vector3.Distance(MainCameraPivotCamera.main.transform.position));
    }

    public void change_camera_OrthographicMode()
    {
        Camera.main.orthographic = true;
        float camOrthographicSize = (Mathf.Tan(Camera.main.fieldOfView / 2f * Mathf.Deg2Rad) * findMainCameraPivotDist());
        Camera.main.orthographicSize = camOrthographicSize;
    }

    public void change_camera_PerspectiveMode()
    {
        Camera.main.orthographic = false;
    }

    public void OnValueChangedEditToggle(bool value)
    {
        if (value)
        {
            cam_Gizmo.rect = viewportRect;
        }
        else
        {
            cam_Gizmo.rect = new Rect(viewportXviewportRect.yMinviewportRect.xMaxviewportRect.yMax);
        }
    }
}




Compass Mouse Event

using UnityEngine;
using UnityEngine.EventSystems;

[RequireComponent(typeof(BoxCollider))]
public class CompassMouseEvent : MonoBehaviour {

    public CompassGizmoControl ref_CompassGizmoControl;


    private Color orgColor;
    private Color OverColor = Color.cyan;
    private Material m_mat;

    void Start () {
        m_mat = GetComponent<MeshRenderer> ().material;
        orgColor = m_mat.color;
    }

    void OnMouseEnter()
    {
        if (!EventSystem.current.IsPointerOverGameObject())
        {
            m_mat.color = OverColor;
        }
    }

    void OnMouseExit()
    {
        m_mat.color = orgColor;
    }

    void OnMouseDown()
    {
        ref_CompassGizmoControl.clickedGizmoObject (this.transform);
    }

}



Compass Ui Control

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CompassUiControl : MonoBehaviour {

    public CompassGizmoControl ref_CompassGizmoControl;

    public void _mainCamera_OrthographicMode(Toggle t)
    {
        if (t.isOn
        {
            ref_CompassGizmoControl.change_camera_OrthographicMode ();
        }
    }

    public void _mainCamera_PerspectiveMode(Toggle t)
    {
        if (t.isOn
        {
            ref_CompassGizmoControl.change_camera_PerspectiveMode();
        }
    }
}












git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...