Revision | eb1c0d0b7e849e3fc5ec4261ce3300d9a2fc4ff8 (tree) |
---|---|
Time | 2023-03-06 22:16:23 |
Author | kazuhiro_kondow <simauma.circus@gmai...> |
Commiter | kazuhiro_kondow |
Vector Angleの修正
パラメータがマイナス値の場合に正しい値が出せない
@@ -0,0 +1,113 @@ | ||
1 | +{ | |
2 | + "cells": [ | |
3 | + { | |
4 | + "cell_type": "code", | |
5 | + "execution_count": 8, | |
6 | + "metadata": {}, | |
7 | + "outputs": [ | |
8 | + { | |
9 | + "name": "stdout", | |
10 | + "output_type": "stream", | |
11 | + "text": [ | |
12 | + "theta_d1 : -0.2292\n", | |
13 | + "theta_d2 : 11.7161\n", | |
14 | + "theta_d3 : -11.7161\n" | |
15 | + ] | |
16 | + } | |
17 | + ], | |
18 | + "source": [ | |
19 | + "# 2023-03-06 10:25:04,359 12488 MainThread exchange_rate_info.py:236 set_technical_indicators [DEBUG]: num[-2]: MACD: -0.0535, MACDSignal: -0.0514\n", | |
20 | + "# 2023-03-06 10:25:04,360 12488 MainThread exchange_rate_info.py:236 set_technical_indicators [DEBUG]: num[-1]: MACD: -0.0492, MACDSignal: -0.0511\n", | |
21 | + "# 2023-03-06 10:25:04,362 12488 MainThread exchange_rate_info.py:242 set_technical_indicators [DEBUG]: befor turning point:None\n", | |
22 | + "# 2023-03-06 10:25:04,363 12488 MainThread exchange_rate_info.py:296 set_technical_indicators [INFO]: CrossOver up. vector angle:-0.2292 Already judged goldencross.\n", | |
23 | + "# マイナス角度も判定できるように整数にしたい\n", | |
24 | + "\n", | |
25 | + "import numpy as np\n", | |
26 | + "\n", | |
27 | + "# vector angle\n", | |
28 | + "def vector_angle(u: np.ndarray, v: np.ndarray):\n", | |
29 | + " a1 = np.around(((u[0] - u[1]) / (0 - 1)), 4)\n", | |
30 | + " a2 = np.around(((v[0] - v[1]) / (0 - 1)), 4)\n", | |
31 | + " theta = np.arctan((a2 - a1) / (1 + a1 * a2))\n", | |
32 | + " theta_d = np.around(np.rad2deg(theta), 4)\n", | |
33 | + " return theta_d\n", | |
34 | + "\n", | |
35 | + "u1 = np.array([-0.0535, -0.0492])\n", | |
36 | + "v1= np.array([-0.0514, -0.0511])\n", | |
37 | + "\n", | |
38 | + "u2 = np.array([0.0535, -0.0492])\n", | |
39 | + "v2 = np.array([-0.0514, 0.0511])\n", | |
40 | + "\n", | |
41 | + "u3 = np.array([-0.0535, 0.0492])\n", | |
42 | + "v3 = np.array([0.0514, -0.0511])\n", | |
43 | + "\n", | |
44 | + "print(f'theta_d1 : {vector_angle(u1, v1)}')\n", | |
45 | + "print(f'theta_d2 : {vector_angle(u2, v2)}')\n", | |
46 | + "print(f'theta_d3 : {vector_angle(u3, v3)}')" | |
47 | + ] | |
48 | + }, | |
49 | + { | |
50 | + "cell_type": "code", | |
51 | + "execution_count": 11, | |
52 | + "metadata": {}, | |
53 | + "outputs": [ | |
54 | + { | |
55 | + "name": "stdout", | |
56 | + "output_type": "stream", | |
57 | + "text": [ | |
58 | + "theta_d1 : 0.2292\n", | |
59 | + "theta_d2 : 11.7161\n", | |
60 | + "theta_d3 : 11.7161\n" | |
61 | + ] | |
62 | + } | |
63 | + ], | |
64 | + "source": [ | |
65 | + "\n", | |
66 | + "# vector angle2\n", | |
67 | + "def vector_angle2(u: np.ndarray, v: np.ndarray):\n", | |
68 | + " # 傾き,tilt\n", | |
69 | + " a1 = np.around(((u[0] - u[1]) / (0 - 1)), 4)\n", | |
70 | + " a2 = np.around(((v[0] - v[1]) / (0 - 1)), 4)\n", | |
71 | + " u1 = np.array([1, a1])\n", | |
72 | + " v1 = np.array([1, a2])\n", | |
73 | + " i = np.inner(u1, v1)\n", | |
74 | + " n = np.linalg.norm(u1) * np.linalg.norm(v1)\n", | |
75 | + " c = i / n\n", | |
76 | + " theta = np.arccos(np.clip(c, -1.0, 1.0))\n", | |
77 | + " theta_d = np.around(np.rad2deg(theta), 4)\n", | |
78 | + " return theta_d\n", | |
79 | + "\n", | |
80 | + "print(f'theta_d1 : {vector_angle2(u1, v1)}')\n", | |
81 | + "print(f'theta_d2 : {vector_angle2(u2, v2)}')\n", | |
82 | + "print(f'theta_d3 : {vector_angle2(u3, v3)}')" | |
83 | + ] | |
84 | + } | |
85 | + ], | |
86 | + "metadata": { | |
87 | + "kernelspec": { | |
88 | + "display_name": "venv", | |
89 | + "language": "python", | |
90 | + "name": "python3" | |
91 | + }, | |
92 | + "language_info": { | |
93 | + "codemirror_mode": { | |
94 | + "name": "ipython", | |
95 | + "version": 3 | |
96 | + }, | |
97 | + "file_extension": ".py", | |
98 | + "mimetype": "text/x-python", | |
99 | + "name": "python", | |
100 | + "nbconvert_exporter": "python", | |
101 | + "pygments_lexer": "ipython3", | |
102 | + "version": "3.10.9" | |
103 | + }, | |
104 | + "orig_nbformat": 4, | |
105 | + "vscode": { | |
106 | + "interpreter": { | |
107 | + "hash": "3434ed70bd0ce2eb2bb8ac6e97f0ebaa4c4b8adeb56c97e7db5709836a4a2d70" | |
108 | + } | |
109 | + } | |
110 | + }, | |
111 | + "nbformat": 4, | |
112 | + "nbformat_minor": 2 | |
113 | +} |
@@ -98,7 +98,12 @@ class ExchangeRateInfo(): | ||
98 | 98 | raise ValueError('Nan is included in the value.') |
99 | 99 | a1 = np.around(((u[0] - u[1]) / (0 - 1)), 4) |
100 | 100 | a2 = np.around(((v[0] - v[1]) / (0 - 1)), 4) |
101 | - theta = np.arctan((a2 - a1) / (1 + a1 * a2)) | |
101 | + u1 = np.array([1, a1]) | |
102 | + v1 = np.array([1, a2]) | |
103 | + i = np.inner(u1, v1) | |
104 | + n = np.linalg.norm(u1) * np.linalg.norm(v1) | |
105 | + c = i / n | |
106 | + theta = np.arccos(np.clip(c, -1.0, 1.0)) | |
102 | 107 | theta_d = np.around(np.rad2deg(theta), 4) |
103 | 108 | return theta_d |
104 | 109 |