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

龙岗网站设计案例如何做旅游网站推销

龙岗网站设计案例,如何做旅游网站推销,百度 特定网站搜索,无锡网络营销推广第一阶段、一个简单策略入门量化投资 1-4移动均线交叉策略3 上一文1-3移动均线交叉策略2中#xff0c;我们得到的结果是令人失望的。但我们的探索还要继续。 我们知道#xff0c;使用投资组合的方式进行分散投资是降低风险的好办法。尽管移动均线交叉策略的表现并不理想我们得到的结果是令人失望的。但我们的探索还要继续。 我们知道使用投资组合的方式进行分散投资是降低风险的好办法。尽管移动均线交叉策略的表现并不理想我们还是在此策略基础上进行修改添加采用投资组合进行投资的代码重新进行回测。 修改后的代码你只需提前设置你想要购买股票的公司代码列表例如 # the list of listed companies that we are concerned about listed_company_list [AAPL,MSFT,GOOG,FB,TWTR,NFLX,AMZN,SNY,NTDOY,IBM,HPQ] 假设初始资金仍为100万在使用上面给出的投资组合的情况下资产的变化情况如下图所示 这时我们策略的收益率为93.5% 平均年化收益率为9.138% 显然使用投资组合后收益进一步减少了但是我们也清楚其中的积极意义这样的策略分摊了风险。我们都知道风险越大收益越高的现象是普遍存在的如何权衡呢 于是我们看到同样是均线交叉策略使用和不使用投资组合两种情况在回测后判断策略优劣时就已经针对风险与收益的权衡出现了问题。 因此如何更合理的在回测时评价策略的优劣是一个需要探索的有意义工作未完待续… 完整代码 import numpy as np import pandas as pd import matplotlib.pyplot as plt import datetimeimport stockdata_preProcess as preProcess##### the first step: get the listed companiess stock data that we concerned about# the time interval of the data we want to get(from start to end) start datetime.datetime(2010, 1, 1) end datetime.date.today()# the list of listed companies that we are concerned about listed_company_list [AAPL,MSFT,GOOG,FB,TWTR,NFLX,AMZN,SNY,NTDOY,IBM,HPQ] # *trouble*: I cant get YHOO s data, and I havet find# download data (we do not need to repeat this work) #preProcess.downloadAndSaveData(listed_company_list, start, end)# use moving average crossover strategy to build the trading signal dataframe # stocks: the data, e.g: [(AAPL, apple_adjust_data),(MSFT, microsoft_adjust_data),(GOOG, google_adjust_data)] # fast: the span of short-term moving average # slow: the span of long-term moving average def ma_crossover_orders(stocks, fast, slow):fast_str str(fast) dslow_str str(slow) dma_diff_str fast_str - slow_strtrades pd.DataFrame({Price: [], Regime: [], Signal: []})for s in stocks:s[1][fast_str] np.round(s[1][Close].rolling(window fast, center False).mean(), 2)s[1][slow_str] np.round(s[1][Close].rolling(window slow, center False).mean(), 2)s[1][ma_diff_str] s[1][fast_str] - s[1][slow_str]s[1][Regime] np.where(s[1][ma_diff_str] 0, 1, 0)s[1][Regime] np.where(s[1][ma_diff_str] 0, -1, s[1][Regime])regime_orig s[1].ix[-1, Regime]s[1].ix[-1, Regime] 0s[1][Signal] np.sign(s[1][Regime] - s[1][Regime].shift(1))s[1].ix[-1, Regime] regime_origsignals pd.concat([pd.DataFrame({Price: s[1].loc[s[1][Signal] 1, Close],Regime: s[1].loc[s[1][Signal] 1, Regime],Signal: Buy}),pd.DataFrame({Price: s[1].loc[s[1][Signal] -1, Close],Regime: s[1].loc[s[1][Signal] -1, Regime],Signal: Sell}),])signals.index pd.MultiIndex.from_product([signals.index, [s[0]]], names [Date, Symbol])trades trades.append(signals)trades.sort_index(inplace True)trades.index pd.MultiIndex.from_tuples(trades.index, names [Date, Symbol])return trades# do the backtest # signals: the dataframe recording the trading signal # cash: the initial cash flow # port_value: the largest proportion of single transaction to total assets # batch: the smallest unit of the number of shares traded def backtest(signals, cash, port_value .1, batch 100):SYMBOL 1portfolio dict() # denote: all the stock asset allocationport_prices dict() # denote: all the stock price correspond to the asset allocationresults pd.DataFrame({Start Cash: [],End Cash: [],Portfolio Value: [],Type: [],Shares: [],Share Price: [],Trade Value: [],Profit per Share: [],Total Profit: []})for index, row in signals.iterrows():# index[SYMBOL] denote the listed companys name, e.g APPLshares portfolio.setdefault(index[SYMBOL], 0)trade_val 0batches 0# step 1 : sell current stock(if we hold current stock)# if shares0, means we already hold the stock of the company# so it is a sell signal here, we sell all the shares held nowcash_change row[Price] * sharesportfolio[index[SYMBOL]] 0old_price port_prices.setdefault(index[SYMBOL], row[Price]) # get the price when we buy the stock before# step 2 : compute portfolios value( the value after sell current stock)portfolio_val 0for key, val in portfolio.items():portfolio_val val * port_prices[key]# step 3 : buy current stock( if it is a buy singnal here )if row[Signal] Buy and row[Regime] 1:batches np.floor((portfolio_val cash) * port_value) // np.ceil(batch * row[Price])trade_val batches * batch * row[Price]cash_change - trade_valportfolio[index[SYMBOL]] batches * batchport_prices[index[SYMBOL]] row[Price]old_price row[Price]elif row[Signal] Sell and row[Regime] -1:passpprofit row[Price] - old_priceresults results.append(pd.DataFrame({Start Cash: cash,End Cash: cash cash_change,Portfolio Value: cash cash_change portfolio_val trade_val,Type: row[Signal],Shares: batch * batches,Share Price: row[Price],Trade Value: abs(cash_change),Profit per Share: pprofit,Total Profit: batches * batch * pprofit}, index [index]))cash cash_changeresults.sort_index(inplace True)results.index pd.MultiIndex.from_tuples(results.index, names [Date, Symbol])return results##### get the data we save in .csv file and then return the repaired data to the user DataSetList preProcess.repairAndGetData(listed_company_list)##### use moving average crossover strategy to build the trading signal dataframe # build the data format requied by the function ma_crossover_orders # ( combine the stock name and the corresponding data ) stock_NameDataTuple_List [] for i in range(len(listed_company_list)):cur_stock DataSetList[i];cur_company listed_company_list[i]stock_NameDataTuple_List.append((cur_company,cur_stock))signals ma_crossover_orders(stock_NameDataTuple_List, fast 20, slow 50) # these codes are the same as below: (use Ctrl/ to batch annotation code) # apple DataSetList[0] # microsoft DataSetList[1] # google DataSetList[2] # facebook DataSetList[3] # twitter DataSetList[4] # netflix DataSetList[5] # amazon DataSetList[6] # sony DataSetList[7] # nintendo DataSetList[8] # ibm DataSetList[9] # hp DataSetList[10] # signals ma_crossover_orders([(AAPL, preProcess.ohlc_adjust(apple)), # (MSFT, preProcess.ohlc_adjust(microsoft)), # (GOOG, preProcess.ohlc_adjust(google)), # (FB, preProcess.ohlc_adjust(facebook)), # (TWTR, preProcess.ohlc_adjust(twitter)), # (NFLX, preProcess.ohlc_adjust(netflix)), # (AMZN, preProcess.ohlc_adjust(amazon)), # (SNY, preProcess.ohlc_adjust(sony)), # (NTDOY, preProcess.ohlc_adjust(nintendo)), # (IBM, preProcess.ohlc_adjust(ibm)), # (HPQ, preProcess.ohlc_adjust(hp))], # fast 20, slow 50) print(signals)##### do the back test bk backtest(signals, 1000000) print(bk)##### show the changes in portfolio value #bk[Portfolio Value].groupby(level 0).apply(lambda x: x[-1]).plot() portfolio_ValueList bk[Portfolio Value].groupby(level 0).apply(lambda x: x[-1]) portfolio_ValueList.plot() #print(portfolio_ValueList)##### compute annualized rate of return initial_value portfolio_ValueList[0] deadline_value portfolio_ValueList[-1]initial_date portfolio_ValueList.index[0] deadline_date portfolio_ValueList.index[-1] holding_interval (deadline_date - initial_date).days / 365AnnualReturnRate ( pow(deadline_value/initial_value,1/holding_interval) - 1 )*100 print(平均年化收益率 ,AnnualReturnRate,%) print((deadline_value-initial_value)/initial_value)plt.show()
http://www.yutouwan.com/news/374870/

