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
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
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 |
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
移动端课程