跳轉到

finlab.market_info

finlab.market_info.MarketInfo

市場類別 假如希望開發新的交易市場套用到回測系統,可以繼承 finlab.market_info.MarketInfo 來實做新類別。

get_asset_id_to_name staticmethod

get_asset_id_to_name()

設定對標報酬率的時間序列 Returns: (dict): 股號與股名對照表,ex:{'2330':'台積電'}

get_benchmark staticmethod

get_benchmark()

設定對標報酬率的時間序列

這個函數用於設定對標報酬率的時間序列。

RETURNS DESCRIPTION
Series

pd.Series: 時間序列的報酬率。

RAISES DESCRIPTION
ExceptionType

Description of conditions under which the exception is raised.

Examples:

date 0050
2007-04-23 100
2007-04-24 100.1
2007-04-25 99
2007-04-26 98.3
2007-04-27 99.55

get_freq staticmethod

get_freq()

Returns the frequency of the data. Used to determine how to resample the data when the data is not daily. The freq will be saved in finlab.core.report.

Returns: str: The frequency of the data.

get_market_value staticmethod

get_market_value()

取得回測用市值數據

RETURNS DESCRIPTION
DataFrame

市值數據,其中 index 為日期,而 columns 是股票代號。

get_name staticmethod

get_name()

Returns the name of the market data source.

This function is used to get the name of the market data source.

get_odd_lot staticmethod

get_odd_lot()

Returns the odd lot size of the market.

RETURNS DESCRIPTION
int

The odd lot size of the market.

get_price staticmethod

get_price(trade_at_price, adj=True)

取得回測用價格數據

PARAMETER DESCRIPTION
trade_at_price

選擇回測之還原股價以收盤價或開盤價計算,預設為'close'。可選'close'或'open'。

TYPE: str

adj

是否使用還原股價計算。

TYPE: str DEFAULT: True

RETURNS DESCRIPTION
DataFrame

價格數據

Examples:

格式範例

date 0015 0050 0051 0052
2007-04-23 9.54 57.85 32.83 38.4
2007-04-24 9.54 58.1 32.99 38.65
2007-04-25 9.52 57.6 32.8 38.59
2007-04-26 9.59 57.7 32.8 38.6
2007-04-27 9.55 57.5 32.72 38.4

get_reference_price

get_reference_price()

Returns the most recent reference price of the market.

RETURNS DESCRIPTION

pandas.Series: The most recent reference price of the market.

get_trading_price

get_trading_price(name, adj=True)

取得回測用價格數據

PARAMETER DESCRIPTION
name

選擇回測之還原股價以收盤價或開盤價計算,預設為'close'。可選 'open'、'close'、'high'、'low'、'open_close_avg'、'high_low_avg'、或 'price_avg'。

TYPE: str

Returns: (pd.DataFrame): 價格數據

market_close_at_timestamp

market_close_at_timestamp(timestamp=None)

Returns the timestamp of the market close of the given timestamp.

PARAMETER DESCRIPTION
timestamp

The timestamp to find the market close to.

TYPE: datetime DEFAULT: None

RETURNS DESCRIPTION
datetime

The timestamp of the closest market close.

tzinfo staticmethod

tzinfo()

Returns the timezone of the market.

RETURNS DESCRIPTION

datetime.timezone: The timezone of the market.