Evaluate Cryptocurrency Craze in MATLAB

Evaluate Cryptocurrency Craze in MATLAB

Hi. Last week, I created a poll inquiring about the next live interactive session topic. The options from our side were Share Market, Cryptocurrency, Blockchain, Audio Processing, and Video Processing. On a different platform, different options were winners. The majority of votes came for Cryptocurrency and Audio Processing. We have chosen to work on both for future topics. Recently we had a practice run for Cryptocurrency. At the end of the discussion, I felt that most of the questions, including mine, targeted legality, pros, and cons instead of technical details where we should have focused more. What do you suggest, whether we should keep the discussion mixed with all kinds of questions or purely technical without involving questions like:

  • How do you invest in Cryptocurrency?
  • Could you please explain the cryptography done with Cryptocurrency?
  • What intrinsic value do Cryptocurrencies have, like Shares or Gold?
  • What kind of regulations or rules applies to Cryptocurrency?
  • How are NFTs and Blockchain related to Cryptocurrencies?
  • What is the comparison of Cryptocurrency against gold?
  • In which countries Cryptos are being used? For what purpose they are being used?
  • What is the reason for Cryptos to go up or down?

What question do you think we should include further? Do you have any questions for which you are looking for an answer? Share your questions here in the comments!

Disclaimer: You will not find any financial advice here or in our live session. We are no expert in Cryptocurrency, crypto art, NFTs, their trading, etc. This article and live session aim to increase awareness for education and research purposes. We wish to display some plots derived from data with our own subjective opinions. The data will be retrieved from CryptoCompare.com, a separate entity with its own policy and out of our control.
        

I am using cryptocompare.com for fetching various Cryptocurrencies. To get real-time data, we don't need API Key access. To retrieve Historial Data, we will need API Key. I will guide you for that in the coming paragraphs. But first, How do you fetch the Real-Time value of Bitcoin in INR or other currencies?

fprintf('Date & Time of Code Execution: %s IST\n',datestr(now));
%% Get Bitcoin in single currency: INR
url = 'https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=INR';
res = webread(url);
fprintf('\n1 Bitcoin = %.2f INR\n',res.INR)        

Date & Time of Code Execution: 15-Mar-2022 10:07:48 IST

1 Bitcoin = 3139914.59 INR

If you want to get the data for Ethereum instead of Bitcoin, you can replace BTC with ETH in the URL. Now, if you wish to get the price of Bitcoin in multiple currencies together, How will you do it? Let's see the code below:

%% Get Bitcoin in multiple currencies: USD, INR, EUR

url = 'https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,INR,EUR';

res = webread(url);

fprintf('\n1 Bitcoin = %.2f USD = %.2f INR = %.2f EUR\n',res.USD,res.INR,res.EUR)        

1 Bitcoin = 38821.76 USD = 3139914.59 INR = 35371.95 EUR

Please note that these prices were obtained at my trial run on 15th March 2022. The price can be different when you try it in the future. Now let us try and get historical data for Bitcoin in INR since its beginning. We will need to create API Key for this. Go to https://min-api.cryptocompare.com/pricing and choose the free plan. Once your account is created, Go to "Create an API Key" under API Key Section. Give a suitable name with full Read/Write access.

No alt text provided for this image

Post that, your API key will be ready, and it could be copied to our MATLAB Program.

No alt text provided for this image

We will use the following code after replacing your own API Key.

%% Fetch Historical Data of Bitcoin in INR

api_key = '<YOUR KEY HERE>';

url ='https://min-api.cryptocompare.com/data/v2/histoday';

fsym = 'BTC'; % The cryptocurrency symbol of interest

tsym = 'INR'; % The currency symbol to convert into 

limit = 2000; % The number of data points to return (Max: 2000)

toTs = -1; % Returns historical data before that timestamp.

data = [];

for i = 1:2 % To cover limitation of 2000 entries per fetch

???fullurl = [url '?fsym=' fsym '&tsym=' tsym '&limit=' num2str(limit),...

???????'&toTs=' num2str(toTs) '&api_key=' api_key];

???res = webread(fullurl); % Read data from web

???toTs = res.Data.TimeFrom; % For the next iteration

???s2t = struct2table(res.Data.Data); % Convert data in table form

