workspace.ipynb 2.17 KB
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import FinanceDataReader as fdr\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "def basicinform(input):\n",
    "    stocks = pd.read_csv('stockcodename.csv',index_col=0)\n",
    "    symbol = ''\n",
    "    for i in enumerate(stocks.Name) :\n",
    "        if i[1] == input:\n",
    "            symbol = (stocks.iloc[i[0]].Symbol)\n",
    "            break\n",
    "    df = fdr.DataReader(symbol)\n",
    "    ror_df = df.Close.pct_change()\n",
    "    volume = df.Volume.iloc[-1]\n",
    "    price = df.Close.iloc[-1]\n",
    "    ror = ror_df[-1]\n",
    "    #print(\"현재가: \", price)\n",
    "    #print(\"거래량: \", volume)\n",
    "    #print(\"전일 대비 수익률:\", ror)\n",
    "    #display(df)\n",
    "    value = {\"현재가\": price ,\n",
    "              \"거래랑\": volume ,\n",
    "              \"전일 대비 수익률:\" : ror\n",
    "            }\n",
    "    return value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'현재가': 79700, '거래랑': 13358073, '전일 대비 수익률:': -0.004993757802746579}\n"
     ]
    }
   ],
   "source": [
    "print(basicinform('삼성전자'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "stocks = fdr.StockListing('KOSPI') # 코스피\n",
    "stocks.to_csv(\"stockcodename.csv\",mode='w', encoding='utf-8-sig')"
   ]
  }
 ],
 "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.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}