Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  



























Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 

















File:Stock-indices-2020crash+recovery.svg




Page contents not supported in other languages.  









File
Talk
 

















Read
View on Commons
 








Tools
   


Actions  



Read
View on Commons
 




General  



What links here
Upload file
Special pages
Printable version
Page information
Get shortened URL
Download QR code
 

















This is a file from the Wikimedia Commons

From Wikipedia, the free encyclopedia
 


File

File history

File usage

Global file usage

Metadata
File:Stock-indices-2020crash+recovery.svg
Size of this PNG preview of this SVG file: 504 × 378 pixels. Other resolutions: 320 × 240 pixels | 640 × 480 pixels | 1,024 × 768 pixels | 1,280 × 960 pixels | 2,560 × 1,920 pixels.

Original file(SVG file, nominally 504 × 378 pixels, file size: 177 KB)





Summary

Description
English: Stock index chart of 2020 with stock market crash
Date
Source Own work
Author Geek3
SVG development

InfoField

 
The SVG code is valid.
 
This plot was created with Matplotlib.
Source code

InfoField

Python code

#!/usr/bin/python3
# -*- coding: utf8 -*-

import csv
import datetime
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

class Stock:
    def __init__(self, name):
        self.data = self.get_csv(name)
        self.convert_types()
        self.filter_date(datetime.datetime(2020, 1, 1), datetime.datetime(2020, 12, 31))
    
    def get_csv(self, name):
        try:
            with open(name, 'r' ) as f:
                reader = csv.DictReader(f)
                return [line for line in reader]
        except FileNotFoundError as ex:
            print(ex)
            print('get data from', 'https://finance.yahoo.com/quote/DAX/history?p=DAX')
            exit()
    
    def convert_types(self):
        for il, l in enumerate(self.data):
            for k in l.keys():
                try:
                    if k == 'Date':
                        l[k] = datetime.datetime.strptime(l[k], '%Y-%m-%d')
                    else:
                        l[k] = float(l[k])
                except Exception:
                    del self.data[il]
    
    def filter_date(self, date, date2=None):
        self.data = [i for i in self.data if i['Date'] >= date]
        if date2 is not None:
            self.data = [i for i in self.data if i['Date'] <= date2]
    
    def get_dates(self):
        return [l['Date'] for l in self.data]
    
    def get_values(self):
        return np.array([float(l['Close']) for l in self.data])
    
    def get_values_norm(self):
        v = self.get_values()
        #vmean = np.mean([v for i, v in enumerate(v) if self.data[i]['Date'].month == 1])
        #return v / vmean
        # v / max(v)
        return v / max([v for i, v in enumerate(v) if self.data[i]['Date'].month < 4])


# data is found on finance.yahoo.com
data_spx = Stock('^GSPC.csv')
data_DJI = Stock('^DJI.csv')
data_stoxx50e = Stock('^STOXX50E.csv')
data_DAX = Stock('^GDAXI.csv')

plt.figure(figsize=[5.6, 4.2])
ax = plt.gca()
ax.set_prop_cycle(color=['#0072bd', '#d95319', '#edb120', '#7e2f8e'])

plt.plot(data_spx.get_dates(), 100*data_spx.get_values_norm(), 'o-', ms=3, label='S&P 500')
plt.plot(data_DJI.get_dates(), 100*data_DJI.get_values_norm(), 'o-', ms=3, label='Dow Jones')
plt.plot(data_stoxx50e.get_dates(), 100*data_stoxx50e.get_values_norm(), 'o-', ms=3, label='EURO STOXX 50')
plt.plot(data_DAX.get_dates(), 100*data_DAX.get_values_norm(), 'o-', ms=3, label='DAX')

plt.xlim(datetime.datetime.strptime('2019-12-24', '%Y-%m-%d'),
         datetime.datetime.strptime('2021-01-08', '%Y-%m-%d'))
ax.tick_params(axis='x', which='minor', pad=6)
ax.xaxis.set_major_locator(mpl.dates.MonthLocator())
ax.xaxis.set_major_formatter(mpl.ticker.NullFormatter())
ax.xaxis.set_minor_formatter(mpl.dates.DateFormatter("%m"))
ax.xaxis.set_minor_locator(mpl.dates.MonthLocator(bymonthday=16))
ax.yaxis.set_major_formatter(mpl.ticker.FormatStrFormatter('%.0f%%'))

for tick in ax.xaxis.get_minor_ticks():
    tick.tick1line.set_markersize(0)
    tick.tick2line.set_markersize(0)
    tick.label1.set_horizontalalignment('center')

plt.xlabel('date (month 2020)')
plt.ylabel('value relative to 2020 pre-crash maximum')
plt.grid(True)
plt.legend(loc='lower right', framealpha=1, edgecolor='k', borderpad=0.7, borderaxespad=0.6)
plt.tight_layout()
plt.savefig('stock-indices-2020crash+recovery.svg')

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
  • Under the following conditions:
    • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
    • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    some value

    1 January 2021

    image/svg+xml

    File history



    Click on a date/time to view the file as it appeared at that time.
    Date/TimeThumbnailDimensionsUserComment
    current15:15, 1 January 2021Thumbnail for version as of 15:15, 1 January 2021504 × 378 (177 KB)Geek3Uploaded own work with UploadWizard



    The following pages on the English Wikipedia use this file (pages on other projects are not listed):

    COVID-19 pandemic

    Profit (accounting)


    Global file usage


    The following other wikis use this file:

    Usage on ar.wikipedia.org

    انهيار أسواق الأسهم العالمية 2020


    Usage on en.wikiversity.org

    WikiJournal Preprints/COVID-19 pandemic


    Usage on ms.wikipedia.org

    Pandemik COVID-19


    Usage on pt.wikipedia.org

    Pandemia de COVID-19


    Usage on ru.wikipedia.org

    Обвал фондового рынка (2020)


    Usage on uk.wikipedia.org

    Глобальна фінансова криза 2020 року


    Usage on www.wikidata.org

    Q87629158



    Metadata

    If the file has been modified from its original state, some details may not fully reflect the modified file.


    Retrieved from "https://en.wikipedia.org/wiki/File:Stock-indices-2020crash%2Brecovery.svg"







    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki