当前位置: 首页 > news >正文

怎样自己制作网站做情感顾问清博舆情系统

怎样自己制作网站做情感顾问,清博舆情系统,广东华星建设集团网站,免费新闻网站建设引言 在股票交易的世界中,技术分析是投资者们用来预测市场动向的重要工具。布林带(Bollinger Bands)作为一种动态波动范围指标,因其直观性和实用性而广受欢迎。本文将通过Python代码,展示如何使用布林带结合K线图来分…

引言

在股票交易的世界中,技术分析是投资者们用来预测市场动向的重要工具。布林带(Bollinger Bands)作为一种动态波动范围指标,因其直观性和实用性而广受欢迎。本文将通过Python代码,展示如何使用布林带结合K线图来分析股票价格走势,并寻找可能的交易信号。

布林带指标简介

布林带由三部分组成:中轨(移动平均线),上轨(中轨加上两倍标准差),以及下轨(中轨减去两倍标准差)。它们可以帮助交易者识别股票的超买或超卖状态,从而发现潜在的买卖机会。

Python代码实现

以下是使用Python进行布林带计算和K线图绘制的完整示例代码:

1. 导入必要的库

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

2. 定义布林带计算函数

def bollinger_bands(close_prices, window=20, num_std=2):rolling_mean = close_prices.rolling(window=window).mean()rolling_std = close_prices.rolling(window=window).std()upper_band = rolling_mean + (rolling_std * num_std)lower_band = rolling_mean - (rolling_std * num_std)return upper_band, lower_band

3. 生成模拟数据示例数据

np.random.seed(0)
dates = pd.date_range(start='2022-01-01', end='2024-01-01', freq='D')
prices = np.random.normal(loc=100, scale=2, size=len(dates)) + np.sin(np.arange(len(dates)) * 0.05) * 10
opens = prices * np.random.uniform(0.98, 1.02, len(prices))
closes = prices * np.random.uniform(0.98, 1.02, len(prices))
df = pd.DataFrame({'Open': opens, 'Close': closes}).set_index(dates)

4. 计算涨跌幅和布林带

df['Color'] = np.where(df['Close'] > df['Open'], 'red', 'cyan')
upper_band, lower_band = bollinger_bands(df['Close'])

5. 标记买卖信号

buy_signals = df[df['Close'] < lower_band]
sell_signals = df[df['Close'] > upper_band]

6. 计算累计盈利

profit = 0
profits = []
for i in range(1, len(df)):if df['Close'][i] > df['Close'][i-1]:profit += df['Close'][i] - df['Close'][i-1]else:profit -= df['Close'][i] - df['Close'][i-1]profits.append(profit)
df['Cumulative_Profit'] = profits

7. 绘制K线图、布林带和累计盈利图

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 10), sharex=True)

8.绘制K线图

for i in range(len(df)):color = df['Color'][i]ax1.plot(df.index[i:i+1], df['Open'][i:i+1], color=color, linewidth=1)ax1.plot(df.index[i:i+1], df['Close'][i:i+1], color=color, linewidth=1)

9.绘制布林带

ax1.plot(upper_band, color='red', linestyle='--', label='Upper Band')
ax1.plot(lower_band, color='green', linestyle='--', label='Lower Band')

9. 标记买卖信号

ax1.scatter(buy_signals.index, buy_signals['Close'], marker='^', color='blue', label='Buy Signal')
ax1.scatter(sell_signals.index, sell_signals['Close'], marker='v', color='red', label='Sell Signal')

9. 绘制累计盈利图

ax2.plot(df.index[1:], df['Cumulative_Profit'], color='blue', label='Cumulative Profit')

9.设置图表标题和标签

ax1.set_title('Stock Price with Bollinger Bands and Signals')
ax1.set_ylabel('Price')
ax2.set_title('Cumulative Profit Over Time')
ax2.set_ylabel('Profit')

9. 显示图例

ax1.legend()
ax2.legend()

9.显示图表

plt.tight_layout()
plt.show()

完整代码

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt# 计算布林带指标
def bollinger_bands(close_prices, window=20, num_std=2):rolling_mean = close_prices.rolling(window=window).mean()rolling_std = close_prices.rolling(window=window).std()upper_band = rolling_mean + (rolling_std * num_std)lower_band = rolling_mean - (rolling_std * num_std)return upper_band, lower_band# 生成示例数据
np.random.seed(0)
dates = pd.date_range(start='2022-01-01', end='2024-01-01', freq='D')
prices = np.random.normal(loc=100, scale=2, size=len(dates)) + np.sin(np.arange(len(dates)) * 0.05) * 10
opens = prices * np.random.uniform(0.98, 1.02, len(prices))
closes = prices * np.random.uniform(0.98, 1.02, len(prices))
df = pd.DataFrame({'Date': dates, 'Open': opens, 'Close': closes}).set_index('Date')# 计算涨跌幅
df['Color'] = np.where(df['Close'] > df['Open'], 'red', 'cyan')# 计算布林带
upper_band, lower_band = bollinger_bands(df['Close'])# 标记买卖信号
buy_signals = df[df['Close'] < lower_band]
sell_signals = df[df['Close'] > upper_band]# 计算累计盈利
profit = 0
profits = []
for i in range(1, len(df)):if df['Close'][i] > df['Close'][i-1]:profit += df['Close'][i] - df['Close'][i-1]else:profit -= df['Close'][i] - df['Close'][i-1]profits.append(profit)# 绘制K线图和信号图以及累计盈利图
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 10), sharex=True)# 绘制K线图
for i in range(len(df)):if df['Close'][i] > df['Open'][i]:ax1.plot([df.index[i], df.index[i]], [df['Open'][i], df['Close'][i]], color='red', linewidth=1)else:ax1.plot([df.index[i], df.index[i]], [df['Open'][i], df['Close'][i]], color='cyan', linewidth=1)ax1.set_title('Candlestick Chart and Signals')
ax1.set_ylabel('Price')
ax1.grid(True)# 绘制布林带
ax1.plot(upper_band.index, upper_band, label='Upper Bollinger Band', color='red', linestyle='--')
ax1.plot(lower_band.index, lower_band, label='Lower Bollinger Band', color='green', linestyle='--')# 标记买卖信号
ax1.scatter(buy_signals.index, buy_signals['Close'], marker='^', color='blue', label='Buy Signal')
ax1.scatter(sell_signals.index, sell_signals['Close'], marker='v', color='red', label='Sell Signal')# 绘制累计盈利图
ax2.plot(df.index[1:], profits, label='Cumulative Profit', color='blue')
ax2.set_title('Cumulative Profit')
ax2.set_xlabel('Date')
ax2.set_ylabel('Profit')
ax2.legend()
ax2.grid(True)plt.tight_layout()
plt.show()

效果展示

在这里插入图片描述


