将数据上传至 hdfs hdfs dfs -put stocks /user/bigdata 2. /stocks/NASDAQ/AAPL'; alter table stocks_external add partition(exchanger="NASDAQ", symbol="INTC") location '/user/bigdata/stocks/NASDAQ/INTC'; alter table stocks_external add partition(exchanger="NYSE ", symbol="IBM") location '/user/bigdata/stocks/NYSE/IBM'; alter table stocks_external add partition stocks_external; 4.
stocks_df = spread.sheet_to_df()stocks_df.head()我们可以看到 DataFrame 包含股票价格和股票数量的实际值。 在[53]中:stocks_df["Marketcap_1_1"] = stocks_df["Price_1_1"] * stocks_df["Shares"]stocks_df["Marketcap_ 2_1"] = stocks_df["Price_2_1"] * stocks_df["Shares"]stocks_df["Marketcap_3_1"] = stocks_df["Price_3_1 _2_1_1_1"] = (stocks_df["Price_2_1"] - stocks_df["Price_1_1"]) / stocks_df["Price_1_1"]*100# Percentage 1ststocks_df["PercentageChange_3_1_1_1"] = (stocks_df["Price_3_1"] - stocks_df["Price_1_1"]) / stocks_df
<- read.csv(file.choose()) 数据查看 head(stocks) summary(stocks[,-1]) cl <- stocks$Increase #已知涨跌 colors ="scatterplot3d - stocks", pch=20) ? 数据集划分 stocks$Date <- ymd(stocks$Date) stocksTrain <- year(stocks$Date) < 2014 predictors <- cbind(lag #查看偏相关图 acf(stocks$Google) pacf(stocks$Google) acf(stocks$MSFT) pacf(stocks$MSFT) ? == stocks$Increase[!
(current_stocks, previous_stocks): """对比新旧股票数据(接收DataFrame)""" # 从历史数据中提取股票代码 prev_codes = {s["股票代码"] for s in previous_stocks.get("stocks", [])} # 从当前DataFrame中提取新股票 new_stocks = [] (hyperlinked_name) return new_stocks def send_dingding_alert(new_stocks, board_code): """通过钉钉发送新增股票提醒 获取最新股票数据 current_stocks = fetch_stocks(STOCK_BOARD_CODE) # 修复1:使用.empty判断DataFrame是否为空 if 对比数据变化 new_stocks = compare_stocks(current_stocks, previous_data) # 4.
加载自选股文件 ===== defload_block_stocks(block_path): """读取.blk文件并转换为标准代码""" try: withopen( 文件最后修改时间 # 首次加载自选股 stocks = load_block_stocks(block_path) monitored_stocks = set(stocks) print(f"初始监控列表: {monitored_stocks}") # 获取昨日成交量 for stock in monitored_stocks: df new_stocks = set(load_block_stocks(block_path)) # 处理新增股票 added = new_stocks ), callback=on_data) monitored_stocks = new_stocks last_mtime = current_mtime
print(concept_sectors) sector_gains = [] for sector in concept_sectors: stocks = xtdata.get_stock_list_in_sector(sector) # 获取板块成分股[3,4](@ref) #print(stocks) (stocks) #print(quotes) total_gain = 0 valid_stocks = 0 ['lastClose'] - 1) * 100 # 计算单股涨幅 total_gain += gain valid_stocks += 1 if valid_stocks > 0: avg_gain = total_gain / valid_stocks # 板块平均涨幅
public double getMarketValue(){ double marketValue = 0.0; for(Stock stock:stocks){ marketValue int save(double marketValue); } 来看一下测试用例 @Test public void testPortfolioVerifySave(){ //add stocks to the portfolio portfolio.setStocks(stocks); //mock the behavior of stock service to return the value of various stocks when(stockService.getPrice(teslaStock)).thenReturn(500.00); when (stocks); //mock the behavior of stock service to return the value of various stocks when(stockService.getPrice
# 默认为守护线程 queue.start() # 测试INSERT for i in range(12,15): queue.register_execute("INSERT INTO stocks , callback=lambda lst_row, data: print(lst_row)) # 测试SELECT queue.register_execute("SELECT * FROM stocks ", callback=lambda lst_row, data: print(data)) # 包装SQL语句SELECT queue.select('stocks').where('price', 这里节选一些好了: # INSERT语句 queue.insert('stocks')\ .data({'trans': 'BUY', 'symbol': 'RHAT', 'price': 35.14 , 'qty': 100, 'date': '2017-01-01'}).register() # 两种不同写法的SELECT语句 queue.select('stocks').where('price
=get_index_stocks('000300.XSHG') # 设置沪深300为初始股票池 # 设置可行股票池 g.feasible_stocks = set_feasible_stocks (g.stocks,context) g.t+=1 #4 # 设置可行股票池:过滤掉当日停牌的股票 # 输入:initial_stocks为list类型,表示初始股票池; context(见 API) # 输出:unsuspened_stocks为list类型,表示当日未停牌的股票池,即:可行股票池 def set_feasible_stocks(initial_stocks,context ) unsuspened_stocks =list(df_paused_info.index[df_paused_info.paused_info == False]) return unsuspened_stocks 支股票,list类型 list_to_buy = stocks_to_buy(context) # 待卖出的股票,list类型 list_to_sell
连接多个DataFrame # 读取stocks_2016和stocks_2017两个数据集,用Symbol作为行索引名 In[21]: stocks_2016 = pd.read_csv('data /stocks_2016.csv', index_col='Symbol') stocks_2017 = pd.read_csv('data/stocks_2017.csv', index_col 前本节的第二个例子,pd.concat也可以如下实现: In[28]: stocks_2016.append(stocks_2017) Out[28]: ? # 原书没有下面三行代码 In[29]: stocks_2015 = stocks_2016.copy() In[30]: stocks_2017 Out[30]: ? 3. _2016, stocks_2017, stocks_2018 = stock_tables ?
negative results when they execute the transaction MB5B for aspecific posting date, even when the negative stocks Ifnegative stocks are not allowed in the system, this goods issue could not havebeen executed with posting Inthe stocks tables (MARC, MARD, MBEW) the system will never allow negativestocks if you make the settings for negative stocks NOT allowed in Customizingfor Inventory Management by using transaction “OMJ1”. Willindeed offer negative stocks: ?
set public double getMarketValue(){ double marketValue = 0.0; for(Stock stock:stocks to be added to the portfolio List<Stock> stocks = new ArrayList<Stock>(); Stock teslaStock = new Stock("1","tesla", 10); Stock amazonStock = new Stock("2","amazon",100); stocks.add (teslaStock); stocks.add(amazonStock); //add stocks to the portfolio portfolio.setStocks (stocks); //mock the behavior of stock service to return the value of various stocks
sqlite3 conn = sqlite3.connect('test.db') # 创建游标对象 c = conn.cursor() # 创建表 c.execute("CREATE TABLE stocks (data TEXT, trans TEXT, symbol TEXT, qty REAL, price REAL)") # 插入数据 c.execute("INSERT INTO stocks VALUES (其他数据库模块可能使用不同的占位符,比如%s)例如: # 不要这么做 # 定义变量 symbol = 'rhat' # 获取查询结果 dbs = c.execute("SELECT * FROM stocks %s'" % symbol) # 打印出数据 for db in dbs: print(db) # 正确做法 t = ('rhat', ) c.execute('SELECT * FROM stocks stocks ORDER BY price'): print(row) # fetchone和fetchall方式获取内容 c.execute('SELECT * FROM stocks ORDER
4.优化配置策略 1.编写一个工程和spider模板 列出相关命令: scrapy startproject BaiduStocks cd BaiduStocks scrapy genspider stocks baidu.com ->进一步修改spiders/stocks.py文件 2..编写Spider 对Spider编写包括以下处理: 配置stocks.py文件 修改对返回页面的处理 修改对新增URL 爬取请求的处理 我们在BaiduStocks\BaiduStocks\spiders文件目录下找到stocks.py文件,打开并修改。 修改代码如下; import re import scrapy class StocksSpider(scrapy.Spider): name = 'stocks' start_urls ITEM_PIPELINES = { 'BaiduStocks.pipelines.BaiduStocksInfoPipeline': 300, } 最后运行需执行如下命令: scrapy crawl stocks
Thread from xtquant import xtdata class StockSelector: def __init__(self): self.selected_stocks = xtdata.get_stock_list_in_sector("沪深A股") return [stock.split('.')[0] for stock in all_stocks = len(stock_list) print(f"开始选股,共{total_stocks}只股票需要筛选...") ") # 截断错误信息 continue self.selected_stocks = selected return selected selected = selector.select_stocks() print(f"选股完成,共选出 {len(selected)} 只股票") if len(selected) =
笔者将之前的用例进行了改造, @Test public void testPortfolioGetMarketValueMultiTimes(){ //Creates a list of stocks to be added to the portfolio List<Stock> stocks = new ArrayList<Stock>(); Stock teslaStock = new Stock("1","tesla", 10); Stock amazonStock = new Stock("2","amazon",100); stocks.add(teslaStock ); stocks.add(amazonStock); //add stocks to the portfolio portfolio.setStocks(stocks); //mock the behavior of stock service to return the value of various stocks when(stockService.getPrice
strategy_dfs: 包含多个策略选股DataFrame的列表 返回: 包含个股出现次数和详细策略信息的DataFrame """ # 收集所有股票的代码和名称 all_stocks ): temp_df = df[['股票代码', '股票名称']].copy() temp_df['策略来源'] = f'策略{i + 1}' all_stocks = pd.concat([all_stocks, temp_df], ignore_index=True) # 统计每只股票的出现次数 count_summary = all_stocks ().reset_index() count_summary.columns = ['股票代码', '出现次数'] # 添加股票名称 stock_name_map = all_stocks [all_stocks['股票代码'] == stock]['策略来源'].unique() strategy_occurrence[stock] = ', '.join(strategies
= '/v3/marketing/favor/coupon-stocks';//创建代金券批次API const START_COUPON_STOCKS = '/v3/marketing/favor API const PAUSE_COUPON_STOCKS = '/v3/marketing/favor/stocks/%d/pause';//暂停代金券批次API const RESTART_COUPON_STOCKS = '/v3/marketing/favor/stocks/%d/pause';//重启代金券批次API const QUERY_COUPON_STOCKS = '/v3/marketing/ favor/stocks';//条件查询批次列表API const QUERY_COUPON_STOCKS_INFO = '/v3/marketing/favor/stocks/%s';//查询批次详情 = '/v3/marketing/favor/stocks/%s/use-flow';//下载批次核销明细API const COUPON_STOCKS_REFUND_FLOW_DOWNLOAD
",stocks); 10 return modelAndView; 11 } ? = stockRepo.findAll(pageable); 5 return stocks; 6 } ?
= potential_stocks.sort_values(by='净利润增长率(%)', ascending=False) # 重置索引 potential_stocks = potential_stocks.reset_index(drop=True) return potential_stocks步骤 5:结果输出与本地保存将筛选出的潜力股整理为表格,并保存为本地 python运行def export_stock_result(potential_stocks): """ 输出筛选结果,保存为本地Excel文件 """ if potential_stocks.empty :') print('-' * 80) print(potential_stocks) # 保存为本地Excel文件(需安装openpyxl库,支持xlsx格式) try : potential_stocks.to_excel('潜力股筛选结果.xlsx', index=False, engine='openpyxl') print('-' *