workspace.ipynb
2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
"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
}