相关文章:

  • 销售型网站有哪些正规拼多多代运营公司
  • dede网站建设步骤网站优化防范
  • 南京做网站xjrkj网络服务商怎么咨询
  • 海口建站网站模板焦作seo公司
  • iis wordpress多站点昆明市网站备案
  • php建网站推广普通话主题班会记录
  • 如何做网校网站百度竞价运营
  • 中国制造网网站建设的优势类似wordpress的博客
  • 静态网站开发课程网希爱力双效片
  • 雄县网站建设网站数据不变重新安装wordpress
  • 帝国做网站网站建设网站模板
  • 男女做羞羞羞的事视频网站如何选择做pc端网站
  • 东莞市建设监督网站首页网站建设飠金手指科杰十二
  • 关于建设招商网站的通知wordpress下载安装
  • 活泼的网站棋牌网站搭建公司
  • 泰安网站制作推荐看室内设计案例的网站
  • 齐齐哈尔网站建设网站后台如何修改密码
  • 网站首页排版设计电商运营的基本内容
  • html5 metro风格网站模板没有网站可以做百度推广吗
  • 祥云平台做网站如何怎么做网页设计视频
  • dede建设网站软文代理平台
  • 越南做购物网站仙桃网站设计
  • 企业网站开发期末报告wordpress添加网址为导航
  • 网站推广营销怎么做网和网站的区别
  • 百度商桥接入网站手机wordpress无法评论
  • 营销推广渠道有哪些大连优化网站课程
  • 搭建一个20人的办公网络静态网站seo怎么做
  • 网站设计好做吗广告公司怎么宣传自己
  • 手机上的网站完全不收费的聊天软件
  • 昆山移动网站建设传奇世界网页版论坛