<jupyter_start><jupyter_text>Sovereign Domestic Debt DefaultSovereign debt is a central government's debt. It is debt issued by the national government in a foreign currency in order to finance the issuing country's growth and development.Sovereign debt is usually created by borrowing government bonds and bills and issuing securities. Countries that are less creditworthy compared to others directly borrow from world organizations like The World Bank and other international financial institutions. An unfavorable change in exchange rates and an overly optimistic valuation of the payback from the projects financed by the debt can make it difficult for countries to repay sovereign debt.The most important risk in sovereign debt is the risk of default by the issuing country. For this reason, countries with stable economies and political systems are considered to be less of a default risk in comparison to countries with a history of instabilitySovereign Domestic Debt is a debt owed to lenders who are within the country.<jupyter_code>fig,ax = plt.subplots(figsize = (20,10))
sns.countplot(money['country'],hue= money['domestic_debt_in_default'],ax=ax)
plt.xlabel('countries')
plt.ylabel('counts')
plt.xticks(rotation=45)
sovereign = money[['year','country','domestic_debt_in_default','exch_usd','banking_crisis']]
sovereign = sovereign[(sovereign['country']=='Angola') | (sovereign['country']=='Zimbabwe') |(sovereign['country']=='Egypt')]
plt.figure(figsize=(20,15))
count = 1
for country in sovereign.country.unique():
    plt.subplot(len(sovereign.country.unique()),1,count)
    subset = sovereign[(sovereign['country'] == country)]
    sns.lineplot(subset['year'],subset['domestic_debt_in_default'],ci=None)
    plt.scatter(subset['year'],subset["banking_crisis"], color='coral', label='Banking Crisis')
    plt.subplots_adjust(hspace=0.6)
    plt.xlabel('Years')
    plt.ylabel('Sovereign Domestic Debt Defaults/Banking Crisis')
    plt.title(country)
    count+=1<jupyter_output><empty_output><jupyter_text>Sovereign External Debt DefaultExternal debt is the portion of a country's debt that was borrowed from foreign lenders, including commercial banks, governments, or international financial institutions. These loans, including interest, must usually be paid in the currency in which the loan was made. To earn the needed currency, the borrowing country may sell and export goods to the lender's country.A debt crisis can occur if a country with a weak economy is not able to repay the external debt due to the inability to produce and sell goods and make a profitable return.If a nation is unable or refuses to repay its external debt, it is said to be in a sovereign default. This can lead to the lenders withholding future releases of assets that might be needed by the borrowing nation. Such instances can have a rolling effect, wherein the borrower’s currency collapses and that nation’s overall economic growth is stalled.<jupyter_code>fig,ax = plt.subplots(figsize = (20,10))
sns.countplot(money['country'],hue= money['sovereign_external_debt_default'],ax=ax)
plt.xlabel('countries')
plt.ylabel('counts')
plt.xticks(rotation=50)
sovereign_ext = money[['year','country', 'sovereign_external_debt_default', 'banking_crisis']]
sovereign_ext = sovereign_ext[(sovereign_ext['country'] == 'Central African Republic') | (sovereign_ext['country'] == 'Ivory Coast') | (sovereign_ext['country']=='Zimbabwe') | (sovereign_ext['country'] == 'Egypt')]
plt.figure(figsize=(20,15))
count = 1

for country in sovereign_ext.country.unique():
    plt.subplot(len(sovereign_ext.country.unique()),1,count)
    subset = sovereign_ext[(sovereign_ext['country'] == country)]
    sns.lineplot(subset['year'],subset['sovereign_external_debt_default'],ci=None)
    plt.scatter(subset['year'],subset["banking_crisis"], color='coral', label='Banking Crisis')
    plt.subplots_adjust(hspace=0.6)
    plt.xlabel('Years')
    plt.ylabel('Sovereign Ext Debt Defaults/Banking Crisis')
    plt.title(country)
    count+=1
