├── high_low.py
├── wave.py
└── README.md
/high_low.py:
--------------------------------------------------------------------------------
1 | from stringprep import in_table_a1
2 |
3 |
4 | def high_low(x,y):
5 | p1 = x**(0.125)*y**(0.875)
6 | p2 = x**(0.236)*y**(0.764)
7 | p3 = x**(0.382)*y**(0.618)
8 | p4 = x**(0.5)*y**(0.5)
9 | p5 = x**(0.618)*y**(0.382)
10 | p6 = x**(0.764)*y**(0.236)
11 | p7 = x**(0.875)*y**(0.125)
12 | return p1,p2,p3,p4,p5,p6,p7
13 | x = float(input("Enter the maxima" + " "))
14 | y = float(input("Enter the minima" + " "))
15 | result = high_low(x,y)
16 | print(str(result))
--------------------------------------------------------------------------------
/wave.py:
--------------------------------------------------------------------------------
1 | from stringprep import in_table_a1
2 | # Calculate wave 3 to wave 1; wave 5 to wave 3; wave C to wave A when the price falls
3 | def wave_negcor(x,y):
4 | nec1 = p1 * ((1-abs(pe))**0.125)
5 | nec2 = p1 * ((1-abs(pe))**0.236)
6 | nec3 = p1 * ((1-abs(pe))**0.382)
7 | nec4 = p1 * ((1-abs(pe))**0.5)
8 | nec5 = p1 * ((1-abs(pe))**0.618)
9 | nec6 = p1 * ((1-abs(pe))**0.764)
10 | nec7 = p1 * ((1-abs(pe))**0.875)
11 | nec8 = p1 * (1-abs(pe))
12 | nec9 = p1 * ((1-abs(pe))**1.236)
13 | nec10 = p1 * ((1-abs(pe))**1.382)
14 | nec11 = p1 * ((1-abs(pe))**1.5)
15 | nec12 = p1 * ((1-abs(pe))**1.618)
16 | return nec1, nec2, nec3, nec4, nec5, nec6, nec7, nec8, nec9, nec10, nec11, nec12
17 | # Compare wave 3 to wave 1; wave 5 to wave 3; wave C to wave A when the price increases
18 | def wave_poscor(x,y):
19 | poc1 = p1 * ((1+pe)**0.236)
20 | poc2 = p1 * ((1+pe)**0.382)
21 | poc3 = p1 * ((1+pe)**0.5)
22 | poc4 = p1 * ((1+pe)**0.618)
23 | poc5 = p1 * ((1+pe)**0.764)
24 | poc6 = p1 * ((1+pe)**0.875)
25 | poc7 = p1 * (1+pe)
26 | poc8 = p1 * ((1+pe)**1.236)
27 | poc9 = p1 * ((1+pe)**1.382)
28 | poc10 = p1 * ((1+pe)**1.5)
29 | poc11 = p1 * ((1+pe)**1.618)
30 | poc12 = p1 * ((1+pe)**2)
31 | poc13 = p1 * ((1+pe)**2.618)
32 | return poc1, poc2, poc3, poc4, poc5, poc6, poc7, poc8, poc9, poc10, poc11, poc12, poc13
33 | # Compare wave 2 to wave 1; wave 4 to wave 3; wave B to wave A when the price falls in wave 1
34 | def wave_negative(x,y):
35 | ne1 = p1 * ((1+abs(pe))**0.125)
36 | ne2 = p1 * ((1+abs(pe))**0.236)
37 | ne3 = p1 * ((1+abs(pe))**0.382)
38 | ne4 = p1 * ((1+abs(pe))**0.5)
39 | ne5 = p1 * ((1+abs(pe))**0.618)
40 | ne6 = p1 * ((1+abs(pe))**0.764)
41 | ne7 = p1 * ((1+abs(pe))**0.875)
42 | ne8 = p1 * ((1+abs(pe))**1)
43 | return ne1, ne2, ne3, ne4, ne5, ne6, ne7, ne8
44 | # Compare wave 2 to wave 1; wave 4 to wave 3; wave B to wave A when the price increases in wave 1
45 | def wave_positive(x,y):
46 | po1 = p1 * ((1-pe)**0.125)
47 | po2 = p1 * ((1-pe)**0.236)
48 | po3 = p1 * ((1-pe)**0.382)
49 | po4 = p1 * ((1-pe)**0.5)
50 | po5 = p1 * ((1-pe)**0.618)
51 | po6 = p1 * ((1-pe)**0.764)
52 | po7 = p1 * ((1-pe)**0.875)
53 | po8 = p1 * ((1-pe)**1)
54 | return po1, po2, po3, po4, po5, po6, po7, po8
55 |
56 | x = float(input("Enter the final value" + " "))
57 | y = float(input("Enter the initial value" + " "))
58 | # rate of change = (final value - initial value)/initial value
59 | pe = (x-y)/y
60 | p1 = float(input("Enter the value you want to start" + " "))
61 | result1 = wave_negcor(x, y)
62 | result2 = wave_poscor(x, y)
63 | result3 = wave_negative(x,y)
64 | result4 = wave_positive(x,y)
65 | # If the rate of change is positive(price increases), and you want to know the price of the fixing wave, then use wave_positive
66 | if pe > 0 and x == p1:
67 | print(str(result4))
68 | # If the rate of change is positive(price increases), and you want to know the price of the corresponding push wave, then use wave_poscor
69 | if pe > 0 and x != p1:
70 | print(str(result2))
71 | # If the rate of change is negative(price decreases), and you want to know the price of the fixing wave, then use wave_negative
72 | if pe < 0 and x == p1:
73 | print(str(result3))
74 | # If the rate of change is negative(price decreases), and you want to know the price of the corresponding fixing wave, then use wave_negcor
75 | if pe < 0 and x != p1:
76 | print(str(result1))
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Stock-market
2 | Mainly focusing on Elliott's Wave Theory to help determining the market trend and golden ratios to determine price.
3 |
4 | - [Stock-market](#stock-market)
5 | * [Introduction](#introduction)
6 | * [Basic formation](#basic-formation)
7 | * [Basic principle](#basic-principle)
8 | * [Number the waves](#number-the-waves)
9 | * [Calculation of the waves](#calculation-of-the-waves)
10 | * [Speical cases for Corrective Wave Patterns](#speical-cases-for-corrective-wave-patterns)
11 | + [The Zig-Zag Formation](#the-zig-zag-formation)
12 | + [The Flat Formation](#the-flat-formation)
13 | + [The Triangle Formation](#the-triangle-formation)
14 | * [Price determination using golden ratios](#price-determination-using-golden-ratios)
15 |
16 |
17 |
18 | ## Introduction
19 | Elliott Wave Theory is a technical analysis used to describe price movements in the financial market. The stock price movements and consumer behaviors can be identified as waves according to Elliot.
20 |
21 | ## Basic formation
22 |
23 |
24 |
25 | As shown in the above graph, a whole big wave consists of 8 small waves. There are two types of waves, one called **Impulse (Motive) wave** and the other called **Corrective wave**. In the above graph, wave 1,3 and 5 are **Impulse waves**, and wave 2 and 4 are **Corrective waves**. However we can see that the 5-wave trends are then corrected and reversed by 3-wave countertrends: A-B-C.
26 |
27 | The **Impulse wave** is not always in the upward direction and the **Corrective wave** is not always in the downward direction. That's because the definition of Impulse wave is to make a net movement in the same direction as the trend of the next-largest degree while the definition of Corrective wave is to correct the direction of the movement. For example, in the bear market shown in the following graph,
28 | 
29 |
30 | wave 1,3, and 5 are still **Impulse waves**, but they are moving downwards.
31 |
32 | ## Basic principle
33 |
34 | * The movement of Wave 2 will not exceed the starting point of wave 1.
35 | * Wave 3 is usually the longest wave, but cannot be the shortest (compared to Wave 1 and 5).
36 | * Wave 4 will never enter the domain of Wave 1.
37 |
38 | ## Number the waves
39 |
40 | Sometimes a big wave can consist of a whole 5-3 wave. It will be shown as follows:
41 |
42 |
43 |
44 | Here, Wave (1) consists of Wave (i), (ii), (iii), (iv), (v); Wave (2) consits of Wave (a), (b) and (c);... These will usually happen when you look at different time scales.
45 |
46 | ## Calculation of the waves
47 | The calculation of prices usually involves Fibonacci Sequence.
48 | * %Wave 2 = (%Wave 1) $^{0.5}$ or (%Wave 1) $^{0.618}$. Here is the Python code below which helps you calculate:
49 |
50 | ```ruby
51 | # Bull market, po4 and po5 are the most common ones (as stated above)
52 | def wave_positive(x,y):
53 | po1 = p1 * ((1-pe)**0.125)
54 | po2 = p1 * ((1-pe)**0.236)
55 | po3 = p1 * ((1-pe)**0.382)
56 | po4 = p1 * ((1-pe)**0.5)
57 | po5 = p1 * ((1-pe)**0.618)
58 | po6 = p1 * ((1-pe)**0.764)
59 | po7 = p1 * ((1-pe)**0.875)
60 | po8 = p1 * ((1-pe)**1)
61 | return po1, po2, po3, po4, po5, po6, po7, po8
62 | # Enter the highest value in Wave 1
63 | x = float(input("Enter the final value" + " "))
64 | # Enter the lowest value in Wave 1
65 | y = float(input("Enter the initial value" + " "))
66 | # Calculate the increasing rate of prices
67 | pe = (x-y)/y
68 | # Enter the value to start calculating (In this case is the highest value of Wave 1)
69 | p1 = float(input("Enter the value you want to start" + " "))
70 | result4 = wave_positive(x,y)
71 | # pe is indeed greater than 0 as it is in bull market and the final value is the highest value of Wave 1
72 | if pe > 0 and x == p1:
73 | print(str(result4))
74 | ```
75 |
76 | * %Wave 3 = (%Wave 1) $^{1.618}$ or (%Wave 1) $^{2}$ or (%Wave 1) $^{2.618}$. Here is the Python code below which helps you calculate:
77 |
78 | ```ruby
79 | # Bull market, poc11, poc12 and poc13 are the most common prices, while other prices are convenient for calculating prices compared Wavee 5 to Wave 1
80 | def wave_poscor(x,y):
81 | poc1 = p1 * ((1+pe)**0.236)
82 | poc2 = p1 * ((1+pe)**0.382)
83 | poc3 = p1 * ((1+pe)**0.5)
84 | poc4 = p1 * ((1+pe)**0.618)
85 | poc5 = p1 * ((1+pe)**0.764)
86 | poc6 = p1 * ((1+pe)**0.875)
87 | poc7 = p1 * (1+pe)
88 | poc8 = p1 * ((1+pe)**1.236)
89 | poc9 = p1 * ((1+pe)**1.382)
90 | poc10 = p1 * ((1+pe)**1.5)
91 | poc11 = p1 * ((1+pe)**1.618)
92 | poc12 = p1 * ((1+pe)**2)
93 | poc13 = p1 * ((1+pe)**2.618)
94 | return poc1, poc2, poc3, poc4, poc5, poc6, poc7, poc8, poc9, poc10, poc11, poc12, poc13
95 | x = float(input("Enter the final value" + " "))
96 | y = float(input("Enter the initial value" + " "))
97 | # rate of change = (final value - initial value)/initial value
98 | pe = (x-y)/y
99 | # Enter the value to start calculating (In this case should be the lowest value in Wave 2)
100 | p1 = float(input("Enter the value you want to start" + " "))
101 | result2 = wave_poscor(x, y)
102 | # pe is indeed greater than 0 as it is in bull market and the final value is not the hightest value of Wave 1
103 | if pe > 0 and x != p1:
104 | print(str(result2))
105 | ```
106 |
107 | * %Wave 4 = (%Wave 3) $^{0.382}$. Here is the Python code below which helps you calculate:
108 |
109 | ```ruby
110 | # Bull market, po3 is the most common ones (as stated above)
111 | def wave_positive(x,y):
112 | po1 = p1 * ((1-pe)**0.125)
113 | po2 = p1 * ((1-pe)**0.236)
114 | po3 = p1 * ((1-pe)**0.382)
115 | po4 = p1 * ((1-pe)**0.5)
116 | po5 = p1 * ((1-pe)**0.618)
117 | po6 = p1 * ((1-pe)**0.764)
118 | po7 = p1 * ((1-pe)**0.875)
119 | po8 = p1 * ((1-pe)**1)
120 | return po1, po2, po3, po4, po5, po6, po7, po8
121 | # Enter the highest value in Wave 3
122 | x = float(input("Enter the final value" + " "))
123 | # Enter the lowest value in Wave 3
124 | y = float(input("Enter the initial value" + " "))
125 | # Calculate the increasing rate of prices
126 | pe = (x-y)/y
127 | # Enter the value to start calculating (In this case is the highest value of Wave 3)
128 | p1 = float(input("Enter the value you want to start" + " "))
129 | result4 = wave_positive(x,y)
130 | # pe is indeed greater than 0 as it is in bull market and the final value is the highest value of Wave 3
131 | if pe > 0 and x == p1:
132 | print(str(result4))
133 | ```
134 |
135 | * %Wave 5 = %Wave 1 or (%Wave 1) $^{0.618}$ when %Wave 3 > %Wave 1 or (%Wave 3) $^{0.236}$, (%Wave 3) $^{0.382}$ when %Wave 3 < %Wave 1. Here is the Python code below which helps you calculate:
136 |
137 | ```ruby
138 | # Bull market, porc4, poc5 and poc7 are the most common prices.
139 | def wave_poscor(x,y):
140 | poc1 = p1 * ((1+pe)**0.236)
141 | poc2 = p1 * ((1+pe)**0.382)
142 | poc3 = p1 * ((1+pe)**0.5)
143 | poc4 = p1 * ((1+pe)**0.618)
144 | poc5 = p1 * ((1+pe)**0.764)
145 | poc6 = p1 * ((1+pe)**0.875)
146 | poc7 = p1 * (1+pe)
147 | poc8 = p1 * ((1+pe)**1.236)
148 | poc9 = p1 * ((1+pe)**1.382)
149 | poc10 = p1 * ((1+pe)**1.5)
150 | poc11 = p1 * ((1+pe)**1.618)
151 | poc12 = p1 * ((1+pe)**2)
152 | poc13 = p1 * ((1+pe)**2.618)
153 | return poc1, poc2, poc3, poc4, poc5, poc6, poc7, poc8, poc9, poc10, poc11, poc12, poc13
154 | x = float(input("Enter the final value" + " "))
155 | y = float(input("Enter the initial value" + " "))
156 | # rate of change = (final value - initial value)/initial value
157 | pe = (x-y)/y
158 | # Enter the value to start calculating (In this case should be the lowest value in Wave 4)
159 | p1 = float(input("Enter the value you want to start" + " "))
160 | result2 = wave_poscor(x, y)
161 | # pe is indeed greater than 0 as it is in bull market and the final value is not the hightest value of Wave 1
162 | if pe > 0 and x != p1:
163 | print(str(result2))
164 | ```
165 |
166 | * %Wave A = (%Wave 5) $^{0.5}$ or (%Wave 5) $^{0.618}$. Here is the Python code below which helps you calculate:
167 |
168 | ```ruby
169 | # Bull market, po4 and po5 are the most common ones (as stated above)
170 | def wave_positive(x,y):
171 | po1 = p1 * ((1-pe)**0.125)
172 | po2 = p1 * ((1-pe)**0.236)
173 | po3 = p1 * ((1-pe)**0.382)
174 | po4 = p1 * ((1-pe)**0.5)
175 | po5 = p1 * ((1-pe)**0.618)
176 | po6 = p1 * ((1-pe)**0.764)
177 | po7 = p1 * ((1-pe)**0.875)
178 | po8 = p1 * ((1-pe)**1)
179 | return po1, po2, po3, po4, po5, po6, po7, po8
180 | # Enter the highest value in Wave 5
181 | x = float(input("Enter the final value" + " "))
182 | # Enter the lowest value in Wave 5
183 | y = float(input("Enter the initial value" + " "))
184 | # Calculate the increasing rate of prices
185 | pe = (x-y)/y
186 | # Enter the value to start calculating (In this case is the highest value of Wave 5)
187 | p1 = float(input("Enter the value you want to start" + " "))
188 | result4 = wave_positive(x,y)
189 | # pe is indeed greater than 0 as it is in bull market and the final value is the highest value of Wave 5
190 | if pe > 0 and x == p1:
191 | print(str(result4))
192 | ```
193 |
194 | * %Wave B = (%Wave A) $^{0.382}$ or (%Wave A) $^{0.5}$ or (%Wave A) $^{0.618}$. Here is the Python code below which helps you calculate:
195 |
196 | ```ruby
197 | # Bull market, so Wave A is corrective, and ne3, ne4 and ne5 are the most common ones (as stated above)
198 | def wave_negative(x,y):
199 | ne1 = p1 * ((1+abs(pe))**0.125)
200 | ne2 = p1 * ((1+abs(pe))**0.236)
201 | ne3 = p1 * ((1+abs(pe))**0.382)
202 | ne4 = p1 * ((1+abs(pe))**0.5)
203 | ne5 = p1 * ((1+abs(pe))**0.618)
204 | ne6 = p1 * ((1+abs(pe))**0.764)
205 | ne7 = p1 * ((1+abs(pe))**0.875)
206 | ne8 = p1 * ((1+abs(pe))**1)
207 | return ne1, ne2, ne3, ne4, ne5, ne6, ne7, ne8
208 | # Enter the lowest value in Wave A
209 | x = float(input("Enter the final value" + " "))
210 | # Enter the highest value in Wave A
211 | y = float(input("Enter the initial value" + " "))
212 | # Calculate the increasing rate of prices
213 | pe = (x-y)/y
214 | # Enter the value to start calculating (In this case is the lowest value of Wave A)
215 | p1 = float(input("Enter the value you want to start" + " "))
216 | result3 = wave_negative(x,y)
217 | # pe is less than 0 as it is in bull market and the final value is the lowest value of Wave A
218 | if pe < 0 and x == p1:
219 | print(str(result3))
220 | ```
221 |
222 | * %Wave C = %Wave A or (%Wave A) $^{0.618}$ or (%Wave A) $^{1.382}$ or (%Wave A) $^{1.618}$. Here is the Python code below which helps you calculate:
223 |
224 | ```ruby
225 | def wave_negcor(x,y):
226 | nec1 = p1 * ((1-abs(pe))**0.125)
227 | nec2 = p1 * ((1-abs(pe))**0.236)
228 | nec3 = p1 * ((1-abs(pe))**0.382)
229 | nec4 = p1 * ((1-abs(pe))**0.5)
230 | nec5 = p1 * ((1-abs(pe))**0.618)
231 | nec6 = p1 * ((1-abs(pe))**0.764)
232 | nec7 = p1 * ((1-abs(pe))**0.875)
233 | nec8 = p1 * (1-abs(pe))
234 | nec9 = p1 * ((1-abs(pe))**1.236)
235 | nec10 = p1 * ((1-abs(pe))**1.382)
236 | nec11 = p1 * ((1-abs(pe))**1.5)
237 | nec12 = p1 * ((1-abs(pe))**1.618)
238 | return nec1, nec2, nec3, nec4, nec5, nec6, nec7, nec8, nec9, nec10, nec11, nec12
239 | # Enter the lowest price of Wave A
240 | x = float(input("Enter the final value" + " "))
241 | # Enter the highest price of Wave A
242 | y = float(input("Enter the initial value" + " "))
243 | # rate of change = (final value - initial value)/initial value
244 | pe = (x-y)/y
245 | # Enter the highest value of Wave C
246 | p1 = float(input("Enter the value you want to start" + " "))
247 | result1 = wave_negcor(x, y)
248 | # pe is less than 0 in bull market and the final value is the highest value of Wave B
249 | if pe < 0 and x != p1:
250 | print(str(result1))
251 |
252 | ```
253 |
254 | Note here all the code is provided in bull market, full code including bear market will be attached in the file.
255 |
256 | ## Speical cases for Corrective Wave Patterns
257 |
258 | ### The Zig-Zag Formation
259 |
260 |
261 |
262 | * Zig-zag formations are very steep moves in price that go against the predominant trend.
263 | * Wave $B$ is typically shortest in length compared to Waves $A$ and $C$.
264 | * These zig-zag patterns can happen twice or even three times in a corection (2 to 3 zig-zag patterns linked together).
265 | * Each of the waves in zig-zag patterns could be broken up into 5-wave patterns.
266 |
267 | ### The Flat Formation
268 |
269 |
270 |
271 | * Flat formations are simple sideways corrective waves.
272 | * The lengths of the waves are ***Generally*** equal in length, with wave $B$ reversing wave $A$'s move and wave $C$ undoing wave $B$'s move.
273 | * ***Generally*** in above means sometimes wave $B$ can go beyond the beginning of wave $A$.
274 |
275 | ### The Triangle Formation
276 |
277 |
278 |
279 | * Triangle formations are corrective patterns that are bound by either converging or diverging trend lines.
280 | * Triangles are made up of 5-waves that move against the trend in a sideways fashion. These triangles can be ***symmetrical***, ***descending***, ***ascending*** or ***expanding***.
281 |
282 | ## Price determination using golden ratios
283 |
284 | * When we look at price charts over a long period of time, or a chart where the stock price has moved in a wide vertical range, the common linear price chart is not as useful as the ***semi-log*** chart.
285 | * The semi-log chart has a logarithmic scale for the vertical axis while the time axis is still linear - hence the chart is a semi-log chart (not a ***log*** chart).
286 |
287 |
288 |
289 | How do we determine the price of correction or price of impulse?
290 |
291 | * Consider the above graph, we would like to calculate the correction price in nearly 2009-05-24, which is a correction to the price from 2002-05-24 to 2007-05-24.
292 | * We use ***golden ratio*** to calculate.
293 | * Let the highest price be $p_{h}$, which is the price in approximately 2007-05-24, and the lowest price be $p_{l}$, which is the price in approximately 2002-07-24.
294 | * Then the correction price $p_{c}$ usually can be $$p_{c} = p_{h}^{0.125}\times p_{l}^{0.875}\quad\text{or}\quad p_{c} = p_{h}^{0.236}\times p_{l}^{0.764}\quad\text{or}\quad p_{c} = p_{h}^{0.382}\times p_{l}^{0.618}\quad\text{or}\quad p_{c} = p_{h}^{0.5}\times p_{l}^{0.5}.$$
295 | * Similar for impulse wave, but this time the lowest price should take the exponential of $0.125,0.236,0.382$ and $0.5$.
296 | * Overall, the most important thing is to find the corresponding wave which the price is correcting or pushing.
297 |
298 | I have also included my own python file named 'high_low' for calculation, which makes it easier to store and list all the possible values.
299 |
300 | ```ruby
301 | def high_low(x,y):
302 | p1 = x**(0.125)*y**(0.875)
303 | p2 = x**(0.236)*y**(0.764)
304 | p3 = x**(0.382)*y**(0.618)
305 | p4 = x**(0.5)*y**(0.5)
306 | p5 = x**(0.618)*y**(0.382)
307 | p6 = x**(0.764)*y**(0.236)
308 | p7 = x**(0.875)*y**(0.125)
309 | return p1,p2,p3,p4,p5,p6,p7
310 | x = float(input("Enter the maxima" + " "))
311 | y = float(input("Enter the minima" + " "))
312 | result = high_low(x,y)
313 | print(str(result))
314 | ```
315 |
--------------------------------------------------------------------------------