???% Convert epoch time to datetime pattern of MATLAB

???s2t.time = datetime(s2t.time, 'convertfrom','posixtime');

???% Convert data in timetable format with time as reference

???tt = table2timetable(s2t,'RowTimes','time');

???data = [data; tt]; % Merge data of different iterations

end

data = retime(data,'daily'); % Remove duplicate dates and arrange properly

disp(tail(data))        
No alt text provided for this image

As usual, I am not explaining the code, and I expect you to try it in your system and understand what has been done. If you have any doubt, you can post in the comments, and I will try to assist you! Now, if we want to plot this resulting data, We can do so:

figure; plot(data.time,data.close,'-.')

xlabel('Date'); ylabel('Price of Bitcoin in INR');

title('Historical: Bitcoin to INR')        
No alt text provided for this image

Suppose we want to see the performance of Bitcoin in the last 1 year; how we will do that?

year = 1;

t = data.time(end-365*year:end); % time 

p = data.close(end-365*year:end); % closing price

figure;?plot(t,p,'-o'); grid on;

xlabel('Date'); ylabel('Price of Bitcoin in INR');

title('Historical (Last 1 Year): Bitcoin to INR');        
No alt text provided for this image

Since we achieved the objective of our article, I will end programming here and give you some tasks to do yourself. Here are your To-Dos:

  1. Compare Bitcoin (BTC) & Ethereum (ETH) closing price growth from 2017 to 2022.
  2. Find the best performing & worst-performing 1 day, 1 week, 1 month, and 1 year period for Bitcoin since its inception.

I hope you guys will try the above tasks, and I would love to see your code or outcome in the comment section. I even gave you a couple of To-Dos in the previous week's article at Bollywood Movie Mania in MATLAB. I hope you will solve them if you have not tried yet. What do you think of these articles? Let me know in comments or get in touch with me at [email protected]

Happy MATLABing!

要查看或添加评论,请登录

Gunjan Gupta的更多文章

  • Decoding G20 Summit 2023: What a MATLAB WordCloud Reveals

    Decoding G20 Summit 2023: What a MATLAB WordCloud Reveals

    The G20 India Summit 2023 in New Delhi has been the talk of the town, especially with India playing the host and PM…

    1 条评论
  • How do Small Saving Schemes compare to Inflation?

    How do Small Saving Schemes compare to Inflation?

    On March 31, 2022, Govt of India announced the Interest Rate for various Small Saving Schemes like PPF, NSC, SCSS…

  • Analyze Tax Saving Investment under 80C with MATLAB

    Analyze Tax Saving Investment under 80C with MATLAB

    Hey. This is the time of the year when all Tax Payers who have not done anything during the entire year start thinking…

  • Bollywood Movie Mania in MATLAB

    Bollywood Movie Mania in MATLAB

    Hello LinkedIn Friends & Followers. It’s been a long period since my last post, and I am sorry for the delay.

  • Equation Instruction Rotation Simulation & Population

    Equation Instruction Rotation Simulation & Population

    Hi Reader! Give a big shout to yourself for subscribing to GG's Journal. I hope you have read my previous two articles:…

  • From #shorts to long work, Kanban is the way to go!

    From #shorts to long work, Kanban is the way to go!

    Hi Reader! Thanks for giving your valuable time to come and read this new article under GG's Journal. I am thrilled to…

  • How to make #shorts with MATLAB?

    How to make #shorts with MATLAB?

    Hi folks! Thank you for reading my article, and I hope you join my newsletter: GG's Journal. This is my second article…

  • Life is a Hackathon. How to solve it?

    Life is a Hackathon. How to solve it?

    Greetings Everyone! Wishing you a Happy New Year! Is it too late to wish now? Maybe, but doing it seems better than…

    2 条评论
  • 5 - Webinar Series @ MATLAB Helper

    5 - Webinar Series @ MATLAB Helper

    Hello friend. For the last few weeks, we have been conducting several webinars as well as the live interactive sessions…

    5 条评论
  • Arduino with MATLAB - Webinar #3

    Arduino with MATLAB - Webinar #3

    After Conducting two successful webinars on Arduino, MATLAB Helper in association with Airavath Foundation is…

社区洞察

其他会员也浏览了