本帖最后由 keshun 于 2023-1-2 09:48 编辑
具体报酬:80元人民币。
支付方式:支付宝,微信
联系方式:QQ:1397538658
有效期限:2022年12月31日之前。
需求描述:
(1)系统环境(Win10,中文版,家庭版,python3.10)
(2)想要实现的功能写在代码中
(3)测试数据及期待结果- # coding=utf-8
- import pandas as pd
- import mplfinance as mpf
- import numpy as np
-
- my_style = mpf.make_mpf_style(y_on_right = True,marketcolors=mpf.make_marketcolors(up='r',down='g',edge='inherit',wick='inherit',volume='inherit'))
-
- fo = open('EOS.txt', encoding='utf-8') ; df = [] ; k=0 ; data = pd.DataFrame()
- for i in fo.readlines()[1:]:
- i = i.strip().split()
- df.append([i[1],float(i[2]),float(i[3]),float(i[4]),float(i[5]),float(i[6])])
- for j in ('Date','Open','High','Low','Close','Volume'):
- data[j] = [i[k] for i in df] ; k +=1
-
- low_list = data['Low'].rolling(9, min_periods=9).min()
- low_list.fillna(value=data['Low'].expanding().min(), inplace=True)
- high_list = data['High'].rolling(9, min_periods=9).max()
- high_list.fillna(value=data['High'].expanding().max(), inplace=True)
- rsv = (data['Close'] - low_list) / (high_list - low_list) * 100
- data['K'] = np.round(pd.Series.ewm(rsv, com=2).mean(), 2)
- data['D'] = np.round(pd.Series.ewm(data['K'], com=2).mean(), 2)
- data['J'] = np.round(3 * data['K'] - 2 * data['D'], 2)
-
- data['C1'] = np.round(data['Close'] / data['Open'] *100-100 ,2)
- arr=[]
- for i in range(len(data)):
- if (data['Volume'].values[i] / data['Volume'].mean()) > 2: arr.append(1)
- else: arr.append(0)
- data['V1'] = arr
-
- data['Date'] = pd.DatetimeIndex(data['Date'])
- data.set_index(['Date'], inplace=True)
-
- print(data)
- class InterCandle:
- def __init__(self, data):
- self.data = data ; self.start = len(data)-40 ; self.len = 40
- self.fig = mpf.figure(figsize=(12, 8))
- self.price_axe = self.fig.add_axes([0.06, 0.35, 0.88, 0.50]) #[X轴,Y轴,宽,高]
- self.volume_axe = self.fig.add_axes([0.06, 0.20, 0.88, 0.15], sharex=self.price_axe)
- self.kdj_axe = self.fig.add_axes([0.06, 0.05, 0.88, 0.15], sharex=self.price_axe)
- self.fig.canvas.mpl_connect('key_press_event', self.on_key_press)
-
- def plt_show(self): self.refresh_plot(self.data.iloc[self.start:self.start + self.len])
- def refresh_plot(self, plot_data):
- add_plot = []
- add_plot.append(mpf.make_addplot(plot_data[['C1']], ax=self.price_axe))
- add_plot.append(mpf.make_addplot(plot_data[['K','D','J']], ax=self.kdj_axe))
- mpf.plot(plot_data, ax=self.price_axe, addplot=add_plot, volume=self.volume_axe, type='candle', style=my_style, xrotation=90) ; mpf.show()
-
- def on_key_press(self, event):
- if event.key == 'enter': img_path = str(self.start) + '-' + str(self.start + self.len) ; plt.savefig(img_path + '.jpg') ; return
- elif (event.key == 'left' or event.key == 'down') and self.start > 1: self.start = self.start - 1
- elif (event.key == 'right' or event.key == 'up') and self.start + self.len < self.data.shape[0]: self.start = self.start + 1
- self.price_axe.clear() ; self.volume_axe.clear() ; self.kdj_axe.clear()
- self.refresh_plot(self.data.iloc[self.start:self.start + self.len])
-
- if __name__ == '__main__': InterCandle(data).plt_show()
-
-
-
- #此代码动态(键盘的方向键控制)K线图,目前有几点问题80元有偿求助:
- #1.图1蜡烛图与曲线数值相差太大,如此需要双Y轴;左边标蜡烛图刻度,右边标'C1'刻度;
- #2.图2图3刻度都要在右边;
- #3.X轴日期时间网格刻度只有5个,需要自定义为10个;
- #4.当'V1'的值是1,在图1中'C1'对应值位置标个红点;
- #5.图动态移动显示40个值,'C1'第40个值显示在图1曲线对应位置(也就是'C1'最后一个值显示在曲线上)。
-
-
- input("关闭窗口")
复制代码
- Date Open High Low Close Volume
- 0 2022-08-14T17:40 1.3727 1.3732 1.3689 1.3707 2620.0
- 1 2022-08-14T17:45 1.3706 1.3706 1.3693 1.3698 1523.0
- 2 2022-08-14T17:50 1.3701 1.3705 1.3683 1.3683 956.0
- 3 2022-08-14T17:55 1.3684 1.3686 1.3671 1.3686 680.0
- 4 2022-08-14T18:00 1.3689 1.3689 1.3656 1.3656 989.0
- 5 2022-08-14T18:05 1.3658 1.3668 1.3640 1.3649 558.0
- 6 2022-08-14T18:10 1.3648 1.3648 1.3603 1.3618 5764.0
- 7 2022-08-14T18:15 1.3621 1.3621 1.3582 1.3590 3321.0
- 8 2022-08-14T18:20 1.3591 1.3604 1.3571 1.3593 9799.0
- 9 2022-08-14T18:25 1.3595 1.3661 1.3595 1.3636 5021.0
- 10 2022-08-14T18:30 1.3637 1.3651 1.3629 1.3629 2088.0
- 11 2022-08-14T18:35 1.3629 1.3629 1.3605 1.3613 7983.0
- 12 2022-08-14T18:40 1.3608 1.3610 1.3588 1.3592 1328.0
- 13 2022-08-14T18:45 1.3594 1.3614 1.3591 1.3605 7216.0
- 14 2022-08-14T18:50 1.3610 1.3625 1.3593 1.3625 2543.0
- 15 2022-08-14T18:55 1.3625 1.3626 1.3588 1.3606 3277.0
- 16 2022-08-14T19:00 1.3601 1.3621 1.3601 1.3616 494.0
- 17 2022-08-14T19:05 1.3616 1.3617 1.3587 1.3589 1050.0
- 18 2022-08-14T19:10 1.3596 1.3620 1.3584 1.3613 2304.0
- 19 2022-08-14T19:15 1.3613 1.3618 1.3604 1.3604 1444.0
- 20 2022-08-14T19:20 1.3605 1.3617 1.3601 1.3616 875.0
- 21 2022-08-14T19:25 1.3618 1.3656 1.3614 1.3655 2358.0
- 22 2022-08-14T19:30 1.3648 1.3652 1.3642 1.3643 1578.0
- 23 2022-08-14T19:35 1.3643 1.3643 1.3556 1.3573 5246.0
- 24 2022-08-14T19:40 1.3579 1.3579 1.3502 1.3510 9492.0
- 25 2022-08-14T19:45 1.3511 1.3534 1.3505 1.3525 5515.0
- 26 2022-08-14T19:50 1.3526 1.3554 1.3526 1.3532 3227.0
- 27 2022-08-14T19:55 1.3530 1.3550 1.3522 1.3550 1279.0
- 28 2022-08-14T20:00 1.3550 1.3550 1.3517 1.3538 1872.0
- 29 2022-08-14T20:05 1.3546 1.3566 1.3529 1.3529 888.0
- 30 2022-08-14T20:10 1.3522 1.3527 1.3465 1.3470 6591.0
- 31 2022-08-14T20:15 1.3475 1.3548 1.3475 1.3512 5245.0
- 32 2022-08-14T20:20 1.3503 1.3509 1.3447 1.3502 8314.0
- 33 2022-08-14T20:25 1.3497 1.3513 1.3495 1.3497 667.0
- 34 2022-08-14T20:30 1.3496 1.3499 1.3462 1.3465 2957.0
- 35 2022-08-14T20:35 1.3464 1.3468 1.3432 1.3449 3396.0
- 36 2022-08-14T20:40 1.3449 1.3467 1.3441 1.3448 2239.0
- 37 2022-08-14T20:45 1.3446 1.3449 1.3409 1.3421 2612.0
- 38 2022-08-14T20:50 1.3412 1.3444 1.3410 1.3432 2487.0
- 39 2022-08-14T20:55 1.3432 1.3460 1.3432 1.3453 1558.0
- 40 2022-08-14T21:00 1.3451 1.3451 1.3421 1.3424 1581.0
- 41 2022-08-14T21:05 1.3424 1.3425 1.3368 1.3379 5666.0
- 42 2022-08-14T21:10 1.3382 1.3393 1.3368 1.3387 3267.0
- 43 2022-08-14T21:15 1.3382 1.3382 1.3237 1.3312 30675.0
- 44 2022-08-14T21:20 1.3316 1.3335 1.3300 1.3307 6188.0
- 45 2022-08-14T21:25 1.3304 1.3304 1.3231 1.3280 8975.0
- 46 2022-08-14T21:30 1.3280 1.3280 1.3172 1.3201 15803.0
- 47 2022-08-14T21:35 1.3193 1.3295 1.3184 1.3280 9690.0
- 48 2022-08-14T21:40 1.3271 1.3290 1.3250 1.3290 5052.0
- 49 2022-08-14T21:45 1.3292 1.3314 1.3277 1.3311 3632.0
- 50 2022-08-14T21:50 1.3313 1.3321 1.3269 1.3283 9128.0
- 51 2022-08-14T21:55 1.3281 1.3283 1.3234 1.3253 3961.0
- 52 2022-08-14T22:00 1.3253 1.3279 1.3238 1.3274 1437.0
- 53 2022-08-14T22:05 1.3274 1.3307 1.3256 1.3267 4869.0
- 54 2022-08-14T22:10 1.3271 1.3299 1.3271 1.3279 1463.0
- 55 2022-08-14T22:15 1.3280 1.3311 1.3280 1.3311 2780.0
- 56 2022-08-14T22:20 1.3312 1.3312 1.3274 1.3299 3572.0
- 57 2022-08-14T22:25 1.3292 1.3292 1.3260 1.3270 1537.0
- 58 2022-08-14T22:30 1.3269 1.3287 1.3232 1.3282 3214.0
- 59 2022-08-14T22:35 1.3288 1.3313 1.3281 1.3299 1792.0
- 60 2022-08-14T22:40 1.3300 1.3324 1.3298 1.3320 2575.0
复制代码
|