{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('SPY', 0.3) ('GABBA', 0.2) ('GLD', 0.3) ('7ABBA', 0.2)]\n",
      "[('7ABBA', 0.2), ('GABBA', 0.2), ('GLD', 0.3), ('SPY', 0.3)]\n",
      "['AAPL', 'AGP', 'CORP', 'GLD', 'GOOG', 'GSPC.INDX', 'IJR', 'LQD', 'RDFTX', 'SPLV', 'SPY', 'THPBX', 'VTSMX', 'VTTHX', 'XOM']\n",
      "Portfolio contains bad symbols :  ['7ABBA', 'GABBA']\n"
     ]
    }
   ],
   "source": [
    "# Pftk Imports\n",
    "import pftk.pftkutil.qsdateutil as du\n",
    "import pftk.pftkutil.tsutil as tsu\n",
    "import pftk.pftkutil.data_access as da\n",
    "\n",
    "# Third Party Imports\n",
    "import datetime as dt\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "# Reading the portfolio\n",
    "na_portfolio = np.loadtxt('tutorial3_portfolio.csv', dtype='U5,f4', delimiter=',', comments=\"#\", skiprows=1)\n",
    "print(na_portfolio)\n",
    "\n",
    "# Sorting the portfolio by symbol name\n",
    "na_portfolio = sorted(na_portfolio, key=lambda x: x[0])\n",
    "print(na_portfolio)\n",
    "\n",
    "# Create two list for symbol names and allocation\n",
    "ls_port_syms = []\n",
    "lf_port_alloc = []\n",
    "for port in na_portfolio:\n",
    "    ls_port_syms.append(port[0])\n",
    "    lf_port_alloc.append(port[1])\n",
    "\n",
    "# Creating an object of the dataaccess class with Yahoo as the source.\n",
    "c_dataobj = da.DataAccess('EODHistoricalData')\n",
    "ls_all_syms = c_dataobj.get_all_symbols()\n",
    "print(ls_all_syms)\n",
    "\n",
    "# Bad symbols are symbols present in portfolio but not in all syms\n",
    "ls_bad_syms = list(set(ls_port_syms) - set(ls_all_syms))\n",
    "\n",
    "if len(ls_bad_syms) != 0:\n",
    "    print(\"Portfolio contains bad symbols : \", ls_bad_syms)\n",
    "\n",
    "for s_sym in ls_bad_syms:\n",
    "    i_index = ls_port_syms.index(s_sym)\n",
    "    ls_port_syms.pop(i_index)\n",
    "    lf_port_alloc.pop(i_index)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('7ABBA', 0.2), ('GABBA', 0.2), ('GLD', 0.3), ('SPY', 0.3)]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "na_portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
