- 阅读权限
- 255
- 威望
- 2 级
- 论坛币
- 3876 个
- 通用积分
- 200.3172
- 学术水平
- 621 点
- 热心指数
- 635 点
- 信用等级
- 606 点
- 经验
- 48595 点
- 帖子
- 1292
- 精华
- 3
- 在线时间
- 790 小时
- 注册时间
- 2010-11-19
- 最后登录
- 2023-8-4
|
- import numpy as np
- import pandas as pd
- import scipy
- import math
- import statsmodels
复制代码- dp = get_fundamentals(query(fundamentals.eod_derivative_indicator.market_cap,fundamentals.financial_indicator.book_value_per_share),'2010-11-01', '60m')
- market = all_instruments()
- price_data = get_price(list(market['order_book_id']),start_date='2005-11-01', end_date='2010-10-30',frequency='1d',fields='ClosingPx')
复制代码- price_data = get_price(list(market['order_book_id']),start_date='2005-11-01', end_date='2010-11-05',frequency='1d',fields='ClosingPx')
复制代码- index_date = dp['book_value_per_share'].index
- stocks = dp['book_value_per_share'].columns
复制代码- Index(['2010-11-01', '2010-09-30', '2010-09-01', '2010-07-30', '2010-07-01',
- '2010-06-01', '2010-04-30', '2010-04-01', '2010-03-01', '2010-02-01',
- '2009-12-31', '2009-12-01', '2009-10-30', '2009-09-30', '2009-09-01',
- '2009-07-31', '2009-07-01', '2009-06-01', '2009-04-30', '2009-04-01',
- '2009-02-27', '2009-01-23', '2008-12-31', '2008-12-01', '2008-10-31',
- '2008-09-26', '2008-09-01', '2008-08-01', '2008-07-01', '2008-05-30',
- '2008-04-30', '2008-04-01', '2008-02-29', '2008-02-01', '2007-12-28',
- '2007-11-30', '2007-11-01', '2007-09-28', '2007-08-31', '2007-08-01',
- '2007-06-29', '2007-06-01', '2007-04-30', '2007-03-30', '2007-03-01',
- '2007-02-01', '2006-12-29', '2006-12-01', '2006-11-01', '2006-09-29',
- '2006-09-01', '2006-08-01', '2006-06-30', '2006-06-01', '2006-04-28',
- '2006-03-31', '2006-03-01', '2006-01-25', '2005-12-30', '2005-12-01',
- '2005-11-01'],
- dtype='object')
复制代码- #调整nan值为零
- where_are_NaNs = np.isnan(dp['book_value_per_share'])
- dp['book_value_per_share'][where_are_NaNs] = 0
- where_are_NaNs = np.isnan(dp['market_cap'])
- dp['market_cap'][where_are_NaNs] = 0
- where_are_NaNs = np.isnan(price_data)
- price_data[where_are_NaNs] = 0
复制代码- ##btm stores the index book_to_market ratio
- btm = pd.DataFrame(index=index_date,columns=stocks)
- for stk in stocks:
- for date in index_date:
- if price_data[stk][date]!=0:
- btm[stk][date] = dp['book_value_per_share'][stk][date]/price_data[stk][date]
- else:
- btm[stk][date] = 0
复制代码
|
-
总评分: 学术水平 + 2
热心指数 + 2
信用等级 + 2
查看全部评分
|