Building a PlotLy $GME Chart in Python
Skills:
LLM Foundations80%Prompt Craft70%Prompting Basics60%Advanced Prompting60%Prompt Systems Engineering60%
Key Takeaways
The video demonstrates how to build a PlotLy chart for $GME stock in Python, utilizing the Alpha Vantage API for data and incorporating various technical indicators such as simple moving average, on balance volume, and rate of change. It covers the process from setting up the environment to creating interactive charts with Plotly and analyzing stock data.
Full Transcript
hi and welcome to a video we're going to do something a little bit different today and we're going to build a python project from scratch and what i want to do is build a plotly chart and feed stock information into this chart from the alphavantage api which is like very similar to the yahoo finance api as far as i am aware i haven't used either of them that much to be honest but they seem to have pretty good documentation and it's a little bit different and i just want to explore using this api rather than you finance which is like the sort of de facto standard almost so after we give some stock information to this chart we want to actually chart it and plot a few sort of interesting indicators so i've kind of you can see on the screen i've gone for a few different indicators here that that i mean i haven't really seen any of these before not i'm not a finance person so you know i don't claim to know what all this means exactly but obviously the simple moving average is obviously it's a moving average of the stock price over time so that that one is quite simple and i just want to include that in there so that we can see that we're actually doing things right and we're applying these indicators correctly and then we have this this thing called the on balance volume which sort of measures positive and negative volume flow so you know the reason i'm including all these volume and balancing and momentum-based indicators at the moment in the stock market you know we have the big wall streets versus wall street's bets and i want to sort of use this opportunity to just build sort of a cool project that at least gives a little bit of information on what is actually happening in terms of the actual stock market now a lot of these are you know traditional indicators they've been around for a few years so i don't know if they're actually going to be useful or not because obviously the market conditions at the moment are not normal it'd be interesting to see and then we have this balance of power which is uh the market strength of buyers versus sellers so again pretty relevant rate of change you know maybe we'll include this i'm not sure this one called arun um which looks quite interesting actually so if we go on here and you can see that it essentially gives us this so we get like a downtrend and uptrend indicator line and whenever these cross over that's typically when you see an uptrend or downtrend and i think that'd be quite interesting to see as well and this so this is based on the time between highs and lows in a specific time period so what you're doing here is measuring the the lowest point and that gives you your sort of the points of the edges or the the peeps and troughs of this indicator here so i think that would be pretty interesting and then we have this chicken oscillator and i thought this would also be quite interesting because this is uh tracking the strength of price movements and the underlying buying and selling pressure to estimate demand so that should also be pretty interesting so let's go ahead and we're going to start coding this up okay so the first thing we need to do is figure out how to use the alpha vantage api so basically every all the data that we want we can get from here so the main part of that is going to be this time series intraday api so we'll just go ahead and figure this out okay so if we just take this and let's let's figure out the format that data is actually going to come in with okay so we have our interval which we included here symbol we're gonna change that to jimmy and then we have this time series which is in the dictionary and inside here we have our open high low close and volume as well which is interesting so okay let's pull that together so first i do want to have the candlestick format so so i came up with this so candlestick is is this whereas if we were just tracking the sort of average it would look like this so first we're just going to do this with blackley and then we'll figure out how to build the candlestick so we're going to go ahead and try and build that so for now we're just going to use this data and we'll get into a data frame so import pandas and just clean it up a little bit okay so i'm going to initialize the data frame first and then we'll just loop through each of these entries we'll have the date and time in one column the open high low close and volume in other columns and we'll just append each one of these as we so work through so here we're just going to print out each of the date time keys because here we need to actually access this in order to get into our actual values here so just print this out and then we need to also add this there we go so these five minute intervals and this is what we're going to work with let's just make things a little bit easier to read i know we're going to do here is append a dictionary which is going to contain each one of these columns you whenever we're doing this append method we also need to add ignore index onto the end otherwise we'll get a index error which is is really annoying and it just happens every time usually i forget to add this in before seeing the error but this time apparently not okay so we also need to add in dt here because at the moment we're trying to access the the whole dictionary the top level of it whereas we need to access each data frame section of it see like i remembered it this time and i still got it wrong okay so now we have all of our data in a more easy to read format so i want to see why these are all the same maybe that's normal okay so they're not all the same that you change so we are also looking at ibm and ibm i don't think it's a particularly volatile stock okay so i'm going to switch this data over to gme for that i do have i do have my key somewhere okay so i have my key here now it's just in a text file so when you're reading from text files like your keys which is generally i think what you'll do a lot of the time when you're just developing something or i i mean you could put it straight into your code um i wouldn't recommend but i mean it's up to you so you just need to do with open specified file r for read and just put key like this and that should work so now take this and let's swap for gme an api key i want to use what i have defined here i'm going to put key in there convert this into an string okay let's see okay that worked it's cool and let's compare this so these were hardly changing um supposed to change a little bit here between these but actually in within these are high and low uh within five minutes of us didn't really change much and maybe it wasn't for game stop either let's see i need to refresh here a little more movement interesting okay so i haven't used slightly that much before so let's just try and figure out i mean if you're using the creating the candlestick a graphite i'm not really sure how how i'm going to go about that yet see i don't even have it installed on this on this instance oh it's all before i did uh so i i got my api key i didn't really explain how you can get one too so all you need to do i think it says on here i look so you just go to this page and you click claim your free api key go on there and or you just put whatever you're doing so i supposed to meet software developer maybe put student if you're learning uh but either way it doesn't really matter because you're gonna get this free api key anyway um it's not they give it to you straight away i think from what i can remember so it's not really an issue there so let's go back to politely and let's just install that quickly yeah it looks like just pip installed plotly and i think as well because i haven't installed it in this environment i'm going to have to install a load of jupiter extensions as well to actually show the plot but let's let's see let's see if it works first okay so let's get that data again don't need to see that again okay so see that let's just go with the open for now okay yeah so you can see that it's not showing anything and this is an issue with one of the plotly extensions so we just need to install those it's not difficult though from what i remember yeah just plot the extension here so it's the jupiter lab extension so that's checking what we have okay so i need these two jupiter lab extension of jupiter lab plotly and plotly widget so let's go and install those two i realized maybe this is too small for you to see so these two are going to do although these are the uninstall we're going to install them okay so then we need to install the other one as well then we might need to restart youtube but let's see if it works i'm also going to need a stupid lab build as well just in case i need it i don't think i will but let's try okay so let's go back to our lab and let's just refresh and try let's see if it works if not we'll just restart yeah okay so let's just restart it quickly okay let's try this again here we go so it's working now so yeah that's pretty cool um although what is this we have yeah that's weird do we need to okay let me check what these are i assume these must be strings uh they're not actually all actual numbers yeah so we need to convert these into numbers as well okay so we can do that with the two numeric function and then just pass the the columns that we want in there i'm not sure if we can do all of them at once or if we have to do one at a time let's try it all okay yeah so just one at a time so let's just take this list also not sure if it does it in place or not as well let's just have a quick look okay so i think it does not do it in place let's see okay so okay so no it doesn't right there we go so now it's a float and this should work now there we go so that looks pretty cool we have this sort of interactive interactivity with the chart which this is why i wanted to use plotly over like matplotlib i think this is definitely something we want to have in the chart so we have that now let's before we do the candlesticks let's just try putting on the a few of the indicators and see how that looks and see if they're straightforward or not so this simple moving average so let's add that in okay so let's just clean this api requesting up a little bit okay so that is our api and then we just want to change these just use it like this instead okay so we have resume we want gme weekly uh interval no we want so five minutes like oh no we don't we so say it's a moving average so yeah let's go weekly and see how that looks time period this is like 10 days what do we have here we don't have a time period so we do want to adjust that a little bit so maybe we can let me zoom in a little bit here probably can't see anything so the function interval so yeah we have a few let's go like a 60 minute because then we can actually see that on the time period that we're already looking at number of data points but okay let's change this to a 60 minute moving average so now we don't want to change that one i will change this one and add in the api key as well okay let's just see what we get okay cool so we have this okay we have this technical analysis info okay so we want to pulling data out of here okay cool so i wonder if you can add like multiple functions i don't know but let's stick with this i'm basically going to do the same thing again where we take these but this time we are getting our moving average so technical analysis let's put this in and all we want here is the date time and then this estimate value so to analysis i think that's fine so now just change this to sma i think that should be okay let's see okay we let's uh put that in here so i don't do that again now just over wrote all of that i mean i need to change this okay okay let's cool so we will also need to do this again right where we convert it to numeric let's just add sma head here and let's plot this and let's just see what we get okay so we got a lot more data here so we need to restrict that so you're only within what we have here but at the same time i think it would be cool if we got a little more data than what we have but let's just keep it dynamic for now so we just take the minimum date time that we have within uh df and then we'll just apply that to all of our technical indicators that we're only pulling it from then onwards we could probably get from the api but let's let's just filter the data frame yeah because here i'm not sure they do actually give you like a date time limit that you can just extract from that point so yeah i think we need to do it from the data frame anyway so after we do all of this let's also get the and the min date time that will just be df date time dot min we also need to re-extract all of that because i overwrote it earlier okay and then let's check our date time should be something reasonable so yeah i think that makes sense uh it's like 12 hours before no about eight hours before this point so that's fine so eight hours of data in there so when we do this all we need to do is just filter out anything that is below that date time so all we do is sma equals sma where the date time is greater than or equal to min dt okay so let's just check so we have the length of sma here so we've got 560 rows and then if we do this we filter it down to nine which is is more reasonable so we have i think we had around eight hours in there so nine nine hours maybe and we're taking it in 60 minute intervals so that makes sense and then if we do that cool so we get our sma indicator here so let's plot those both together and see see how it looks okay so apparently you need to also add fig abscatta and then you add mode lines onto the end to add another line hmm so maybe i didn't see this okay so line is especially lines i think okay cool so that looks good we have our sma and our actual plot so that seems pretty straightforward but now we actually want to maybe add candlesticks into this because that would be pretty cool in my opinion no idea how we can do that in politely so let's try and figure it out actually looks really simple so i need to use the graph objects instead of express let's try and add that then so if it's really that easy then this was super easy oh well okay so that's our candlestick that's really cool i don't really know from this bit but i mean i suppose it's kind of cool let's just go with it for now so we have that and then we also want to the add scatter again to add the sma okay that's pretty cool so now we just want to add in a few of those other indicators so what do we have we have this unbalanced volume balance of power rate of change arun and triken so let's do this on balance volume one first i'm going to add in a couple of functions to actually do things as well so like here every time that we want to convert these to numeric numeric i think we want to convert anything that's just not called date time so we can just add that as a as a function let's do two numeric then just add our data frame and then we just go for call in df.columns we only want to do this if call is not equal to date time so every other column we do want to convert to numeric and just return that okay so instead of needing to write it out every time we just write to numeric when we have our data so okay so here we're getting the time series data we also want to convert it to numeric here you can leave it as df okay let's just test that see how it is okay looks good so we can remove that and then we are getting our sma data so let's just move that into one box as well and this we just want sma and small okay let's move this up to the top as well i want to add in a few more here so we have which one is is the on balance i think yeah the unbalanced volume let's do that one i'm probably gonna do something similar here again right so let's go to our documentation and let's get the on balance obviously so we have this so just paste that there do something pretty similar again so we have the api key it's going to be our key um the interval should probably check what that actually means for this so this was probably the one that i was most interested in seeing it's like a it measures the positive negative flow with the intention of identifying where you've got a load of sort of big sort of big investors putting a lot of money into it or sorry when you've got a lot of smaller investors putting a lot of money into it so the basically the volume is higher because obviously the retail investors are putting a lot more bets on but they're smaller they're smaller buys or sells [Music] so that i imagine would be how this works although i you know i really i've just read this very briefly before so it could be completely wrong but it sounds pretty interesting from reading this so let's just try and implement it i'm going to go with shorter time period than what it's suggesting here because i don't know if we we will see anything with that or sure to interval sorry then gme okay so let's put this in now we need to see what we actually get here okay so this technical analysis and it's basically the same as before when we had the sma so we could probably write a function that does that for us but let's let's just do it like this for now so just change this to abv it's pretty easy change okay so let's try that i think this one should be pretty interesting to see and i don't know to be honest i don't we're gonna need to put these on another chart because obviously that isn't going to to work i wonder i imagine there isn't an easy way of doing it but let's just check quickly yeah okay so you should probably have a look at how people normally do this okay and let's try and stick with the graph objects so i don't know if it's going to go yeah this just gives us express so okay so we're actually just gonna use the scatter um okay cool so right something like this we go scatter and then we do we add maybe some why okay so we just swapped our abv okay cool so we have this it's interesting so this is our on balance value is that right unbalanced volume sorry so i wonder if this would make more sense because it's volume to have it as a like a bar chart at the bottom because i think that's how these things usually work hmm that'll be interesting i think okay so we have subplots here we have space very similar to okay perfect so that looks kind of good but we want step so i mean it's just the same as hard as i know yeah the only thing that i'm not doing here is matching on the x-axis but again that shouldn't really be an issue for us because we do actually have we have already matched on the x-axis so let's give that a go so we want subplots make and we we penetrate this time instead so so this time i'm going to append trace i don't know if we can add scatter okay no so we need to yeah i don't know if we should have really been doing that anyway because it needs to be more like this and then i suppose we can add mode here or maybe not less that's not for now it's just pen trace and we do that for sma as well let's see how how that goes i just want two rows and we've already imported this so let's okay so we have data why okay and we also need to specify the row in the column as well okay so this is gonna be row sean this yeah this one will be row two this one here will be row one coldwell co one and we just need to remove the data part that we added in here so yeah this pen trays and just remove that okay so yeah it's pretty messy what ah okay so it's because we have this so i kind of want to just get rid of that for now so i don't know what it is like excited slider maybe okay so this is kind of what we need i think yeah so just need to update the layout um and just make this false and i think let's put this up to here type date okay should work let's see okay cool so we have so now we have this or is it most useful like how do you normally let's have a look at how this unbalance volume is normally plotted okay so this is the unbalanced volume here so it's just like in the line chart underneath the other line chart so it's basically what we have already this is um interesting so here's like a confirming trade when they're both in the same direction okay so this is what we want to look at here when the price and obvi are making higher peaks and higher troughs upward trend is likely to continue so when they're both going up when i'm making lower and lower the there's a downward trend if the obv is rising accumulation might may be taking place so if we have a look at this so you can see they're both going down so that's like okay the downward trend is likely to continue and here they're both going up so upward trend is likely to continue and then they're just leveling out here so it's not really anything of interest but i suppose here it's kind of balanced and we see the momentum so pushing up again just before it rises so maybe that is what we're sort of looking for either way it's pretty interesting to to actually look at and then i also want to probably have a look at this shaking oscillator as well so it looks pretty interesting i think so if we go back into the api documentation so i think it's this one yeah so it's the chicken a d line okay so when this is measuring big investors i think so when you're looking for where the big investors are putting their money this is supposed to be an indicator of it as far as i understand so it examines the strength of price moves and the underlying buying and selling pressure to try and measure the demand and divergence between the price and the oscillator is indicated most frequent single not and flags a short term reversal price so that'd be interesting to see if we can maybe find that happening around here or around here so let's let's figure that one out as well you so so this time we're just replacing the function with a d interval this one's doing daily so maybe this is the sort of thing we want to be looking at more frequently so we have the key gme and i think that's pretty much what we want let's put this down to um let's go 60 minutes again now we can maybe change okay so let's see what we get so it's just tracking a d okay cool so let's pull that through i'm just gonna use this code again replace this um something called a d or let's call it chat chi canadi okay and what is it just tracking id right yeah so that's all we want let me just replace this with you i can id again and add chad down here as well okay um so i think so this bit we need what do we want this bit to be so just checking 80. okay so we've got two numeric so that all looks pretty good to me let's add that in so obviously that's gonna need another another row so let's just add that in chad and we'll put this at the bottom we need to add another another row here let's see how that looks so okay cool doesn't look bad it's interesting so the point was that one day diverge is a indication of a sort of a movement change and that indicates a reversal in price so i know i suppose here is like the only bit where it kind of doesn't follow the price because the price is pretty level but it's even going down here right and here it starts to go up so maybe that's what's that's indicating the reversal in price change but it's also kind of difficult to because we're only looking at our time here so we should probably increase the you know how much we're viewing so let's just go to like 10 minutes and see how that looks okay was um oh i bet i bet we can't do that yeah it's not returning anything it's probably the interval oh you see okay so we need 15 minutes let's go five see what it's like okay so that's more interesting so now we just see like this big movement up here but then i bet if we if we look at it long term it's pretty probably pretty stable so let's try and increase how much data we're actually looking at so the interval um okay so what's our men dt okay so this is returning okay so this is actually returning friday so i was wrong early when i said this is uh saturday's data just kind of stupid but does this actually return us anything more than what we have here okay cool so actually on this full rather than compact so output size is going to be full so that should give us a lot more data so before we were heading it 11 on the 29th let's see what we have now okay that's way further back that's cool uh we probably i don't know if we'll be able to even see that much though so maybe it's worth maybe not doing a five-minute intervals we're going like daily let's see what that looks like oh of course that changes this as well so let's change it here hopefully that should work okay now so let's check what we are returning okay so oh because we are doing the intraday we can only go 60 minutes so let's change that to 60 minutes okay i know guys even further back i wasn't expecting that it's pretty good there's um a lot of data so now i'm thinking what do we want here maybe daily what do we want daily let's go weekly for now and these maybe we can go daily so look at these how they are now so here's obviously the source of volume it's pushing up loads and everyone's buying into it but you can see there's this massive increase here this is back in at the start of january let me see that so started january and yeah it was going up but not loads you can just see it kind of pushing up pushing up and then here you have same again it starts to go a little bit crazy so here it went over z went greater than zero and this is january 22nd so here this is before it all went crazy so i i think it kind of went down here and then back up let me see it's pretty interesting so i mean i think that's it for for this video for now it's probably i mean obviously there's a lot we could do like tidying up but just in getting a few indicators together and the actual stock data in in candlesticks and it's pretty easy i mean i've never done most of this before with plotly and it's super easy to figure out so that's pretty good so i i suppose that's it so and thank you for watching the video i'll leave all this code on github as well i'll add a link in the description if it helps i mean it's not too much anyway but might help you pull things together a bit quicker so anyway thank you for watching and i will see you again next time bye
Original Description
A code-along video covering the coding process from imagination to Python.
Something a little different, I'm not overly keen on this format - it's pretty long - but I've recorded it and I think maybe this can be useful for a few of you.
I haven't prepared anything beforehand, this is just going into the coding process with a rough outline of wanting to build a stock chart for GME (GameStop) and adding a few technical indicators - to get more familiar with PlotLy and the AlphaVantage API.
So, it's a weird one, but I hope a few of you enjoy it - thanks :)
🤖 70% Discount on the NLP With Transformers in Python course:
https://bit.ly/3DFvvY5
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from James Briggs · James Briggs · 16 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
▶
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Stoic Philosophy Text Generation with TensorFlow
James Briggs
How to Build TensorFlow Pipelines with tf.data.Dataset
James Briggs
Every New Feature in Python 3.10.0a2
James Briggs
How-to Build a Transformer for Language Classification in TensorFlow
James Briggs
How-to use the Kaggle API in Python
James Briggs
Language Generation with OpenAI's GPT-2 in Python
James Briggs
Text Summarization with Google AI's T5 in Python
James Briggs
How-to do Sentiment Analysis with Flair in Python
James Briggs
Python Environment Setup for Machine Learning
James Briggs
Sequential Model - TensorFlow Essentials #1
James Briggs
Functional API - TensorFlow Essentials #2
James Briggs
Training Parameters - TensorFlow Essentials #3
James Briggs
Input Data Pipelines - TensorFlow Essentials #4
James Briggs
6 of Python's Newest and Best Features (3.7-3.9)
James Briggs
Novice to Advanced RegEx in Less-than 30 Minutes + Python
James Briggs
Building a PlotLy $GME Chart in Python
James Briggs
How-to Use The Reddit API in Python
James Briggs
How to Build Custom Q&A Transformer Models in Python
James Briggs
How to Build Q&A Models in Python (Transformers)
James Briggs
How-to Decode Outputs From NLP Models (Python)
James Briggs
Identify Stocks on Reddit with SpaCy (NER in Python)
James Briggs
Sentiment Analysis on ANY Length of Text With Transformers (Python)
James Briggs
Unicode Normalization for NLP in Python
James Briggs
The NEW Match-Case Statement in Python 3.10
James Briggs
Multi-Class Language Classification With BERT in TensorFlow
James Briggs
How to Build Python Packages for Pip
James Briggs
How-to Structure a Q&A ML App
James Briggs
How to Index Q&A Data With Haystack and Elasticsearch
James Briggs
Q&A Document Retrieval With DPR
James Briggs
How to Use Type Annotations in Python
James Briggs
Extractive Q&A With Haystack and FastAPI in Python
James Briggs
Sentence Similarity With Sentence-Transformers in Python
James Briggs
Sentence Similarity With Transformers and PyTorch (Python)
James Briggs
NER With Transformers and spaCy (Python)
James Briggs
Training BERT #1 - Masked-Language Modeling (MLM)
James Briggs
Training BERT #2 - Train With Masked-Language Modeling (MLM)
James Briggs
Training BERT #3 - Next Sentence Prediction (NSP)
James Briggs
Training BERT #4 - Train With Next Sentence Prediction (NSP)
James Briggs
FREE 11 Hour NLP Transformers Course (Next 3 Days Only)
James Briggs
New Features in Python 3.10
James Briggs
Training BERT #5 - Training With BertForPretraining
James Briggs
How-to Use HuggingFace's Datasets - Transformers From Scratch #1
James Briggs
Build a Custom Transformer Tokenizer - Transformers From Scratch #2
James Briggs
3 Traditional Methods for Similarity Search (Jaccard, w-shingling, Levenshtein)
James Briggs
3 Vector-based Methods for Similarity Search (TF-IDF, BM25, SBERT)
James Briggs
Building MLM Training Input Pipeline - Transformers From Scratch #3
James Briggs
Training and Testing an Italian BERT - Transformers From Scratch #4
James Briggs
Faiss - Introduction to Similarity Search
James Briggs
Angular App Setup With Material - Stoic Q&A #5
James Briggs
Why are there so many Tokenization methods in HF Transformers?
James Briggs
Choosing Indexes for Similarity Search (Faiss in Python)
James Briggs
Locality Sensitive Hashing (LSH) for Search with Shingling + MinHashing (Python)
James Briggs
How LSH Random Projection works in search (+Python)
James Briggs
IndexLSH for Fast Similarity Search in Faiss
James Briggs
Faiss - Vector Compression with PQ and IVFPQ (in Python)
James Briggs
Product Quantization for Vector Similarity Search (+ Python)
James Briggs
How to Build a Bert WordPiece Tokenizer in Python and HuggingFace
James Briggs
Metadata Filtering for Vector Search + Latest Filter Tech
James Briggs
Build NLP Pipelines with HuggingFace Datasets
James Briggs
Composite Indexes and the Faiss Index Factory
James Briggs
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Inference Optimization in Large Language Models
Medium · Machine Learning
Why Most People Get Mediocre Results from Claude and ChatGPT (And It Has Nothing to Do With the AI)
Medium · ChatGPT
Unlocking the LLM’s Hidden Knowledge Engine: The 3X Matrix Expansion in FFN and SwiGLU
Medium · LLM
A Brief History of Artificial Intelligence and Machine Learning
Medium · Machine Learning
🎓
Tutor Explanation
DeepCamp AI