Jump to content
Nigerian Investment Community
Sign in to follow this  
Michael Olafusi

Analyzing Nigeria Stock Market, Bond Yield, Exchange Rate and GDP Using R

Recommended Posts

Today I decided to do an interesting analysis using R. I compiled actual/live data from as far as 1998 on Nigerian All Share Index and 48 of the most valuable stocks. You can access the raw data here: https://drive.google.com/open?id=0B4XKk-Dstn-eVjRMQ0hQR0hvQ3c

 

Here is the R code text.

# Load in necessary libraries

require(ggplot2)

require(lubridate)

 

nse_asi

nse_asi$Date

 

# Uncomment the following lines to see the structure and preview of the raw data

#str(nse_asi)

#summary(nse_asi)

#head(nse_asi)

 

 

# This next lines of code are to generate the charts for each company in a separate window

# It is not compulsory, and might be worth commenting out if it makes your computer freeze

for (cmpy in unique(nse_asi$Company)){

  dev.new()

  print(ggplot(data=nse_asi[nse_asi$Company==cmpy,], aes(x=Date, y=Last_Price))+

  geom_line() +

  ggtitle(cmpy) +

  labs(x="Date",y="Price") )

}

 

# This is the most important chart code. Generates the charts in a neatly grouped way

ggplot(data=nse_asi, aes(x=Date, y=Last_Price, group=Ticker, color=Ticker))+

  geom_line() +

  facet_wrap(~Ticker,scales="free") +

  labs(x="Date",y="Price") +

  theme(legend.position="none")

 

 

And below are the results. Enjoy. Lots of screenshots. And make sure you notice the interesting insights: like how investors in Presco, Okomu Oil, United Capitals and Mobil would have been smiling to the bank despite the market depression and economic recession. I personally made some gain from Mobil. Also notice how not very long ago, 1 USD exchanged for 22 Naira.

 

nse%2Bperformance2.png

NSE ASI (pointed out with the red line) and 48 top stocks

bond%2Byeild.png

FGN 10 Year Bond Yield

 

GDP%2BGrowth.png

Nigeria Real GDP Growth from 1960 till Today

 

USD%2Bto%2BNaira.png

US Dollar to Nigerian Naira Exchange rate

 

7UP.png

 

Access%2BBank.png

 

AIICO.png

 

Berger%2BPaints.png

 

Cadbury.png

 

Chemical%2Band%2BAllied%2BProducts.png

 

Conoil.png

 

Dangote%2BCement.png

 

Dangote%2BFlour.png

 

Dangote%2BSugar.png

 

Diamond%2BBank.png

 

Ecobank.png

 

Eterna%2BOil.png

 

Fidelity%2BBank.png

 

First%2BBank.png

 

Forte%2BOil.png

 

GSK.png

 

GTBank.png

 

Guinness%2BNigeria.png

 

Honeywell%2BFlour.png

 

Lafarge.png

 

Leventis.png

 

Mansard.png

 

May%2Band%2BBaker.png

 

Mobil%2BNigeria.png

 

NAHCO.png

 

NASCON.png

 

Nestle.png

 

Nigerian%2BBreweries.png

 

NSEASI.png

 

Oando.png

 

Okomu%2BOil.png

 

Presco.png

 

PZ%2BCussons.png

 

Seplat.png

 

Skye%2BBank.png

 

Stanbic%2BIBTC.png

 

Sterling%2BBank.png

 

Total%2BNigeria.png

 

Transcorp.png

 

UAC.png

 

UBA.png

 

Unilever.png

 

Union%2BBank.png

 

United%2BCapital.png

 

Unity%2BBank.png

 

Wema%2BBank.png

 

Zenith%2BBank.png

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×