# currency crisis
fig,ax = plt.subplots(figsize=(20,10))
sns.countplot(money['country'],hue=money['currency_crises'],ax = ax)
plt.xlabel('countries')
plt.ylabel('counts')
plt.xticks(rotation = 45)<jupyter_output><empty_output><jupyter_text>Inflation CrisisAs prices rise, a single unit of currency loses value as it buys fewer goods and services. This loss of purchasing power impacts the general cost of living for the common public which ultimately leads to a deceleration in economic growth.Inflation is a quantitative measure of the rate at which the average price level of a basket of selected goods and services in an economy increases over a period of time. It is the constant rise in the general level of prices where a unit of currency buys less than it did in prior periods.Let's look at the countries that were accounted for an inflation crisis<jupyter_code>fig,ax = plt.subplots(figsize=(20,10))
sns.countplot(money['country'],hue=money['inflation_crises'],ax=ax)
plt.xlabel('countries')
plt.ylabel('counts')<jupyter_output><empty_output><jupyter_text>Most commonly used inflation indexes are the Consumer Price Index (CPI). Let's look at the Annual CPI for the three countries to see if we can derive any insights.<jupyter_code>infla = money[['year','country', 'inflation_crises', 'inflation_annual_cpi', 'banking_crisis']]
infla = infla[(infla['country'] == 'Angola') | (infla['country'] == 'Zambia') | (infla['country']=='Zimbabwe') | 
             (infla['country']=='Egypt')]
infla = infla.replace(to_replace=2, value=1, regex=False)

plt.figure(figsize=(20,15))
count = 1

for country in infla.country.unique():
    plt.subplot(len(infla.country.unique()),1,count)
    subset = infla[(infla['country'] == country)]
    sns.lineplot(subset['year'],subset['inflation_crises'],ci=None)
    plt.scatter(subset['year'],subset["banking_crisis"], color='coral', label='Banking Crisis')
    plt.subplots_adjust(hspace=0.6)
    plt.xlabel('Years')
    plt.ylabel('Inflation Crisis/Banking Crisis')
    plt.title(country)
    count+=1

#A look at currency rates
sns.set_style('whitegrid')
plt.figure(figsize=(8,5))
sns.lineplot(x='year',y='exch_usd',hue='country',data=money,palette = 'colorblind')
plt.xlabel('Year')
plt.ylabel('Exchange Rate')
display()<jupyter_output><empty_output><jupyter_text>Observations:Some countries have relatively lower exchange rate than other countries. Countries like South Africa, Zambia, Egypt and Morocco has relatively lower exchange rate (It is hard to interpret with the above graph, Let's break it down the exchange rate for each country in the next graph)The exchange rate is almost zero for all the countries before 1940. This might be because the value is not recorded or a new currency had been adopted by the countries. (Further analysis required)There are tremendous spikes in the exchange rate Angola and Zimbabwe. This might indicate an economic breakdown.  Let's break it down further<jupyter_code>sns.set_style('whitegrid')
fig, axes = plt.subplots(ncols = 4,nrows=4,figsize=(18,12),dpi=60)
axes = axes.flatten()
for i,ax in zip(money['country'].unique(),axes):
    sns.lineplot(x='year',y='exch_usd',hue='independence',data=money[money['country'] == i],ax=ax)
    ax.set_xlabel('year')
    ax.set_ylabel('exchange rate')
    ax.set_title('{}'.format(i))
    ax.get_legend().remove()
handles, labels = ax.get_legend_handles_labels()
fig.legend(handles, labels, loc=1)
fig.subplots_adjust(top=0.95)
for i in range(13,16):
  fig.delaxes(axes[i])
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>Observations:All the countries had a good exchange rate before independence. This is because, most of the countries would have opted for new currency system after independece. For example, Tunisian dinar was introduced in 1960 and the Algerian dinar was introduced in 1964 (Ref:Wikipedia).Egypt has been an independent country since 1850s. However it's exchange rate has started increasing from 1970s. Let's consider Egypt as a special case in respective to independence.The exchange rate had gone up after the independence for almost all the countries expect Tunisia. Except Tunisia and Ivory coast, the exchange rate for all the countries have been increasing from the independence with some fluctuations.There are some sudden spikes in the exchange rate. Angolan Kwanza - In 1999, a second currency was introduced in Angola called the kwanza and it suffered early on from high inflation (Wikipedia). Tunisian dinar was introduced in 1960, hence a spike.<jupyter_code>#Number of inflation crisis by Country
money.groupby('country').agg({'inflation_crises':'sum'}).sort_values('inflation_crises',ascending=False)
money.groupby('country').agg({'currency_crises':'sum'}).sort_values('currency_crises',ascending=False)
money.groupby('country').agg({'banking_crisis':'count'}).sort_values('banking_crisis',ascending=False)
money['banking_crisis'].value_counts('Egypt')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10879500613086612, 'fraction_numerical': 0.01081261843718649, 'mean_word_length': 6.501672240802676, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '510383', 'license': 'MIT', 'n_tokens_mistral': 2808, 'n_tokens_neox': 2546, 'n_words': 872, 'path': 'financial crisis.ipynb', 'repo_name': 'fadyezz/Africa_financial_crisis', 'size': '8971'}