编程介的小学生 2017-08-19 03:15 采纳率: 20.5%
浏览 675
已采纳

Balance

Problem Description
An investor invests a certain percentage of his assets into NINSTRUMENTS financial instruments. After each term, these instruments deduct a certain fixed administrative cost, followed by a fee that is a percentage of the amount that was invested at the beginning of the term, and then add a return, which is a (positive or negative) percentage of the amount invested at the beginning of the term. If any account drops to zero or below after such a transaction, it is considered closed (no fees are charged against it, and is treated as simply zero) until a rebalancing occurs. Rebalancing occurs after every NREBALANCE terms, where the total assets of the investor are redistributed according to the original ratios for the instruments. Without rebalancing, the investor's assets would become dominated by the higher return instruments, which would expose them to more risk compared to a balanced investment plan. Note that it is possible that all instruments drop to zero, in which case they all remain closed for the remaining terms. You are to model the value of such an investment strategy and report the ending value in each instrument (before rebalancing, if it happens to land on a term when a rebalance is due). Compute your results using double precision (do not round intermediate values to pennies), but round your final answers to pennies.

Input
The first line of the input contains the three positive integers:
NINSTRUMENTS NTERMS NREBALANCE
There are no more than 10 instruments, and the number of terms is at most 20. This is followed by 3 lines of floating-point numbers separated by spaces, in the following format:
FIXED_FEE(1) .. FIXED_FEE(NINSTRUMENTS)
PERCENTAGE_FEE(1) .. PERCENTAGE_FEE(NINSTRUMENTS)
PRINCIPAL_START(1) .. PRINCIPAL_START(NINSTRUMENTS)
Finally, there are NTERMS lines each containing NINSTRUMENTS floating-point numbers indicating the percentage return of each instrument in each term:
RETURN(1,1) .. RETURN(1,NINSTRUMENTS)
RETURN(2,1) .. RETURN(2,NINSTRUMENTS)
.
.
RETURN(NTERMS,1) .. RETURN(NTERMS,NINSTRUMENTS)
All percentages (PERCENTAGE_FEE and RETURN) are given as ratios, up to 4 decimal places. For example, a fee of 0.0002 means 0.02% of the investment in this instrument is deducted as a fee each term. FIXED_FEE and PRINCIPAL_START are non-negative floating-point numbers that are specified to 2 decimal places. At least one of the PRINCIPAL_START values is positive.

Output
Write on a single line the principal of each investment (separated by a space) at the end of NTERMS terms. Round each principal to the nearest penny.
PRINCIPAL_END(1) .. PRINCIPAL_END(NINSTRUMENTS)

Sample Input
4 10 5
5.00 10.00 20.00 50.00
0.002 0.001 0.0008 0.0005
150000.00 100000.00 75000.00 50000.00
0.10 0.05 -0.05 -0.85
0.10 0.05 -0.10 -0.85
0.10 0.05 -0.20 -0.85
0.10 0.05 -0.40 -0.85
0.10 0.05 -0.80 -0.85
0.10 0.05 -0.05 -0.90
0.10 0.05 -0.05 -0.90
0.10 0.05 -0.05 -0.90
0.10 0.05 -0.05 -0.85
0.10 0.05 -0.05 -0.85

Sample Output
237698.69 126086.01 57298.74 0.00

  • 写回答

1条回答 默认 最新

  • devmiao 2017-08-29 16:40
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了