繁簡切換您正在訪問的是FX168財經網,本網站所提供的內容及信息均遵守中華人民共和國香港特別行政區當地法律法規。

FX168财经网>人物频道>帖子

历年G20大会前一个交易日涨跌幅

作者/adasda 2019-06-25 08:44 0 来源: FX168财经网人物频道
import numpy as np
import pandas as pd
from jqdata import *
#G20大会前一交易日股票涨幅情况
df = get_price('000001.XSHG',start_date='2008-11-01',end_date='2019-01-31',frequency='daily')

date = ['2008-11-15','2009-04-02','2009-09-24','2010-06-26','2010-11-11','2011-11-03','2012-06-18',
        '2013-09-05','2014-11-15','2015-11-15','2016-09-04','2017-07-07','2018-11-30']
import datetime

def delta(j):
    return datetime.timedelta(days=j)
def strtodate(str1):
    return datetime.datetime.strptime(str1, '%Y-%m-%d').date()
def datetostr(date):
    return datetime.datetime.strftime(date,'%Y-%m-%d')

date_list =[str(i)[:10] for i in list(df.index)]
df1 = pd.DataFrame(columns=df.columns)
for i in date:
    
    j = 1
    
    while datetostr(strtodate(i)-delta(j)) not in date_list:
        
        j = j+1
#     delta = datetime.timedelta(days=j)

#     print(df.loc[datetostr(strtodate(i)-delta(j)),:])
    df1.loc[datetostr(strtodate(i)-delta(j))]=df.loc[datetostr(strtodate(i)-delta(j))]
df1
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
open close high low volume money
2008-11-14 1943.96 1986.44 1987.26 1921.84 1.304395e+10 8.784996e+10
2009-04-01 2380.98 2408.02 2422.63 2380.98 1.798576e+10 1.665421e+11
2009-09-23 2897.81 2842.72 2924.20 2825.86 1.076264e+10 1.167867e+11
2010-06-25 2556.54 2552.82 2572.83 2534.27 5.007885e+09 5.168800e+10
2010-11-10 3120.44 3115.36 3124.26 3093.88 1.850524e+10 2.489743e+11
2011-11-02 2437.87 2504.11 2505.12 2433.72 1.054682e+10 1.020828e+11
2012-06-15 2299.78 2306.85 2314.24 2283.40 6.868758e+09 6.785591e+10
2013-09-04 2121.68 2127.62 2133.00 2115.75 1.420004e+10 1.164574e+11
2014-11-14 2477.97 2478.82 2481.03 2457.05 2.206076e+10 1.919250e+11
2015-11-13 3600.76 3580.84 3632.56 3564.81 3.458709e+10 4.686687e+11
2016-09-02 3057.49 3067.35 3072.53 3050.49 1.504469e+10 1.705921e+11
2017-07-06 3203.86 3212.44 3215.95 3188.77 1.758093e+10 2.022096e+11
2018-11-29 2613.78 2567.44 2617.55 2567.44 1.571687e+10 1.294724e+11
df1['change'] = (df['close']-df['open'])/df['open']
df1
.dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; }
open close high low volume money change
2008-11-14 1943.96 1986.44 1987.26 1921.84 1.304395e+10 8.784996e+10 NaN
2009-04-01 2380.98 2408.02 2422.63 2380.98 1.798576e+10 1.665421e+11 NaN
2009-09-23 2897.81 2842.72 2924.20 2825.86 1.076264e+10 1.167867e+11 NaN
2010-06-25 2556.54 2552.82 2572.83 2534.27 5.007885e+09 5.168800e+10 NaN
2010-11-10 3120.44 3115.36 3124.26 3093.88 1.850524e+10 2.489743e+11 NaN
2011-11-02 2437.87 2504.11 2505.12 2433.72 1.054682e+10 1.020828e+11 NaN
2012-06-15 2299.78 2306.85 2314.24 2283.40 6.868758e+09 6.785591e+10 NaN
2013-09-04 2121.68 2127.62 2133.00 2115.75 1.420004e+10 1.164574e+11 NaN
2014-11-14 2477.97 2478.82 2481.03 2457.05 2.206076e+10 1.919250e+11 NaN
2015-11-13 3600.76 3580.84 3632.56 3564.81 3.458709e+10 4.686687e+11 NaN
2016-09-02 3057.49 3067.35 3072.53 3050.49 1.504469e+10 1.705921e+11 NaN
2017-07-06 3203.86 3212.44 3215.95 3188.77 1.758093e+10 2.022096e+11 NaN
2018-11-29 2613.78 2567.44 2617.55 2567.44 1.571687e+10 1.294724e+11 NaN
 
分享到:
举报财经168客户端下载

全部回复

0/140

投稿 您想发表你的观点和看法?

更多人气分析师

  • 张亦巧

    人气2168文章4145粉丝45

    暂无个人简介信息

  • 梁孟梵

    人气2160文章3177粉丝39

    qq:2294906466 了解群指导添加微信mfmacd

  • 指导老师

    人气1864文章4423粉丝52

    暂无个人简介信息

  • 李冉晴

    人气2296文章3821粉丝34

    李冉晴,专业现贷实盘分析师。

  • 刘钥钥1

    人气2016文章3119粉丝34

    专业从事现货黄金、现货白银模似实盘操作分析指导

  • 张迎妤

    人气1896文章3305粉丝34

    个人专注于行情技术分析,消息面解读剖析,给予您第一时间方向...

  • 金泰铬J

    人气2320文章3925粉丝51

    投资问答解咨询金泰铬V/信tgtg67即可获取每日的实时资讯、行情...

  • 金算盘

    人气2696文章7761粉丝125

    高级分析师,混过名校,厮杀于股市和期货、证券市场多年,专注...

  • 金帝财神

    人气4752文章8329粉丝119

    本文由资深分析师金帝财神微信:934295330,指导黄金,白银,...

FX168财经

FX168财经学院

FX168财经

FX168北美