Address
:
[go:
up one dir
,
main page
]
Include Form
Remove Scripts
Session Cookies
Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
330 views
18 pages
Estimate Support and Resistance of A Stock With Python
Estimate Support and Resistance of a Stock with Python
Uploaded by
FabioSantos
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Estimate Support and Resistance of a Stock with Py... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
330 views
18 pages
Estimate Support and Resistance of A Stock With Python
Estimate Support and Resistance of a Stock with Python
Uploaded by
FabioSantos
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Estimate Support and Resistance of a Stock with Py... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 18
Search
Fullscreen
tat Supt rR ta Sok th Pye y Sahn Sa Pon a Fae rh, 221 ae Estimate Support and Resistance ofa Stock with Python How you can estimate a stock’s support and resistance lines using linear regression Soman oiikar (Foicn ] Feb 4: Sinead [iv fmPhoto by Chris iverani In this article, I will be showing you how you can estimate a stock's support and resistance lines using the Python programming language. If you are only interested in the code for this project, then you can check out my Githiub repository here. Step 1. Installing the necessary modules First, create a file and title it equi renents ext . Next, you can find the necessary modules for this project over her paste itin your requirenents.txt file, Now in your terminal or command Go ahead and copy them, then prompt, run the following command. oxsinetienconpfnsnghin arlene nepali SE ae‘moot tat Supt an Reeac ta Se th Pen [5 ar |Pon fo ae rh, 221 aston pip install -r requirenents.tat Step 11. Import the necessary modules Importny hots wth © oy us view Step 2. Getting the closing prices of a stock In this article, we will primary be focusing on the AAPL stock over the time period of January 1, 2019 to April 1, 2019, but you can apply this same algorithm to other stocks over a different time period. To get the closing prices of a stock, be will be using the pandas dataseader. 2 df = web.catoteacer(sybely "yahoo", "28-82-01", *2019-08-02") loc dna. hosted wth O by Gite view oxinediniptorssinarlseoaime.getarsnesasndtrtwtheorongenaptn an itd westat Sino ars Rese fa Soh Pyn Stan Oar |Pson nae rn F221 etn The result of this will be a pa.2a:aesane object, with 6 columns. High, low, open, close, volume, and adj close. Since we only want to look at the closing prices, we can do this. 1 series = df'chose'] 2 rerloe-tndox = np.arang(series-rhape(o]) antes py hota with © by Gita evr In these lines of code, we are creating a ps.ceries object and storing the closing prices of the API stock inside that variable, Next we are setting the index of the series to be an array of consecutive numbers between 0 and the number of closing prices we have. If you print the series, you will get this. 39 35.5 6.982498 37.687500 st 46.697498, 5847-11750, 47180000 471487499 Moxinedinoiporbinarlnesrams.getardnesancndttwtheorongenaptin an itd we61 47810001 Nane: Close, Length: 62, dtype: float6s 1 tn yn by San ar an Fa Eh | Fa, 204 [Mn You can plot the series and get a visual representation of it by using matplotli pteseittesynol) pttextael 0395") pit.ylabel(“Prsces") pitoplot(series, 1adelsymbot) it.) pit.ehoat) ot anplpy hosed wth © by tub view AAPL e{— 46 a 42 Prices 40 Moxinediniporsinarlnesramsigetandnesacndtntewtheorongenaptn in itd woeoa Pion nae nn | F221 etn 38 36 o 10 20 30 40 50 60 Days So far, our code looks like this. 10 df = weboatoeader(syaboty “yateo", "2039-01-01, “2018-86-81°) 12 sertes = de('cose'] 12. serfes.tndex = op.arange(serses, shapes) step2 py hosted wth © by Sb view Step 3. Smoothening our graph Moxinedincoiporrsinerlnesras.gestarnesancndttwthorongenapt in ited weaman Spot Rance ef Sa th yn Right now, our data on the graph looks quite bumpy and doesn't look good to do any computer analysis on. In this step, we are going to try to smoothen our graph using the savgoi_citter function from the scipy.signa: module. oa Pion nae nn F221 etn ‘The savgo1_¢titer function takes in 3 parameters. Your array, a window length, and a polyorder. I won't be going to deep into these, however, feel free to check out their documentation on this function over here. Our array is obviously going to be our series, You can think of the window length as the level of smoothness you want in your data. The higher window length the more smooth your graph will be and the lower the window length, the less smooth your graph will be. To determine, the window length we want to use, [have created a small algorithm, which I will show you in just a minute. For this project, we will keep the polyorder equal to a constant, number as 3. Step 31. Determine the smoothness To determine the smoothness we want, we need to find the amount of months worth of data we have. Since each month has approximately 30 days, we will intergern divide the amount of prices we have by 30. We will store this in a variable called montn_a: ©. If sonth_ais® is equal to 0 then we will edit the value to 1, Now to determine the smoothness of a graph, we multiply our monch_aier by 2 and add it with 3. Moxinedinoiporbinarlnesrams.getardnesancndttwtheorongenaptin an itd wept reece tS th Pyen ySahn Sa [Pon ae Eri, 221 aes orem stff = serter.tape[8] // 28 Tateger divide the nuber of prices we have Oy 30 4 smooth = Soe(2 * nonLehft 4 3) # Sinple algo co determine encothess pts = savgol_tilter(serses, snot, 3) # Get the smoothed price dt ‘We can visualize this once again using matplotlib. 2 pteittetsymet) 2 pitaataber(oys") 3 pttaylobel(riees") 4 pttcoloctets, 1abel-Fsosoth (synbo1)") 5 pitstegend(> pit show) plot moet hosted wih © by Givi ow AAPL, 48) — smooth AAPL. 46 44 oxinedinciporsbinarlnestrasigestardnesancndtrtwtheorongenaptin an tid1 tn yn by Stan ar an Fa Eh | Fe, 204 [Mn oar = 40 38 36 0 10 20 30 40 50 60 Days We can visualize these in comparison like this. plestttletsyio}) pitexlabe( 055") pit-ylabl(‘Prsces') pit.plot(sriee, Iabel-syntol) pltplot(pts, Zabel snaoth (sytbal)") pue-tegendt) pit.showt) ot py honed wih © ty Gia view re AAPL AAPL, 8 ‘Smooth AAPL. Moxinedincoiporsinerlsesrasigestardnesacndtnscwtheorongenaptn in ited oe‘moot stat Sino ars Resse fa Sn ih Py oy Stan Oar |Pson nae Er F221 an 0 10 20 30 40 50 60 Days Step 4. Identifying local minimum and local maximum points To identify the local minimum and maximum points of a graph, I have created a simple function. or pytnagiona, ta) ssa = (peale] = peony * 2 bsg = (pats) + peasy) oa Moxinedinoiporsbinerlnetranagetarsnenandtntocwtheorongeneaptin in ited soneor sn Retre Sc th yn [iy Sha ar tan Fa Eh | Fe, 04 [Mn 7 lwalsin = 1 © eest am = 11 8 prev.sts = ((, st8[8D. Cs BLEED 20 for E La rageta, Leaots) ~ 2) a spend. = 2 + ptstial > ttt « ptstta 3 sopendto = “nin “ ute ots{ina) € atsit) > pts = provstatance = pythogtorev ps[®], prev pte[:]) * 8.5 » cure stanee = ythagtorevpts(2], (i, pts{iI)) 2 rev pta(0) © arevt3(2] 2 prev tata) = CL ptst8D) 2 6 pend. to oa ni cel plnvappend((y pt5{4))> 26 ocl.nax.oppend((y ots)? » prev pts(0) > prevptst3] » ev ts{3] = Ue otsti)) 2 cal ran apsend((s, 83400) toc min many hs wih © by itis ior Moxinedincoiporrsinerlnesras.gestarnesancndttwthorongenapt in itedtat Supt an Resac ta Sc th Pen [yS Essentially, this function loops through the given p:s from indexes 1 to nar Jon Pan Ere Fee, 27 |Men If the point is less than the point behind it and less than the point ahead of it, then itis a local minimum. Similarly, if the point in greater than the point be and greater than the point ahead of it, isa local maximum. However, if we simply do this, then the algorithm will detect many local minimums and maximums. Therefore, I have used the Pythagorean theorem to determine the distance between the previous point and current point, as well as the distance between the current point and next point. I made sure to only consider a point as a local maximum or minimum if the distance between it and the next point was greater than half of the distance between it and the previous point. Here is the result of plotting the local maximum and minimum points. AAPL — Smooth AAPL Moxinedincoiporssbinarlnesramsigestardnesancndttwtheorongenaptin in itd sae‘moot stat Sint ars Resse ta Sn ih Py Stan Oar |Pson a ae rn | F221 etn 40 38 36 0 10 20 30 40 50 60 Days Step 5. Line of best fit between local minimum and maximum Now we are going to find two lines of best fit. One for the local minimums and one for the local maximums. To do this, we will be using the sKlearn LinearRegression model. As you might already know, the equation for a linear line is y = mx + b, where mis the slope and bis the y intercept. We will create a function that will return the slope and y-intercept of a set of points et regression ceo(ss) ‘be eiven points Moxinedinciporbinerlnesramsigetandnesacndteswtheorongenaptn in itd sanept resect Sot th Pyne Sabana |For Fae Er, 221 aes oct pln_slope, 1cal_nin_int = repression ceof(10ee nln) 20 cal_pae soe, 200aT_mog_ int « regression ceot(10e1_moe) regression cet py hosted with by Gite view First we need to get the x and y points from pts , $0 to do this, we will be using list comprehension. Remember that ps is a list of a tuple of points. [Oe VDE G2, 2)e Be BP UB ¥4Ie OS) YI A= [otto] sor ot An pts] 2 ¥ = {pt(s] 4or ot An pts] 6x parry 1 y= renareayQ) 9 # Me ned to reshage to (1,19, Because that ds the format thas sklearn wil expect the Jnput 22 Moresnagelt 3) Moxinedinipiorsbinarlsesraia.petaranesandntnetorongwneap tn ted see‘moot ar |Pon fo ae rh, 221 aston ‘To we just have to create a LinearRegression model and fit our x and y data. 1 det regression ceor(ps) 2 X= mparay(ipeie) for pt £9 atsDseeshope(-L, 3) 3 ye mpasaytipe(a) for wt 29 ats) 6nd = Linear tagressfont) 5 modesty 9} loeal_ninsope, local pin snt = regression cof {local nin) lecl_pax_slope, local_pox int « repression ceof(leel pox) Step 6. Creating support and resistance lines Creating the support and resistance lines will be fairly simple. We will use the equation y = mx + b. 1 otysmenee Moxinedinoiporinerlnesrams.gestantnesacndttwtheorongenaptin nite v8‘moot tat Supt an Resac ta Sc th Pen [yS 2 support = (Locl_pin slope * na.arrey(sertes.tndex) + 20ca} nest nar Jon Pan Ee Feo, 27 |Aen ocala slope * npwarray(serses.inéex)) + Local nin Now it’s time to plot our support and resistance lines and see how accurate they are. This is how they look on the smooth graph. AAPL — Smooth AAPL 481 — support — Resistance 46 a4 Ea 40 38 36 0 yw 20S Days Mosman coiporhinerlnesrams.getantnesacndtntwthorongenaptn in iti‘moot tat Supt an Reeac ta Se th Pen [5 This is how they look on the real graph. nar Jon Pan Ere Fee, 27 |Men pisstle(eymol) ple atel(‘oays") pls ylatel(‘Prices") Lapel-syntol) (eumort, Label'support', ce") plt.plottreststance, label-"Resistance', ce") pits tegendt) AAPL — APL — Support — Resistance Moxinedincoiporinerlnesrasigestansnesacndtntcewtheorongentaptn in itd sme‘moot tat Supt nese tS ah Pye by Saban Oa [Pon a Fae ri F221 Maen eT 0 10 20 30 40 50 60 Days It looks quite accurate to me. You can get the code and Jupyter Notebook for this project in my GitHub repository over her Python Stocks Algorithms DstaSeionce Programming Learn more. Make Medium yours. Share your thinking. Moxinedincoiporrsinerlnesras.gestarnesancndttwthorongenapt in ited se
You might also like
high-frequency-trading-final-pres-slides
PDF
No ratings yet
high-frequency-trading-final-pres-slides
43 pages
UltimateTrader+G P@FB
PDF
No ratings yet
UltimateTrader+G P@FB
23 pages
The RSI Delta Indicator. Enhancing Momentum Trading
PDF
No ratings yet
The RSI Delta Indicator. Enhancing Momentum Trading
21 pages
Bookmap Masterclass Basic and Advanced Englunlockeda4 PDF Free Pages 3 - Compressed
PDF
No ratings yet
Bookmap Masterclass Basic and Advanced Englunlockeda4 PDF Free Pages 3 - Compressed
70 pages
Trend Lines, Supports and Resistances
PDF
No ratings yet
Trend Lines, Supports and Resistances
8 pages
JMA Quantum Edge
PDF
No ratings yet
JMA Quantum Edge
13 pages
MACD Technical Indicator
PDF
No ratings yet
MACD Technical Indicator
6 pages
Interactive Brokers API Reference Guide
PDF
No ratings yet
Interactive Brokers API Reference Guide
602 pages
Automatic Extraction and Identification of Chart Patterns Towards Financial Forecast
PDF
No ratings yet
Automatic Extraction and Identification of Chart Patterns Towards Financial Forecast
12 pages
RoyalPrince Oscillator With Crossover (2)
PDF
No ratings yet
RoyalPrince Oscillator With Crossover (2)
1 page
On Machine Learning Based Cryptocurrency Trading
PDF
No ratings yet
On Machine Learning Based Cryptocurrency Trading
121 pages
Head & Shoulders, Algorithmically
PDF
No ratings yet
Head & Shoulders, Algorithmically
14 pages
Hidden Divergence - Chamane's Guidelines
PDF
100% (1)
Hidden Divergence - Chamane's Guidelines
13 pages
Interactive Brokers in Python With Backtrader by Daniel Rodrig-Job 6
PDF
No ratings yet
Interactive Brokers in Python With Backtrader by Daniel Rodrig-Job 6
10 pages
Stat444 Notes
PDF
No ratings yet
Stat444 Notes
37 pages
Roadmap Ultimate Edition
PDF
No ratings yet
Roadmap Ultimate Edition
74 pages
Rsi Divergence by Traders Academy
PDF
No ratings yet
Rsi Divergence by Traders Academy
2 pages
Rsi BB Macd Ad
PDF
No ratings yet
Rsi BB Macd Ad
24 pages
Gap Trading. An Introduction & Back-Test in Python
PDF
No ratings yet
Gap Trading. An Introduction & Back-Test in Python
15 pages
Linear_Regression
PDF
No ratings yet
Linear_Regression
18 pages
Dokumen - Tips - Homework 3 Solution Ee263 Introduction To Linear Ee263 Homework 3 Solution
PDF
No ratings yet
Dokumen - Tips - Homework 3 Solution Ee263 Introduction To Linear Ee263 Homework 3 Solution
27 pages
HFT - Hardware Low Latency Techniques
PDF
No ratings yet
HFT - Hardware Low Latency Techniques
4 pages
Heiken-Ashi Trading - The Full Guide in Python
PDF
100% (2)
Heiken-Ashi Trading - The Full Guide in Python
14 pages
ML External File-43
PDF
No ratings yet
ML External File-43
23 pages
What Is Application Function Library (AFL) ?
PDF
No ratings yet
What Is Application Function Library (AFL) ?
12 pages
How To Trade Forex Using Roboforex Strategyquant Software
PDF
No ratings yet
How To Trade Forex Using Roboforex Strategyquant Software
44 pages
Creating A Modified Fisher Transformation For Profitable Trading.
PDF
No ratings yet
Creating A Modified Fisher Transformation For Profitable Trading.
21 pages
How To Export Data From Quant Data Manager and Import To Metatrader 5
PDF
No ratings yet
How To Export Data From Quant Data Manager and Import To Metatrader 5
18 pages
2019 Optiver Fact Sheet
PDF
No ratings yet
2019 Optiver Fact Sheet
3 pages
ML Lab-3
PDF
No ratings yet
ML Lab-3
14 pages
Machine Learning Lab
PDF
No ratings yet
Machine Learning Lab
23 pages
Quantzilla-2.0-Brochure Adv
PDF
No ratings yet
Quantzilla-2.0-Brochure Adv
28 pages
A Q-Learning Agent For Automated Trading in Equity Stock Markets
PDF
No ratings yet
A Q-Learning Agent For Automated Trading in Equity Stock Markets
12 pages
Technical Analysis For Algorithmic Pattern Recognition: Project 2
PDF
No ratings yet
Technical Analysis For Algorithmic Pattern Recognition: Project 2
1 page
A Review of Reinforcement Learning For Financial Time Series Prediction and Portfolio Optimization
PDF
No ratings yet
A Review of Reinforcement Learning For Financial Time Series Prediction and Portfolio Optimization
38 pages
Technical Indicators and GRU-LSTM To Predict Stock Price
PDF
No ratings yet
Technical Indicators and GRU-LSTM To Predict Stock Price
36 pages
Building A Stock Option Valuation Model With Python Part II
PDF
No ratings yet
Building A Stock Option Valuation Model With Python Part II
18 pages
Applying Deep Learning To Enhance Momentum Trading Strategies in Stocks
PDF
100% (1)
Applying Deep Learning To Enhance Momentum Trading Strategies in Stocks
5 pages
JPMC - Task 1
PDF
No ratings yet
JPMC - Task 1
4 pages
MTA Symposium - My Notes (Vipul H. Ramaiya)
PDF
100% (2)
MTA Symposium - My Notes (Vipul H. Ramaiya)
12 pages
Wavelet LSTM Pred Indexes
PDF
No ratings yet
Wavelet LSTM Pred Indexes
8 pages
Time Series Forecasting With 2D Convolutions
PDF
No ratings yet
Time Series Forecasting With 2D Convolutions
33 pages
Importing High Quality Tick Data On MetaTrader 4 & 5
PDF
No ratings yet
Importing High Quality Tick Data On MetaTrader 4 & 5
34 pages
Bollinger Bands % With Adaptive Zones - Afl
PDF
No ratings yet
Bollinger Bands % With Adaptive Zones - Afl
2 pages
Test Strategy in MetaTrader 4 With Tick Precision
PDF
No ratings yet
Test Strategy in MetaTrader 4 With Tick Precision
15 pages
Conditions Indicators 9
PDF
No ratings yet
Conditions Indicators 9
11 pages
Building A Stock Option Valuation Model With Python Part I
PDF
No ratings yet
Building A Stock Option Valuation Model With Python Part I
17 pages
MACD and Histogram Divergence Detection
PDF
No ratings yet
MACD and Histogram Divergence Detection
9 pages
MN0036 Investment Management: Technical Analysis
PDF
No ratings yet
MN0036 Investment Management: Technical Analysis
21 pages
Moving Average
PDF
No ratings yet
Moving Average
17 pages
S I LSTM Stock Price Prediction Based On Multiple Data Sources and Sentiment Analysis
PDF
No ratings yet
S I LSTM Stock Price Prediction Based On Multiple Data Sources and Sentiment Analysis
20 pages
CMT1
PDF
100% (1)
CMT1
10 pages
Identifying Significant Chart Formations
PDF
No ratings yet
Identifying Significant Chart Formations
7 pages
How I Created A Bitcoin Trading Algorithm Using Sentiment Analysis With A 29% Return
PDF
No ratings yet
How I Created A Bitcoin Trading Algorithm Using Sentiment Analysis With A 29% Return
10 pages
The Augmented Bollinger Bands
PDF
No ratings yet
The Augmented Bollinger Bands
23 pages
Commonly Used Technical Indicators
PDF
No ratings yet
Commonly Used Technical Indicators
15 pages
Algo Trader Documentation
PDF
No ratings yet
Algo Trader Documentation
48 pages
Algorithmic Trading Models - Breakouts
PDF
No ratings yet
Algorithmic Trading Models - Breakouts
10 pages
Using Machine Learning To Locate Support and Resistance Lines For Stocks - by Suhail Saqan - The Startup - Jan, 2021 - Medium
PDF
No ratings yet
Using Machine Learning To Locate Support and Resistance Lines For Stocks - by Suhail Saqan - The Startup - Jan, 2021 - Medium
14 pages
Importing Data From Tick Data Into 3rd Party Software
PDF
No ratings yet
Importing Data From Tick Data Into 3rd Party Software
32 pages
Trading Strategy - Technical Analysis With Python TA-Lib
PDF
No ratings yet
Trading Strategy - Technical Analysis With Python TA-Lib
12 pages
A Machine Learning Framework For An Algorithmic Trading System PDF
PDF
No ratings yet
A Machine Learning Framework For An Algorithmic Trading System PDF
11 pages
Using Machine Learning To Locate Support and Resistance Lines For Stocks
PDF
No ratings yet
Using Machine Learning To Locate Support and Resistance Lines For Stocks
14 pages
WINNER: Trading Software $1000 WINNER: Trading Software $500
PDF
No ratings yet
WINNER: Trading Software $1000 WINNER: Trading Software $500
7 pages
Technical Analysis Notes
PDF
No ratings yet
Technical Analysis Notes
6 pages
Technical Analysis 20001
PDF
100% (1)
Technical Analysis 20001
38 pages
Back Testing With 99 Percent Modelling V1
PDF
No ratings yet
Back Testing With 99 Percent Modelling V1
4 pages
Genetic Trading
PDF
No ratings yet
Genetic Trading
22 pages
Body of Knowledge 2014 2
PDF
No ratings yet
Body of Knowledge 2014 2
5 pages
MACD - Pine Script
PDF
No ratings yet
MACD - Pine Script
1 page
MQL Book File List
PDF
No ratings yet
MQL Book File List
2 pages
Trend Detection: by Arthur Merrill
PDF
No ratings yet
Trend Detection: by Arthur Merrill
3 pages
PB-BNF Expiry
PDF
No ratings yet
PB-BNF Expiry
7 pages
High Frequency Trading Final Paper
PDF
No ratings yet
High Frequency Trading Final Paper
7 pages
Algorithmic Trading TCG
PDF
No ratings yet
Algorithmic Trading TCG
18 pages
V25 C10 193verv
PDF
No ratings yet
V25 C10 193verv
10 pages
MT Metastock Part 3 Relative Strength Comparison RSC The Key Success Tool in Trading by Stock Market Sectors
PDF
No ratings yet
MT Metastock Part 3 Relative Strength Comparison RSC The Key Success Tool in Trading by Stock Market Sectors
2 pages
Technical Analysis in Major Brokerages and Financial Media Mathematical Investor
PDF
No ratings yet
Technical Analysis in Major Brokerages and Financial Media Mathematical Investor
4 pages