Skip to content

Instantly share code, notes, and snippets.

@t1nak
Created May 19, 2017 17:15
Show Gist options
  • Save t1nak/9e31b766c1f607c758a2e93d160e832c to your computer and use it in GitHub Desktop.
Save t1nak/9e31b766c1f607c758a2e93d160e832c to your computer and use it in GitHub Desktop.
2017-05-19_KoziolTina_WeeklyReport
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"\n",
"\n",
"\n",
"<h1><center>Tina Koziol</center></h1>\n",
"<center>PhD Candidate, UCT </center>\n",
"\n",
"\n",
"------------------------------------------------------------------------\n",
"\n",
"\n",
"\n",
"&nbsp;\n",
"\n",
"\n",
"\n",
"\n",
"Coding \n",
"================\n",
"\n",
"\n",
"- Writing a test for my vulnerable banks code. The __str__ method in my agent class did not display what my agent config xml looked like becuase of the parent class. So I modified the ```__str__``` method in my example folder. I also created symlink folders within the tests folder to not have redundant files. \n",
"\n",
"&nbsp;"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/Tina/git_repos/BlackRhino/examples/firesales_SA/tests\n"
]
}
],
"source": [
"cd /Users/Tina/git_repos/BlackRhino/examples/firesales_SA/tests/"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This tests methods for agent class\n",
"XxxxxxXXxxxxXXXXxx\n",
"Initiating agent object..\n",
"\n",
"XxxxxxXXxxxxXXXXxx\n",
" <agent identifier=''>\n",
" <parameter type='state_variables' name='losses_from_system_deleveraging' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='shock_for_agent' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='total_assets' value='0'></parameter>\n",
" <parameter type='state_variables' name='direct_losses' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='total_asset_sales' value='0.0'></parameter>\n",
"</agent>\n",
"\n",
"Reading in parameters by calling method..\n",
"\n",
"XxxxxxXXxxxxXXXXxx\n",
" <agent identifier='CAPITEC'>\n",
" <parameter type='parameters' name=debt' value='48913724000.0'></parameter>\n",
" <parameter type='parameters' name=equity' value='13056412000.0'></parameter>\n",
" <parameter type='state_variables' name='losses_from_system_deleveraging' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='direct_losses' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_22' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_23' value='0.0292484274885'></parameter>\n",
" <parameter type='state_variables' name='m_20' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_21' value='0.0615316071201'></parameter>\n",
" <parameter type='state_variables' name='leverage' value='3.74633735516'></parameter>\n",
" <parameter type='state_variables' name='m_9' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_8' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_3' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_2' value='0.263017629379'></parameter>\n",
" <parameter type='state_variables' name='m_1' value='0.0579756038937'></parameter>\n",
" <parameter type='state_variables' name='m_7' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_6' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_5' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_4' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_19' value='0.0039719616554'></parameter>\n",
" <parameter type='state_variables' name='m_18' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_17' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_16' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_15' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_14' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='m_13' value='2.43665755389e-06'></parameter>\n",
" <parameter type='state_variables' name='m_12' value='0.575324856078'></parameter>\n",
" <parameter type='state_variables' name='m_11' value='0.00892747772778'></parameter>\n",
" <parameter type='state_variables' name='m_10' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='shock_for_agent' value='0.0'></parameter>\n",
" <parameter type='state_variables' name='total_assets' value='0'></parameter>\n",
" <parameter type='state_variables' name='total_asset_sales' value='0.0'></parameter>\n",
"</agent>\n",
"\n"
]
}
],
"source": [
"# %load /Users/Tina/git_repos/BlackRhino/examples/firesales_SA/tests/abm_firesales_tests.py\n",
"# -------------------------------------------------------------------------\n",
"#\n",
"# MAIN\n",
"#\n",
"# -------------------------------------------------------------------------\n",
"if __name__ == '__main__':\n",
"\n",
" import pdb # python debugger, for debugging purposes only\n",
"\n",
" import sys\n",
"\n",
"\n",
" from inspect import getsourcefile\n",
" from os import path\n",
" sys.path.append( path.dirname( path.dirname( path.abspath(getsourcefile(lambda:0)) ) ) )\n",
" \n",
" from src.environment import Environment\n",
" from TestAgent import TestAgent\n",
"\n",
"\n",
" test_agent_object = TestAgent() \n",
" \n",
" test_agent_object.print_info(\"This tests methods for agent class\")\n",
"\n",
" test_agent_object.get_parameters_from_file([\"configs/environment/\", \"test_firesales\"])\n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/Tina/git_repos/jupyter_notebooks/weeklyreports/code/replace_xmls/agent1.xml\n",
"XXXX OLD:\n",
"<agent identifier=\"SBSA\">\n",
"\n",
"<parameter type=\"state_variables\" name=\"equity\" value=\"86200249000.0\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"leverage\" value=\"13.0780116888061\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"debt\" value=\"1127327864000.0\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_1\" value=\"0.0245212259042243\" label=\"Cash and gold reserves \"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_2\" value=\"0.0107197211672673\" label=\"SA Interbank deposits, loans and advances \"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_3\" value=\"0.00405856934605684\" label=\"Rand Deposits with and loans to foreign banks\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_4\" value=\"0.0359414516505725\" label=\"Loans granted under repo agreement\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_5\" value=\"0.129182760844701\" label=\"Foreign currency loans and advances d 134),\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_6\" value=\"0.0170625845237423\" label=\"Redeemable preference shares\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_7\" value=\"0.0296141684852751\" label=\"corporate instalment credit \"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_8\" value=\"0.0252157207337808\" label=\"household instalment credit \"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_9\" value=\"0.0690936667241429\" label=\"corporate mortgage\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_10\" value=\"0.217515842585181\" label=\"household mortgage\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_11\" value=\"0.114607784121438\" label=\"Unsecured lending corporate\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_12\" value=\"0.0247813962262941\" label=\"Unsecured lending households\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_13\" value=\"0.0589651490010434\" label=\"Other credit (credit card + leasing + Overdarft + factoring debt)\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_14\" value=\"0.0412585423144622\" label=\"Central and provincial government bonds\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_15\" value=\"0.00466172471770335\" label=\"Other public-sector bonds\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_16\" value=\"0.0123382885320927\" label=\"Private sector bonds\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_17\" value=\"0.000201706905161743\" label=\"Equity holdings in subsidiaries and joint ventures\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_18\" value=\"0.0129940574355693\" label=\"Listed and unlisted equities\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_19\" value=\"0.0839139051737815\" label=\"Securitisation/ asset-backed securities\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_20\" value=\"0.00454473608062181\" label=\"Derivative instruments\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_21\" value=\"0.0408429870466462\" label=\"Treasury bills, SA Reserve Bank bills, Land Bank bills \"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_22\" value=\"0.00209378503289771\" label=\"Other investments\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"m_23\" value=\"0.0358702254473441\" label=\"Non financial assets\"></parameter>\n",
"\n",
"</agent>\n",
"\n",
"XXXX NEW\n",
"<agent identifier=\"SBSA\">\n",
"\n",
"<parameter type=\"parameters\" name=\"equity\" value=\"86200249000.0\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"leverage\" value=\"13.0780116888061\"></parameter>\n",
"\n",
" <parameter type=\"parameters\" name=\"debt\" value=\"1127327864000.0\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_1\" value=\"0.0245212259042243\" label=\"Cash and gold reserves \"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_2\" value=\"0.0107197211672673\" label=\"SA Interbank deposits, loans and advances \"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_3\" value=\"0.00405856934605684\" label=\"Rand Deposits with and loans to foreign banks\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_4\" value=\"0.0359414516505725\" label=\"Loans granted under repo agreement\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_5\" value=\"0.129182760844701\" label=\"Foreign currency loans and advances d 134),\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_6\" value=\"0.0170625845237423\" label=\"Redeemable preference shares\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_7\" value=\"0.0296141684852751\" label=\"corporate instalment credit \"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_8\" value=\"0.0252157207337808\" label=\"household instalment credit \"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_9\" value=\"0.0690936667241429\" label=\"corporate mortgage\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_10\" value=\"0.217515842585181\" label=\"household mortgage\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_11\" value=\"0.114607784121438\" label=\"Unsecured lending corporate\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_12\" value=\"0.0247813962262941\" label=\"Unsecured lending households\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_13\" value=\"0.0589651490010434\" label=\"Other credit (credit card + leasing + Overdarft + factoring debt)\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_14\" value=\"0.0412585423144622\" label=\"Central and provincial government bonds\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_15\" value=\"0.00466172471770335\" label=\"Other public-sector bonds\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_16\" value=\"0.0123382885320927\" label=\"Private sector bonds\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_17\" value=\"0.000201706905161743\" label=\"Equity holdings in subsidiaries and joint ventures\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_18\" value=\"0.0129940574355693\" label=\"Listed and unlisted equities\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_19\" value=\"0.0839139051737815\" label=\"Securitisation/ asset-backed securities\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_20\" value=\"0.00454473608062181\" label=\"Derivative instruments\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_21\" value=\"0.0408429870466462\" label=\"Treasury bills, SA Reserve Bank bills, Land Bank bills \"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_22\" value=\"0.00209378503289771\" label=\"Other investments\"></parameter>\n",
"\n",
" <parameter type=\"state_variables\" name=\"m_23\" value=\"0.0358702254473441\" label=\"Non financial assets\"></parameter>\n",
"\n",
"</agent>\n",
"\n"
]
}
],
"source": [
"run /Users/Tina/git_repos/jupyter_notebooks/weeklyreports/code/replace_xmls/replace_xml.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- This script uses the ``` TestAgent``` class to test the ```get_parameters_from_file``` function within my agent class. \n",
"- Within ``` TestAgent```, I first initiate the environment (because the agent directory is stored in the environment object), use ``` listings = os.listdir(agent_directory) ``` to loop over the agent xmls in the directory.\n",
"- Then I instantiate an agent object and ``` print agent```, so you can see the agent doesn't have any parameters yet. \n",
"- Afterwards I call ```agent.get_parameters_from_file(agent_filename, environment)``` and ``` print agent``` to see if the function worked\n",
"- State variables ```total_asset_sales``` is still 0 because the update algorythm was not called\n",
"\n",
"\n",
"\n",
"As you can see the state_variable - parameters type are mixed up so I wrote a small script that loops over agent xmls and replaces the strings. This looks like this. \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I know this doesn't seem much, but I was quite happy I managed to do this in python. Now I can loop over all agent configs and change the xml files, instead of going through them individually. Even though I am happy about the coding this week, the paper itself didn't really move forward. I need to push more the next weeks."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Seminar\n",
"\n",
"-I prepared some slides for the ACQUFFR seminar and was quite nervous, but it went ok. My public speaking skills are a bit rusty, I suppose I need more practice/exposure. I gave them a general talk about central banks and monetary policy because they don't have that in their course (I also mentioned the Lucca%Moench paper). Alex said he took away some interesting things, as they \"normally don't consider the bigger picture\", but only asset pricing. \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Other stuff\n",
"\n",
"- I looked into the Econometrics content. I really need to fresh up on my R (this week installed it and covered some basics, like reading into files, installing packages and working with the notebooks), so I anticipate this will take up quite some time next week. I talked to Nolwazi and we want to do a 50:50 work split between the tutorials.\n",
"\n",
"- I talked to Alexia and we agreed to find a feasable solution for the outreach program. The class is rather struggling this year, so I don't want to make it more difficult for them (apparently 4 students already deregistered). We spoke to some of the people who did it last year and apparently Ndima Yam was providing most of the content. The students did not spend more than 2h preparing, so we should be able to find something 'easy' like this again. My meeting with Pheliswa was postponed because she is knocked out by the flue. But she was very positive about a cooperation this year again. "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment