VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 7
声望: 1

历史行情好像下载到了DB文件, 现在想再弄成CSV, 到excel文件里先手工,有啥快捷的办法导出到csv吗?

description

Administrator
avatar
加入于:
帖子: 4539
声望: 324

用python的sqlite库,写个脚本30行左右吧

Member
avatar
加入于:
帖子: 7
声望: 1

用Python的交易员 wrote:

用python的sqlite库,写个脚本30行左右吧

多谢。我再去搜搜。

现在有新问题。

Member
avatar
加入于:
帖子: 10
声望: 0
#!/usr/bin/env python

import json
import pandas as pd
from pprint import pprint
from datetime import datetime

from vnpy.trader.database import database_manager
from vnpy.trader.setting import get_settings
from vnpy.trader.constant import Exchange

setting = get_settings()

ticks = database_manager.load_tick_data(
    'au2006',
    Exchange.SHFE,
    start = datetime(2000,1,1),
    end = datetime(3000,1,1)
)

for tick in ticks:
    tick.exchange = tick.exchange.value

ticks = [tick.__dict__  for tick in ticks]
df = pd.DataFrame(ticks)
df.to_csv('t.csv')
Member
avatar
加入于:
帖子: 7
声望: 1

非常感谢

张加林 wrote:

#!/usr/bin/env python

import json
import pandas as pd
from pprint import pprint
from datetime import datetime

from vnpy.trader.database import database_manager
from vnpy.trader.setting import get_settings
from vnpy.trader.constant import Exchange

setting = get_settings()

ticks = database_manager.load_tick_data(
    'au2006',
    Exchange.SHFE,
    start = datetime(2000,1,1),
    end = datetime(3000,1,1)
)

for tick in ticks:
    tick.exchange = tick.exchange.value

ticks = [tick.__dict__  for tick in ticks]
df = pd.DataFrame(ticks)
df.to_csv('t.csv')
© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】