我想在dataframe,trade_list中计算每个交易条目的结算日期,方法是在数据框中查找Country_code,使用cash_mgmt_static来获取trade_settlement_cycle。
然后可以将{p>settlement date
计算为trade date + trade_settlement_cycle
。
我如何在数据框trade_settlement_cycle
中获得cash_mgmt_static
Country_code
,并将trade_list
作为两个数据框中的查找值?
数据框trade_list.csv
从cash_mgmt_static
读取,其中包含交易条目列表。
数据框cash_mgmt_static
从trade_list <- read.csv("trade_list.csv", header=TRUE)
print(trade_list)
Sedol Description Trans_type Trade_date Quantity Price_local CCY_local Trade_value_local Trade_type Country_code
1 B01NPJ1 TATA CONSULTANCY SERVICES LTD BUY 11-Jan-18 38,164 40.88 INR 1,560,044 Buy New IN
2 B012W42 PUBLIC BK BHD BUY 11-Jan-18 221,400 4.92 MYR 1,089,969 Buy More MY
3 6288190 AU OPTRONICS CORP. BUY 11-Jan-18 2,210,000 0.42 TWD 923,639 Buy New TW
4 6491318 KINGBOARD CHEMICAL BUY 11-Jan-18 138,500 5.54 HKD 767,200 Buy New HK
5 6205122 INFOSYS LTD BUY 11-Jan-18 48,855 15.30 INR 747,548 Buy New IN
cash_mgmt_data <- read.csv("cash_mgmt_static.csv", header=TRUE)
print(cash_mgmt_data)
Country_name Country_code CCY Trade_settlement_cycle BUY_funding_cycle Sell_repatriation_cycle FX_SI
1 Australia AU AUD 2 2 2 No
2 Canada CA CAD 2 2 2 No
3 Euro Union EU EUR 2 2 2 No
4 Hong Kong HK HKD 2 2 2 No
5 India IN INR 2 1 3 No
6 Korea KR KRW 2 2 2 No
7 Japan JP JPY 3 3 3 No
8 Malaysia MY MYR 3 3 3 No
9 New Zealand NZ NZD 2 2 2 No
10 Philipines PH PHP 3 3 3 No
11 Singapore SG SGD 3 3 3 No
12 Switzerland CH CHF 2 2 2 No
13 Taiwan TW TWD 2 1 2 No
读取,其中包含各种市场的静态数据。
model.summary()
答案 0 :(得分:0)
谢谢你的帮助。我尝试过匹配并且有效。
library("readxl")
cash_mgmt_static <- read.csv("cash_mgmt_static.csv", header=TRUE)
trade_list <- read.csv("trade_list.csv", header=TRUE)
country_code <- trade_list[row, "Country_code"]
trade_settlement_cycle <- cash_mgmt_data[match(trade_list$Country_code,cash_mgmt_data$Country_code),"Trade_settlement_cycle"]
trade_list$Trade_date = as.Date(trade_list$Trade_date, format= "%d-%B-%y")
trade_list$Settle_date <- trade_list$Trade_date + trade_settlement_cycle
print(trade_list)