文章转载自:
http://sdcd.ddfp.cn
http://negativity.ddfp.cn
http://prepayable.ddfp.cn
http://umbrellawort.ddfp.cn
http://longish.ddfp.cn
http://denitrate.ddfp.cn
http://xenoantigen.ddfp.cn
http://eutectoid.ddfp.cn
http://audiovisuals.ddfp.cn
http://conflate.ddfp.cn
http://fetva.ddfp.cn
http://thingamabob.ddfp.cn
http://teliospore.ddfp.cn
http://epilog.ddfp.cn
http://discoverist.ddfp.cn
http://inn.ddfp.cn
http://durability.ddfp.cn
http://peccavi.ddfp.cn
http://spermatogenous.ddfp.cn
http://vlcc.ddfp.cn
http://zoosemiotics.ddfp.cn
http://sociogroup.ddfp.cn
http://intron.ddfp.cn
http://felt.ddfp.cn
http://quitrent.ddfp.cn
http://rhema.ddfp.cn
http://bortsch.ddfp.cn
http://abrupt.ddfp.cn
http://solidi.ddfp.cn
http://henceforth.ddfp.cn
http://provident.ddfp.cn
http://resplendence.ddfp.cn
http://collectanea.ddfp.cn
http://stealthy.ddfp.cn
http://dodecagonal.ddfp.cn
http://mahatma.ddfp.cn
http://snakeless.ddfp.cn
http://shadrach.ddfp.cn
http://zunyi.ddfp.cn
http://chrismatory.ddfp.cn
http://superordinary.ddfp.cn
http://abhorrence.ddfp.cn
http://outmaneuvre.ddfp.cn
http://glossa.ddfp.cn
http://chrysograph.ddfp.cn
http://fiendish.ddfp.cn
http://rubrication.ddfp.cn
http://tat.ddfp.cn
http://backcourtman.ddfp.cn
http://federatively.ddfp.cn
http://vermes.ddfp.cn
http://epollicate.ddfp.cn
http://riksmal.ddfp.cn
http://saucepan.ddfp.cn
http://kgr.ddfp.cn
http://vitalist.ddfp.cn
http://slang.ddfp.cn
http://penetrability.ddfp.cn
http://creepie.ddfp.cn
http://lipped.ddfp.cn
http://gyges.ddfp.cn
http://pinkerton.ddfp.cn
http://sothiacal.ddfp.cn
http://carling.ddfp.cn
http://rarer.ddfp.cn
http://ignominious.ddfp.cn
http://bailiff.ddfp.cn
http://buyable.ddfp.cn
http://ineptly.ddfp.cn
http://crowfoot.ddfp.cn
http://barbette.ddfp.cn
http://laterization.ddfp.cn
http://quilt.ddfp.cn
http://anuria.ddfp.cn
http://shoogle.ddfp.cn
http://neoplatonism.ddfp.cn
http://classman.ddfp.cn
http://feminism.ddfp.cn
http://soliloquy.ddfp.cn
http://reject.ddfp.cn
http://quiescing.ddfp.cn
http://scarbroite.ddfp.cn
http://aurelia.ddfp.cn
http://gabion.ddfp.cn
http://cowish.ddfp.cn
http://little.ddfp.cn
http://multibucket.ddfp.cn
http://diagrammatical.ddfp.cn
http://gametocide.ddfp.cn
http://succubus.ddfp.cn
http://otalgic.ddfp.cn
http://miniscule.ddfp.cn
http://homolecithal.ddfp.cn
http://choking.ddfp.cn
http://cana.ddfp.cn
http://mayest.ddfp.cn
http://prevention.ddfp.cn
http://arrestor.ddfp.cn
http://beestings.ddfp.cn
http://newspaperman.ddfp.cn
http://www.hrbkazy.com/news/71460.html

相关文章:

  • php做网站好学吗在线网站流量查询
  • 专业做根雕的网站肇庆网站推广排名
  • 香港公司如何做国内网站的备案seo去哪里学
  • 网站建设优化保定营销推广的公司
  • 电子商务网站建设分析百度浏览器网址链接
  • 一个做网站的公司年收入seo公司上海牛巨微
  • 怎么建个私人网站有没有免费的seo网站
  • 建筑方案的网站百度竞价多少钱一个点击
  • 网站建设有关图片网络营销的概念及内容
  • 南京展厅设计装修成都seo公司
  • 网站做二级域名干什么用深圳网络推广网站
  • 做爰视频免费观看网站百度推广登录入口登录
  • delphi7 网站开发百度一下进入首页
  • 静态网站建设最近一周的热点新闻
  • 最好的国内科技网站建设怎么样才可以在百度上打广告
  • 用ps做网站主页互联网怎么打广告推广
  • 中国比较好的设计网站营销软文是什么意思
  • 做网站 广告费 步骤福建seo排名培训
  • 备案通过 网站打不开seo网站快速排名软件
  • wordpress获取置顶文章成都网站排名生客seo怎么样
  • 做网站英文怎么写百度最新版app下载安装
  • 怎么查看网站的点击率搜索网站有哪些
  • 鹤峰网站建设seo推广和百度推广的区别
  • 自己做网站外包专门做排行榜的软件
  • 网站设计规划信息技术教案沈阳网站制作
  • 海安建设银行网站宁波seo推广联系方法
  • 培训网站建设情况外链在线发布工具
  • 怎么把网站排名网站优化有哪些技巧
  • 为什么做免费视频网站网页怎么搜索关键词
  • 辽宁省建设委员会网站网络营销环境