目錄
- 項(xiàng)目地址:
- 1) 啟動(dòng)方法
- 2) web查看方法
- 3) 功能說明:
- 4) 展示:
- 代碼
項(xiàng)目地址:
https://github.com/guodongggg/fund
1) 啟動(dòng)方法
(非必須)修改new.csv,參照test.csv,首行為基金代碼,其次為每支基金在指定日期內(nèi)的操作,正值為買入金額,負(fù)值為贖回份額。具體項(xiàng)目參照x_alpha項(xiàng)目
修改code_list.json文件的prodect為你自己的基金代碼,修改count為每支基金的金額,執(zhí)行同級(jí)目錄下的update_code_list.py,自動(dòng)更新持倉(cāng)百分比
執(zhí)行python run.py
ps:初始化比較麻煩,我也暫時(shí)沒優(yōu)化,后面再說吧
2) web查看方法
打開瀏覽器,訪問本地地址:http://127.0.0.1:8090
在線示例:http://106.12.49.205
3) 功能說明:
- 大盤指數(shù)實(shí)時(shí)情況查看
- 單支基金實(shí)時(shí)、近一周、近一月、近三月的漲跌情況
- 總持倉(cāng)實(shí)際漲幅、預(yù)估漲幅
- 持倉(cāng)成本圖、餅狀圖、收益詳情圖(需修改new.csv)
- 線性回歸圖例
- 外鏈天天基金頁(yè)面
- 外鏈頭條大V號(hào)
- 外鏈微博大V號(hào)
- 外鏈比特幣
- 外鏈薅羊毛頁(yè)面
4) 展示:
![](http://img.jbzj.com/file_images/article/202106/202161171123865.png?202151171131)
![](http://img.jbzj.com/file_images/article/202106/202161171148474.png?202151171155)
代碼
涉及代碼過多,不便全部放出,請(qǐng)自行下載項(xiàng)目查看,放出部分代碼,僅供參考。
update_over_json.py 基金代碼列表
import average_growth
import json
import common
import choose_api
from pathlib import Path
def over_time(detail, board):
"""
判斷當(dāng)日持倉(cāng)的所有基金的合計(jì)漲幅是否超過滬深300
:param code_list: list 基金代碼列表
:return: json文件,格式如下,HS300漲幅、持倉(cāng)合計(jì)漲幅、持倉(cāng)漲幅是否超過滬深300
{
"2020-12-31": {
"HS300": "1.91",
"my_position": "1.35",
"over_take": false
},
"2021-01-04": {
"HS300": "1.08",
"my_position": "1.33",
"over_take": true
}
}
......
"""
# 獲取日期
try:
date = detail[0]['netWorthDate']
except:
date = detail[1]['netWorthDate']
hs300 = ''
for i in board:
if i['name'] == '滬深300':
hs300 = i['changePercent']
# 判斷文件是否存在,不存在則創(chuàng)建
json_file_name = 'file/bj.json'
file = Path(json_file_name)
file.touch(exist_ok=True)
# 此時(shí)更新的準(zhǔn)確凈值漲幅的平均值
avg = average_growth.average_growth(detail)['average_dayGrowth']
print('hs300:', hs300)
print('avg:', avg)
# 寫入文件
with open("file/bj.json", 'r+') as f:
try:
data = json.load(f)
f.seek(0, 0)
f.truncate()
except Exception as e:
print(e)
data = {}
finally:
print(f'獲取數(shù)據(jù): {data}')
data[date] = {
'HS300': hs300,
'my_position': str(avg),
'over_take': True if float(avg) > float(hs300) else False
}
print(f'更新數(shù)據(jù): {date}:{data[date]}')
f.write(json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')))
print(f'{json_file_name} 已更新!')
if __name__ == '__main__':
code_list = common.get_codelist('product')
data = choose_api.choose_api(code_list)
detail = data['detail']
board = data['board']
over_time(detail, board)
nasdaq.py sina財(cái)經(jīng)數(shù)據(jù)爬蟲
import requests
def nasdaq():
"""
爬取sina財(cái)經(jīng)nasdaq基礎(chǔ)數(shù)據(jù)
:return: 構(gòu)建的標(biāo)準(zhǔn)返回格式,只包含當(dāng)日的數(shù)據(jù),無歷史數(shù)據(jù)
"""
url = "http://hq.sinajs.cn/?rn=1609213839262list=gb_$ndx"
r = requests.get(url)
response = r.text
if r.status_code == 200:
data = response.split('=')[1].split(',')
nasdaq_data = {'name': data[0].strip('"'), 'code': '040046', 'price': data[1], 'priceChange': data[4], 'expectGrowth': data[2], 'dayGrowth': data[2], 'lastWeekGrowth': '-', 'lastMonthGrowth': '-', 'lastThreeMonthsGrowth': '-', 'date': ''}
return nasdaq_data
else:
print(f'nasdaq return error: \n {response}')
if __name__ == '__main__':
nasdaq_data = nasdaq()
for k, v in nasdaq_data.items():
print(f'{k}: {v}')
以上就是python flask開發(fā)的簡(jiǎn)單基金查詢工具的詳細(xì)內(nèi)容,更多關(guān)于python 基金查詢工具的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:- Python批量獲取基金數(shù)據(jù)的方法步驟
- python多線程+代理池爬取天天基金網(wǎng)、股票數(shù)據(jù)過程解析
- Python獲取基金網(wǎng)站網(wǎng)頁(yè)內(nèi)容、使用BeautifulSoup庫(kù)分析html操作示例
- Python多進(jìn)程方式抓取基金網(wǎng)站內(nèi)容的方法分析
- Python學(xué)習(xí)筆記之抓取某只基金歷史凈值數(shù)據(jù)實(shí)戰(zhàn)案例
- python程序?qū)崿F(xiàn)BTC(比特幣)挖礦的完整代碼
- Python實(shí)現(xiàn)類似比特幣的加密貨幣區(qū)塊鏈的創(chuàng)建與交易實(shí)例
- python做量化投資系列之比特幣初始配置