中级农民
- 积分
- 231
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2017-7-12
- 最后登录
- 1970-1-1
|
# Trade Data Exercise
You are going to explore and analyze stock market data and trades done by some trading strategy over a historical two-month period. We've provided three CSV file datasets and some helper code to load the data into pandas dataframes. You are free to refer to any external documentation you need while working on these problems. Let's look at the data:
### Market Data
. ----
The first data set contains two months of market data for a set of US equity symbols, with data aggregated by minute. It's columns are:
- symbol: string, the equity symbol
- time_ns: int64, the unix epoch time in nanoseconds (a note about how to work with this field is below)
- trade_count: int, the total number of trades in the symbols over the previous minute (before time_ns)
- volume: int, the total number of shares traded in that minute
- dollar_volume: float, the dollar volume of trades in that minute (the dollar volume of a trade is shares * price)
- last_trade: float, the price of the last trade that happened before time_ns
. Χ
For your convenience we have translated the time_ns column into date and time columns which you may find useful later on
import pandas as pd
data_dir = 'data'
. From 1point 3acres bbs
market_data = pd.read_csv(data_dir + '/history_1.csv')
def add_date_and_time_columns(df):
datetime = pd.to_datetime(df.time_ns)
local_datetime = pd.Series(datetime.array.tz_localize('UTC').tz_convert('US/Eastern'))
df['time_of_day'] = local_datetime.dt.time. 1point 3acres
df['date'] = local_datetime.dt.date
add_date_and_time_columns(market_data)
market_data
### Reference Data
The next file provides equity-specific data, just the sector in which the equity belongs.
- symbol: string, the equity symbol. 1point3acres.com
- sector: string, the market sector of the equity, e.g. bank, tech, energy. check 1point3acres for more.
ref_data = pd.read_csv(data_dir + '/refdata_1.csv')
ref_data.google и
### Strategy Trade Data
The final data set contains a history of trading done by some strategy. Columns are:
.1point3acres
- symbol: string, the equity symbol. 1point 3acres
- time_ns: int64, the unix epoch time when the trade occured
- shares: int, how many shares the strategy bought or sold. .и
- price: float, the price of the transaction
- buy: boolean, true if the strategy bought, false if sold.1point3acres
strategy_trades = pd.read_csv(data_dir + '/trades_1.csv').google и
add_date_and_time_columns(strategy_trades)
strategy_trades ..
## Market Trade Analysis - By Symbol
Let's look at the trades that happened in the market (not the strategy's trades - you do not need the strategy_trades table for these first questions!).
Build a dataset that captures per symbol:.--
- total trade count
- total share volume.--
- total dollar volume
- average daily trade count
- average daily share volume-baidu 1point3acres
- average daily dollar volume
-baidu 1point3acres- percent of total dollar volume represented by that symbol (sum across all symbols should be 100). Χ
Sort and display this dataset from largest average daily dollar volume to smallest
. 1point3acres
## Market Trade Analysis - By Sector
. 1point3acres
Repeat the above but build a data set with one row per sector instead of symbol. From 1point 3acres bbs
## Strategy Analysis - Look-ahead prices
-baidu 1point3acres
Now let's bring the strategy_trades dataset into the mix..
We want see how each trade fared (its profit or loss) at some time in the future. Specifically we are interested in these time horizons from the time of the trade
- 5 minutes
- 10 minutes
- 15 minutes. .и
- 30 minutes
- 60 minutes
First, write a function that determines the price some minutes in the future for each row of the strategy_trades dataset. Then use that function to create price_min5, price_min10, ..., price_min60 columns in the strategy_trades table. Use the market_data dataset with its one-minute last_trade prices as the source for the look-ahead prices.. ----
. ----
## Strategy Analysis - Profit and Return. Waral dи,
For each horizon we want
- profit or loss in dollars for the trade (for buys this is: (size of trade)(lookahead_price - trade_price) )
- basis points of return for the trade (for buys this is 10000 * (lookahead_price - trade_price) / trade_price)
Create profit_min5, profit_min10, ... profit_min60, and bpreturn_min5, bpreturn_min10, ..., bpreturn_min16 columns in the strategy_trades_dataset.--
## Strategy Analysis - Daily Profits
For each sector and date, calculate the total profit at each time horizon.. From 1point 3acres bbs
## Strategy Analysis - Plot Cumulative Profit
In one plot, show the _cumulative_ 10-minute profit for each sector across dates - x-axis is date, y-axis is sum of all profits up to and including that date
## Strategy Analysis - Open Ended.--
-baidu 1point3acres
Is there something you can say or show that highlights different trading outcomes (in terms of basis-point return statistics) in the sectors based on time of day of the trades
|
|